@dotenvx/dotenvx 1.25.1 → 1.26.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.
package/CHANGELOG.md CHANGED
@@ -2,7 +2,23 @@
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.25.1...main)
5
+ [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.26.0...main)
6
+
7
+ ## [1.26.0](https://github.com/dotenvx/dotenvx/compare/v1.25.2...v1.26.0)
8
+
9
+ ### Added
10
+
11
+ * add `privateKey` option to `main.parse` method ([#474](https://github.com/dotenvx/dotenvx/pull/474))
12
+
13
+ ## [1.25.2](https://github.com/dotenvx/dotenvx/compare/v1.25.1...v1.25.2)
14
+
15
+ ### Added
16
+
17
+ * for binaries add pre-build step using esbuild ([#471](https://github.com/dotenvx/dotenvx/pull/471))
18
+
19
+ ### Removed
20
+
21
+ * remove types for functions that were removed a while back ([2aa660](https://github.com/dotenvx/dotenvx/commit/2aa660695757143f65751a201115f074b81942a8))
6
22
 
7
23
  ## [1.25.1](https://github.com/dotenvx/dotenvx/compare/v1.25.0...v1.25.1)
8
24
 
package/README.md CHANGED
@@ -1859,8 +1859,59 @@ More examples
1859
1859
  ```
1860
1860
 
1861
1861
  </details>
1862
+ * <details><summary>`parse(src)`</summary><br>
1862
1863
 
1864
+ Parse a `.env` string directly in node.js code.
1863
1865
 
1866
+ ```js
1867
+ // index.js
1868
+ const dotenvx = require('@dotenvx/dotenvx')
1869
+ const src = 'HELLO=World'
1870
+ const parsed = dotenvx.parse(src)
1871
+ console.log(`Hello ${parsed.HELLO}`)
1872
+ ```
1873
+
1874
+ ```sh
1875
+ $ node index.js
1876
+ Hello World
1877
+ ```
1878
+
1879
+ </details>
1880
+ * <details><summary>`parse(src, {processEnv:})`</summary><br>
1881
+
1882
+ Sometimes, you want to run `parse` without it accessing `process.env`. (You can pass a fake processEnv this way as well - sometimes useful.)
1883
+
1884
+ ```js
1885
+ // index.js
1886
+ const dotenvx = require('@dotenvx/dotenvx')
1887
+ const src = 'USER=Me'
1888
+ const parsed = dotenvx.parse(src, { processEnv: {} })
1889
+ console.log(`Hello ${parsed.USER}`)
1890
+ ```
1891
+
1892
+ ```sh
1893
+ $ node index.js
1894
+ Hello Me
1895
+ ```
1896
+
1897
+ </details>
1898
+ * <details><summary>`parse(src, {privateKey:})`</summary><br>
1899
+
1900
+ Decrypt an encrypted `.env` string with `privateKey`.
1901
+
1902
+ ```js
1903
+ // index.js
1904
+ const dotenvx = require('@dotenvx/dotenvx')
1905
+ const src = 'HELLO="encrypted:BE9Y7LKANx77X1pv1HnEoil93fPa5c9rpL/1ps48uaRT9zM8VR6mHx9yM+HktKdsPGIZELuZ7rr2mn1gScsmWitppAgE/1lVprNYBCqiYeaTcKXjDUXU5LfsEsflnAsDhT/kWG1l"'
1906
+ const parsed = dotenvx.parse(src, { privateKey: 'a4547dcd9d3429615a3649bb79e87edb62ee6a74b007075e9141ae44f5fb412c' })
1907
+ console.log(`Hello ${parsed.HELLO}`)
1908
+ ```
1909
+
1910
+ ```sh
1911
+ $ node index.js
1912
+ Hello World
1913
+ ```
1914
+ </details>
1864
1915
 
1865
1916
  &nbsp;
1866
1917
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.25.1",
2
+ "version": "1.26.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -48,6 +48,7 @@
48
48
  "devDependencies": {
49
49
  "@yao-pkg/pkg": "^5.14.2",
50
50
  "capture-console": "^1.0.2",
51
+ "esbuild": "^0.24.0",
51
52
  "proxyquire": "^2.1.3",
52
53
  "sinon": "^14.0.1",
53
54
  "standard": "^17.1.0",
package/src/lib/main.d.ts CHANGED
@@ -124,50 +124,6 @@ export interface DotenvPopulateInput {
124
124
  */
125
125
  export function config(options?: DotenvConfigOptions): DotenvConfigOutput;
126
126
 
127
- /**
128
- * Decrypt ciphertext
129
- *
130
- * @see https://dotenvx.com/docs
131
- *
132
- * @param envFile - the encrypted ciphertext string
133
- * @param key - the decryption key(s)
134
- */
135
- export function decrypt(
136
- envFile?: string | string[],
137
- key?: string | string[]
138
- ): string;
139
-
140
- export type EncryptRowOutput = {
141
- keys: string[];
142
- filepath: string;
143
- envFilepath: string;
144
- publicKey: string;
145
- privateKey: string;
146
- privateKeyName: string;
147
- privateKeyAdded: boolean;
148
- envSrc: string;
149
- changed: boolean;
150
- error?: Error;
151
- };
152
-
153
- export type EncryptOutput = {
154
- processedEnvFiles: EncryptRowOutput[];
155
- changedFilepaths: string[];
156
- unchangedFilepaths: string[];
157
- };
158
-
159
- /**
160
- * Encrypt plaintext
161
- *
162
- * @see https://dotenvx.com/docs
163
- * @param envFile - path to the .env file(s)
164
- * @param key - keys(s) to encrypt env file(s) (default: all keys in .env file)
165
- */
166
- export function encrypt(
167
- envFile?: string | string[],
168
- key?: string | string[]
169
- ): EncryptOutput;
170
-
171
127
  /**
172
128
  * List all env files in the current working directory
173
129
  *
@@ -181,53 +137,6 @@ export function ls(
181
137
  excludeEnvFile: string | string[]
182
138
  ): string[];
183
139
 
184
- /**
185
- * Get the value of a key from the .env file
186
- *
187
- * @param [key] - the key to get the value of
188
- * @param [envs] - the environment(s) to get the value from
189
- * @param [overload] - whether to overload the value from the .env file
190
- * @param [DOTENV_KEY] - the decryption key string
191
- * @param [all] - whether to return all values
192
- */
193
- export function get(
194
- key?: string,
195
- envs?: string[],
196
- overload?: boolean,
197
- DOTENV_KEY?: string,
198
- all?: boolean
199
- ): Record<string, string | undefined> | string | undefined;
200
-
201
- export type SetOutput = {
202
- key: string;
203
- value: string;
204
- filepath: string;
205
- envFilepath: string;
206
- envSrc: string;
207
- changed: boolean;
208
- encryptedValue?: string;
209
- publicKey?: string;
210
- privateKey?: string;
211
- privateKeyAdded?: boolean;
212
- privateKeyName?: string;
213
- error?: Error;
214
- };
215
-
216
- /**
217
- * Set the value of a key in the .env file
218
- *
219
- * @param key - the key to set the value of
220
- * @param value - the value to set
221
- * @param envFile - the path to the .env file
222
- * @param [encrypt] - whether to encrypt the value
223
- */
224
- export function set(
225
- key: string,
226
- value: string,
227
- envFile: string | string,
228
- encrypt?: boolean
229
- ): EncryptOutput;
230
-
231
140
  export type GenExampleOutput = {
232
141
  envExampleFile: string;
233
142
  envFile: string | string[];
package/src/lib/main.js CHANGED
@@ -154,12 +154,20 @@ const parse = function (src, options = {}) {
154
154
  }
155
155
 
156
156
  // private decryption key
157
- const privateKey = null // implement later
157
+ const privateKey = options.privateKey || null
158
158
 
159
159
  // overload
160
160
  const overload = options.overload || options.override
161
161
 
162
- const { parsed } = new Parse(src, privateKey, processEnv, overload).run()
162
+ const { parsed, errors } = new Parse(src, privateKey, processEnv, overload).run()
163
+
164
+ // display any errors
165
+ for (const error of errors) {
166
+ console.error(error.message)
167
+ if (error.help) {
168
+ console.error(error.help)
169
+ }
170
+ }
163
171
 
164
172
  return parsed
165
173
  }