New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@dotenvx/dotenvx

Package Overview
Dependencies
Maintainers
2
Versions
189
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dotenvx/dotenvx - npm Package Compare versions

Comparing version 1.25.0 to 1.25.1

src/lib/helpers/decryptKeyValue.js

8

CHANGELOG.md

@@ -5,4 +5,10 @@ # Changelog

[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.25.0...main)
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.25.1...main)
## [1.25.1](https://github.com/dotenvx/dotenvx/compare/v1.25.0...v1.25.1)
### Changed
* improve helpful error messaging around decryption failures by specifying specific key and private key name ([#463](https://github.com/dotenvx/dotenvx/pull/463))
## [1.25.0](https://github.com/dotenvx/dotenvx/compare/v1.24.5...v1.25.0)

@@ -9,0 +15,0 @@

2

package.json
{
"version": "1.25.0",
"version": "1.25.1",
"name": "@dotenvx/dotenvx",

@@ -4,0 +4,0 @@ "description": "a better dotenv–from the creator of `dotenv`",

@@ -1635,106 +1635,2 @@ [![dotenvx](https://dotenvx.com/better-banner.png)](https://dotenvx.com)

### config() 📦
* <details><summary>`config()`</summary><br>
Use directly in node.js code.
```ini
# .env
HELLO="World"
```
```js
// index.js
require('@dotenvx/dotenvx').config()
console.log(`Hello ${process.env.HELLO}`)
```
```sh
$ node index.js
[dotenvx@1.24.5] injecting env (1) from .env
Hello World
```
</details>
* <details><summary>`config(path: ['.env.local', '.env'])` - multiple files</summary><br>
Specify path(s) to multiple .env files.
```ini
# .env.local
HELLO="Me"
```
```ini
# .env
HELLO="World"
```
```js
// index.js
require('@dotenvx/dotenvx').config({path: ['.env.local', '.env']})
console.log(`Hello ${process.env.HELLO}`)
```
```sh
$ node index.js
[dotenvx@1.24.5] injecting env (1) from .env.local, .env
Hello Me
```
</details>
* <details><summary>`config(overload: true)` - overload</summary><br>
User `overload` to overwrite the prior set value.
```ini
# .env.local
HELLO="Me"
```
```ini
# .env
HELLO="World"
```
```js
// index.js
require('@dotenvx/dotenvx').config({path: ['.env.local', '.env'], overload: true})
console.log(`Hello ${process.env.HELLO}`)
```
```sh
$ node index.js
[dotenvx@1.24.5] injecting env (1) from .env.local, .env
Hello World
```
</details>
* <details><summary>`config(strict: true)` - strict</summary><br>
Use `strict` to throw if an error is encountered - like a missing .env file.
```ini
# .env
HELLO="World"
```
```js
// index.js
require('@dotenvx/dotenvx').config({path: ['.env.missing', '.env'], strict: true})
console.log(`Hello ${process.env.HELLO}`)
```
```sh
$ node index.js
Error: [MISSING_ENV_FILE] missing .env.missing file (/path/to/.env.missing)
```
</details>
### Extensions 🔌

@@ -1864,2 +1760,108 @@

### config() 📦
* <details><summary>`config()`</summary><br>
Use directly in node.js code.
```ini
# .env
HELLO="World"
```
```js
// index.js
require('@dotenvx/dotenvx').config()
console.log(`Hello ${process.env.HELLO}`)
```
```sh
$ node index.js
[dotenvx@1.24.5] injecting env (1) from .env
Hello World
```
</details>
* <details><summary>`config(path: ['.env.local', '.env'])` - multiple files</summary><br>
Specify path(s) to multiple .env files.
```ini
# .env.local
HELLO="Me"
```
```ini
# .env
HELLO="World"
```
```js
// index.js
require('@dotenvx/dotenvx').config({path: ['.env.local', '.env']})
console.log(`Hello ${process.env.HELLO}`)
```
```sh
$ node index.js
[dotenvx@1.24.5] injecting env (1) from .env.local, .env
Hello Me
```
</details>
* <details><summary>`config(overload: true)` - overload</summary><br>
User `overload` to overwrite the prior set value.
```ini
# .env.local
HELLO="Me"
```
```ini
# .env
HELLO="World"
```
```js
// index.js
require('@dotenvx/dotenvx').config({path: ['.env.local', '.env'], overload: true})
console.log(`Hello ${process.env.HELLO}`)
```
```sh
$ node index.js
[dotenvx@1.24.5] injecting env (1) from .env.local, .env
Hello World
```
</details>
* <details><summary>`config(strict: true)` - strict</summary><br>
Use `strict` to throw if an error is encountered - like a missing .env file.
```ini
# .env
HELLO="World"
```
```js
// index.js
require('@dotenvx/dotenvx').config({path: ['.env.missing', '.env'], strict: true})
console.log(`Hello ${process.env.HELLO}`)
```
```sh
$ node index.js
Error: [MISSING_ENV_FILE] missing .env.missing file (/path/to/.env.missing)
```
</details>
&nbsp;

@@ -1866,0 +1868,0 @@

@@ -0,1 +1,3 @@

const truncate = require('./truncate')
class Errors {

@@ -7,2 +9,6 @@ constructor (options = {}) {

this.key = options.key
this.privateKey = options.privateKey
this.privateKeyName = options.privateKeyName
this.message = options.message
}

@@ -29,4 +35,57 @@

}
missingPrivateKey () {
const code = 'MISSING_PRIVATE_KEY'
const message = `[${code}] could not decrypt ${this.key} using private key '${this.privateKeyName}=${truncate(this.privateKey)}'`
const help = `[${code}] https://github.com/dotenvx/dotenvx/issues/464`
const e = new Error(message)
e.code = code
e.help = help
return e
}
invalidPrivateKey () {
const code = 'INVALID_PRIVATE_KEY'
const message = `[${code}] could not decrypt ${this.key} using private key '${this.privateKeyName}=${truncate(this.privateKey)}'`
const help = `[${code}] https://github.com/dotenvx/dotenvx/issues/465`
const e = new Error(message)
e.code = code
e.help = help
return e
}
looksWrongPrivateKey () {
const code = 'WRONG_PRIVATE_KEY'
const message = `[${code}] could not decrypt ${this.key} using private key '${this.privateKeyName}=${truncate(this.privateKey)}'`
const help = `[${code}] https://github.com/dotenvx/dotenvx/issues/466`
const e = new Error(message)
e.code = code
e.help = help
return e
}
malformedEncryptedData () {
const code = 'MALFORMED_ENCRYPTED_DATA'
const message = `[${code}] could not decrypt ${this.key} because encrypted data appears malformed`
const help = `[${code}] https://github.com/dotenvx/dotenvx/issues/467`
const e = new Error(message)
e.code = code
e.help = help
return e
}
decryptionFailed () {
const code = 'DECRYPTION_FAILED'
const message = this.message
const e = new Error(message)
e.code = code
return e
}
}
module.exports = Errors
const chomp = require('./chomp')
const truncate = require('./truncate')
const decryptValue = require('./decryptValue')
const decryptKeyValue = require('./decryptKeyValue')
const resolveEscapeSequences = require('./resolveEscapeSequences')

@@ -10,5 +9,6 @@ const { execSync } = require('child_process')

constructor (src, privateKey = null, processEnv = process.env, overload = false) {
constructor (src, privateKey = null, processEnv = process.env, overload = false, privateKeyName = null) {
this.src = src
this.privateKey = privateKey
this.privateKeyName = privateKeyName
this.processEnv = processEnv

@@ -44,5 +44,5 @@ this.overload = overload

try {
this.parsed[key] = this.decrypt(this.parsed[key])
this.parsed[key] = this.decrypt(key, this.parsed[key])
} catch (e) {
this.errors.push(this.error(e, key))
this.errors.push(e)
}

@@ -133,4 +133,4 @@

decrypt (value) {
return decryptValue(value, this.privateKey)
decrypt (key, value) {
return decryptKeyValue(key, value, this.privateKeyName, this.privateKey)
}

@@ -213,12 +213,4 @@

}
error (e, key) {
const error = new Error(`[${e.code}] could not decrypt ${key} using private key '${truncate(this.privateKey)}'`)
error.code = e.code
error.help = `[${e.code}] ? ${e.message}`
return error
}
}
module.exports = Parse

@@ -11,3 +11,3 @@ const fsx = require('./../helpers/fsx')

const findPrivateKey = require('./../helpers/findPrivateKey')
const decryptValue = require('./../helpers/decryptValue')
const decryptKeyValue = require('./../helpers/decryptKeyValue')
const isEncrypted = require('./../helpers/isEncrypted')

@@ -90,3 +90,3 @@ const replace = require('./../helpers/replace')

const decryptedValue = decryptValue(value, privateKey)
const decryptedValue = decryptKeyValue(key, value, privateKeyName, privateKey)
// once newSrc is built write it out

@@ -93,0 +93,0 @@ envSrc = replace(envSrc, key, decryptedValue)

@@ -15,2 +15,3 @@ const fsx = require('./../helpers/fsx')

const findPrivateKey = require('./../helpers/findPrivateKey')
const guessPrivateKeyName = require('./../helpers/guessPrivateKeyName')
const determineEnvs = require('./../helpers/determineEnvs')

@@ -96,3 +97,4 @@

const privateKey = findPrivateKey(envFilepath)
const { parsed, errors, injected, preExisted } = new Parse(src, privateKey, this.processEnv, this.overload).run()
const privateKeyName = guessPrivateKeyName(envFilepath)
const { parsed, errors, injected, preExisted } = new Parse(src, privateKey, this.processEnv, this.overload, privateKeyName).run()

@@ -99,0 +101,0 @@ row.parsed = parsed

@@ -11,3 +11,3 @@ const fsx = require('./../helpers/fsx')

const encryptValue = require('./../helpers/encryptValue')
const decryptValue = require('./../helpers/decryptValue')
const decryptKeyValue = require('./../helpers/decryptKeyValue')
const replace = require('./../helpers/replace')

@@ -89,3 +89,3 @@ const detectEncoding = require('./../helpers/detectEncoding')

if (row.originalValue) {
row.originalValue = decryptValue(row.originalValue, privateKey)
row.originalValue = decryptKeyValue(row.key, row.originalValue, privateKeyName, privateKey)
}

@@ -92,0 +92,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc