@dotenvx/dotenvx 1.6.1 → 1.6.2
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.
- package/CHANGELOG.md +8 -2
- package/package.json +1 -1
- package/src/lib/main.d.ts +65 -27
- package/src/lib/services/decrypt.js +4 -0
- package/src/lib/services/encrypt.js +8 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,13 +2,19 @@
|
|
|
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/v1.6.
|
|
5
|
+
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.6.2...main)
|
|
6
|
+
|
|
7
|
+
## 1.6.2
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* add more detailed type definitions ([#313](https://github.com/dotenvx/dotenvx/pull/313))
|
|
6
12
|
|
|
7
13
|
## 1.6.1
|
|
8
14
|
|
|
9
15
|
### Added
|
|
10
16
|
|
|
11
|
-
*
|
|
17
|
+
* add support for `.env1` (`.env*`) file format. (private key expands to `DOTENV_PRIVATE_KEY_DEVELOPMENT1`) ([#312](https://github.com/dotenvx/dotenvx/pull/312))
|
|
12
18
|
|
|
13
19
|
## 1.6.0
|
|
14
20
|
|
package/package.json
CHANGED
package/src/lib/main.d.ts
CHANGED
|
@@ -35,14 +35,6 @@ export interface DotenvConfigOptions {
|
|
|
35
35
|
*/
|
|
36
36
|
encoding?: string;
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
* Turn on logging to help debug why certain keys or values are not being set as you expect.
|
|
40
|
-
*
|
|
41
|
-
* @default false
|
|
42
|
-
* @example require('@dotenvx/dotenvx').config({ debug: process.env.DEBUG })
|
|
43
|
-
*/
|
|
44
|
-
debug?: boolean;
|
|
45
|
-
|
|
46
38
|
/**
|
|
47
39
|
* Override any environment variables that have already been set on your machine with values from your .env file.
|
|
48
40
|
* @default false
|
|
@@ -77,6 +69,40 @@ export interface DotenvConfigOptions {
|
|
|
77
69
|
* Do not warn for missing .env files
|
|
78
70
|
*/
|
|
79
71
|
convention?: string;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Turn on logging to help debug why certain keys or values are not being set as you expect.
|
|
75
|
+
*
|
|
76
|
+
* @default false
|
|
77
|
+
* @example require('@dotenvx/dotenvx').config({ debug: process.env.DEBUG })
|
|
78
|
+
*/
|
|
79
|
+
debug?: boolean;
|
|
80
|
+
|
|
81
|
+
verbose?: boolean;
|
|
82
|
+
|
|
83
|
+
quiet?: boolean;
|
|
84
|
+
|
|
85
|
+
logLevel?:
|
|
86
|
+
| 'error'
|
|
87
|
+
| 'errorv'
|
|
88
|
+
| 'errorvp'
|
|
89
|
+
| 'errorvpb'
|
|
90
|
+
| 'errornocolor'
|
|
91
|
+
| 'warn'
|
|
92
|
+
| 'warnv'
|
|
93
|
+
| 'warnvp'
|
|
94
|
+
| 'warnvpb'
|
|
95
|
+
| 'success'
|
|
96
|
+
| 'successv'
|
|
97
|
+
| 'successvp'
|
|
98
|
+
| 'successvpb'
|
|
99
|
+
| 'info'
|
|
100
|
+
| 'help'
|
|
101
|
+
| 'help2'
|
|
102
|
+
| 'http'
|
|
103
|
+
| 'verbose'
|
|
104
|
+
| 'debug'
|
|
105
|
+
| 'blank';
|
|
80
106
|
}
|
|
81
107
|
|
|
82
108
|
export interface DotenvConfigOutput {
|
|
@@ -115,10 +141,13 @@ export function configDotenv(options?: DotenvConfigOptions): DotenvConfigOutput;
|
|
|
115
141
|
*
|
|
116
142
|
* @see https://dotenvx.com/docs
|
|
117
143
|
*
|
|
118
|
-
* @param
|
|
119
|
-
* @param
|
|
144
|
+
* @param envFile - the encrypted ciphertext string
|
|
145
|
+
* @param key - the decryption key(s)
|
|
120
146
|
*/
|
|
121
|
-
export function decrypt(
|
|
147
|
+
export function decrypt(
|
|
148
|
+
envFile?: string | string[],
|
|
149
|
+
key?: string | string[]
|
|
150
|
+
): string;
|
|
122
151
|
|
|
123
152
|
export type EncryptRowOutput = {
|
|
124
153
|
keys: string[];
|
|
@@ -143,10 +172,13 @@ export type EncryptOutput = {
|
|
|
143
172
|
* Encrypt plaintext
|
|
144
173
|
*
|
|
145
174
|
* @see https://dotenvx.com/docs
|
|
146
|
-
* @param envFile - path to the .env file
|
|
147
|
-
* @param key - keys(s) to encrypt (default: all keys in .env file)
|
|
175
|
+
* @param envFile - path to the .env file(s)
|
|
176
|
+
* @param key - keys(s) to encrypt env file(s) (default: all keys in .env file)
|
|
148
177
|
*/
|
|
149
|
-
export function encrypt(
|
|
178
|
+
export function encrypt(
|
|
179
|
+
envFile?: string | string[],
|
|
180
|
+
key?: string | string[]
|
|
181
|
+
): EncryptOutput;
|
|
150
182
|
|
|
151
183
|
export type VaultEncryptOutput = {
|
|
152
184
|
dotenvKeys: Record<string, string>;
|
|
@@ -158,21 +190,8 @@ export type VaultEncryptOutput = {
|
|
|
158
190
|
existingVaults: string[];
|
|
159
191
|
addedDotenvFilenames: string[];
|
|
160
192
|
envFile: string | string[];
|
|
161
|
-
key: string | string[];
|
|
162
193
|
};
|
|
163
194
|
|
|
164
|
-
/**
|
|
165
|
-
* Encrypt plaintext
|
|
166
|
-
*
|
|
167
|
-
* @see https://dotenvx.com/docs
|
|
168
|
-
* @param directory - current working directory
|
|
169
|
-
* @param envFile - path to the .env file(s)
|
|
170
|
-
*/
|
|
171
|
-
export function vaultEncrypt(
|
|
172
|
-
directory: string,
|
|
173
|
-
envFile: string | string[]
|
|
174
|
-
): VaultEncryptOutput;
|
|
175
|
-
|
|
176
195
|
/**
|
|
177
196
|
* List all env files in the current working directory
|
|
178
197
|
*
|
|
@@ -284,3 +303,22 @@ type KeyOfSettings = Extract<keyof Settings, string>;
|
|
|
284
303
|
export function settings(
|
|
285
304
|
key: KeyOfSettings | undefined | null = null
|
|
286
305
|
): Settings;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Decrypt ciphertext
|
|
309
|
+
* @param encrypted - the encrypted ciphertext string
|
|
310
|
+
* @param keyStr - the decryption key string
|
|
311
|
+
*/
|
|
312
|
+
export function vaultDecrypt(encrypted: string, keyStr: string): string;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Encrypt plaintext
|
|
316
|
+
*
|
|
317
|
+
* @see https://dotenvx.com/docs
|
|
318
|
+
* @param directory - current working directory
|
|
319
|
+
* @param envFile - path to the .env file(s)
|
|
320
|
+
*/
|
|
321
|
+
export function vaultEncrypt(
|
|
322
|
+
directory?: string,
|
|
323
|
+
envFile?: string | string[]
|
|
324
|
+
): VaultEncryptOutput;
|
|
@@ -11,6 +11,10 @@ const replace = require('./../helpers/replace')
|
|
|
11
11
|
const ENCODING = 'utf8'
|
|
12
12
|
|
|
13
13
|
class Decrypt {
|
|
14
|
+
/**
|
|
15
|
+
* @param {string|string[]} [envFile]
|
|
16
|
+
* @param {string|string[]} [key]
|
|
17
|
+
**/
|
|
14
18
|
constructor (envFile = '.env', key = []) {
|
|
15
19
|
this.envFile = envFile
|
|
16
20
|
this.key = key
|
|
@@ -12,6 +12,10 @@ const replace = require('./../helpers/replace')
|
|
|
12
12
|
const ENCODING = 'utf8'
|
|
13
13
|
|
|
14
14
|
class Encrypt {
|
|
15
|
+
/**
|
|
16
|
+
* @param {string|string[]} [envFile]
|
|
17
|
+
* @param {string|string[]} [key]
|
|
18
|
+
**/
|
|
15
19
|
constructor (envFile = '.env', key = []) {
|
|
16
20
|
this.envFile = envFile
|
|
17
21
|
this.key = key
|
|
@@ -59,8 +63,10 @@ class Encrypt {
|
|
|
59
63
|
// iterate over all non-encrypted values and encrypt them
|
|
60
64
|
const parsed = dotenv.parse(src)
|
|
61
65
|
for (const [key, value] of Object.entries(parsed)) {
|
|
62
|
-
if (keys.length < 1 || keys.includes(key)) {
|
|
63
|
-
|
|
66
|
+
if (keys.length < 1 || keys.includes(key)) {
|
|
67
|
+
// optionally control which key to encrypt
|
|
68
|
+
const encrypted =
|
|
69
|
+
isEncrypted(key, value) || isPublicKey(key, value)
|
|
64
70
|
if (!encrypted) {
|
|
65
71
|
row.keys.push(key) // track key(s)
|
|
66
72
|
|