@dotenvx/dotenvx 1.34.0 → 1.35.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,16 @@
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.34.0...main)
5
+ [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.35.0...main)
6
+
7
+ ## [1.35.0](https://github.com/dotenvx/dotenvx/compare/v1.34.0...v1.35.0)
8
+
9
+ ### Added
10
+
11
+ * `npx dotenvx precommit` support as a convenience ([#523](https://github.com/dotenvx/dotenvx/pull/523))
12
+ * `main.get` method ([#524](https://github.com/dotenvx/dotenvx/pull/524))
13
+
14
+ The addition of `main.get` facilitates what we term Decryption at Access, a concept explored in greater detail in our [whitepaper](https://dotenvx.com/dotenvx.pdf).
6
15
 
7
16
  ## [1.34.0](https://github.com/dotenvx/dotenvx/compare/v1.33.0...v1.34.0)
8
17
 
package/README.md CHANGED
@@ -19,7 +19,7 @@ npm install @dotenvx/dotenvx --save
19
19
  ```js
20
20
  // index.js
21
21
  require('@dotenvx/dotenvx').config()
22
- // or import('@dotenvx/dotenvx/config') if you're using esm
22
+ // or import '@dotenvx/dotenvx/config' // for esm
23
23
 
24
24
  console.log(`Hello ${process.env.HELLO}`)
25
25
  ```
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.34.0",
2
+ "version": "1.35.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -3,15 +3,19 @@ const path = require('path')
3
3
 
4
4
  const HOOK_SCRIPT = `#!/bin/sh
5
5
 
6
- if ! command -v dotenvx 2>&1 >/dev/null
6
+ if command -v dotenvx 2>&1 >/dev/null
7
7
  then
8
+ dotenvx ext precommit
9
+ elif npx dotenvx -V >/dev/null 2>&1
10
+ then
11
+ npx dotenvx ext precommit
12
+ else
8
13
  echo "[dotenvx][precommit] 'dotenvx' command not found"
9
14
  echo "[dotenvx][precommit] ? install it with [curl -fsS https://dotenvx.sh | sh]"
10
15
  echo "[dotenvx][precommit] ? other install options [https://dotenvx.com/docs/install]"
11
16
  exit 1
12
17
  fi
13
-
14
- dotenvx ext precommit`
18
+ `
15
19
 
16
20
  class InstallPrecommitHook {
17
21
  constructor () {
package/src/lib/main.d.ts CHANGED
@@ -194,6 +194,13 @@ export interface SetOptions {
194
194
  * Set a .env convention (available conventions: 'nextjs')
195
195
  */
196
196
  convention?: string;
197
+
198
+ /**
199
+ * Specify whether the variable has to be encrypted
200
+ * @default true
201
+ * @example require('@dotenvx/dotenvx').config(key, value, { encrypt: false } })
202
+ */
203
+ encrypt?: boolean;
197
204
  }
198
205
 
199
206
  export type SetOutput = {
package/src/lib/main.js CHANGED
@@ -9,6 +9,7 @@ const { getColor, bold } = require('./../shared/colors')
9
9
  const Ls = require('./services/ls')
10
10
  const Run = require('./services/run')
11
11
  const Sets = require('./services/sets')
12
+ const Get = require('./services/get')
12
13
  const Keypair = require('./services/keypair')
13
14
  const Genexample = require('./services/genexample')
14
15
 
@@ -57,7 +58,6 @@ const config = function (options = {}) {
57
58
  let lastError
58
59
  /** @type {Record<string, string>} */
59
60
  const parsedAll = {}
60
-
61
61
  for (const processedEnv of processedEnvs) {
62
62
  if (processedEnv.type === 'envVaultFile') {
63
63
  logger.verbose(`loading env from encrypted ${processedEnv.filepath} (${path.resolve(processedEnv.filepath)})`)
@@ -234,6 +234,58 @@ const set = function (key, value, options = {}) {
234
234
  }
235
235
  }
236
236
 
237
+ /* @type {import('./main').get} */
238
+ const get = function (key, options = {}) {
239
+ const envs = buildEnvs(options)
240
+
241
+ // ignore
242
+ const ignore = options.ignore || []
243
+
244
+ const { parsed, errors } = new Get(key, envs, options.overload, process.env.DOTENV_KEY, options.all, options.envKeysFile).run()
245
+
246
+ for (const error of errors || []) {
247
+ if (options.strict) throw error // throw immediately if strict
248
+
249
+ if (ignore.includes(error.code)) {
250
+ continue // ignore error
251
+ }
252
+
253
+ console.error(error.message)
254
+ if (error.help) {
255
+ console.error(error.help)
256
+ }
257
+ }
258
+
259
+ if (key) {
260
+ const single = parsed[key]
261
+ if (single === undefined) {
262
+ return undefined
263
+ } else {
264
+ return single
265
+ }
266
+ } else {
267
+ if (options.format === 'eval') {
268
+ let inline = ''
269
+ for (const [key, value] of Object.entries(parsed)) {
270
+ inline += `${key}=${escape(value)}\n`
271
+ }
272
+ inline = inline.trim()
273
+
274
+ return inline
275
+ } else if (options.format === 'shell') {
276
+ let inline = ''
277
+ for (const [key, value] of Object.entries(parsed)) {
278
+ inline += `${key}=${value} `
279
+ }
280
+ inline = inline.trim()
281
+
282
+ return inline
283
+ } else {
284
+ return parsed
285
+ }
286
+ }
287
+ }
288
+
237
289
  /** @type {import('./main').ls} */
238
290
  const ls = function (directory, envFile, excludeEnvFile) {
239
291
  return new Ls(directory, envFile, excludeEnvFile).run()
@@ -260,6 +312,7 @@ module.exports = {
260
312
  parse,
261
313
  // actions related
262
314
  set,
315
+ get,
263
316
  ls,
264
317
  keypair,
265
318
  genexample,