Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tsmx/secure-config

Package Overview
Dependencies
Maintainers
0
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tsmx/secure-config - npm Package Compare versions

Comparing version 2.2.1 to 2.3.0

eslint.config.js

7

package.json
{
"name": "@tsmx/secure-config",
"version": "2.2.1",
"version": "2.3.0",
"description": "Easy and secure configuration management. JSON based encrypted secrets, optional HMAC validation.",

@@ -40,3 +40,6 @@ "main": "secure-config.js",

"devDependencies": {
"eslint": "^8.41.0",
"@eslint/js": "^9.8.0",
"eslint": "^9.8.0",
"eslint-plugin-jest": "^28.8.0",
"globals": "^15.9.0",
"jest": "^29.7.0"

@@ -43,0 +46,0 @@ },

@@ -66,3 +66,3 @@ # [**@tsmx/secure-config**](https://github.com/tsmx/secure-config)

All configuration files must be located in a `conf/` directory of the current running app, meaning a direct subdirectory of the current working directory (`CWD/conf/`).
By default, all configuration files are expected be located in a `conf/` directory of the current running app, meaning a direct subdirectory of the current working directory (`CWD/conf/`). To overwrite this behaviour, you can pass the [directory](#directory) option.

@@ -108,2 +108,3 @@ ### Example structure

hmacProperty: '_signature',
directory: '/path/to/config',
prefix: 'myconf'

@@ -183,2 +184,28 @@ }

### directory
Type: `String`
Default: `./conf/`
Use this parameter to change the directory where the configuration files should be loaded from.
E.g. if the files are located under `/var/myapp/configurations`:
```js
const confOptions = {
directory: '/var/myapp/configurations'
}
const conf = require('@tsmx/secure-config')(confOptions);
```
This option can be combined with the [prefix](#prefix) option to control the configuration filenames within the directory. [Naming conventions](#naming-conventions) according to `NODE_ENV` are applied as normal.
***Hint:*** Setting a relative path within the current running app or an unit-test can easily be achieved by using `path.join` with `process.cwd`. E.g. if the files are located in `./test/configurations`.
```js
const confOptions = {
directory: path.join(process.cwd(), 'test/configurations')
}
```
### prefix

@@ -310,2 +337,5 @@

### 2.3.0
- Support for custom configuration file path with new option [directory](#directory) added.
## Test

@@ -312,0 +342,0 @@

@@ -55,4 +55,5 @@ const path = require('path');

const prefix = getOptValue(options, 'prefix', defaultFilePrefix);
const directory = getOptValue(options, 'directory', path.join(process.cwd(), defaultDirectory));
const confFileName = prefix + (process.env.NODE_ENV ? '-' + process.env.NODE_ENV : '') + '.json';
const confPath = path.join(process.cwd(), defaultDirectory, confFileName);
const confPath = path.join(directory, confFileName);
if (!fs.existsSync(confPath)) {

@@ -74,2 +75,2 @@ throw new Error(`Configuration file for NODE_ENV ${process.env.NODE_ENV} and prefix ${prefix} does not exist.`);

return conf;
};
};

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

const path = require('path');
describe('secure-config multiconf feature test suite (v2 features)', () => {

@@ -98,2 +100,45 @@

it('tests a successful production configuration retrieval with custom directory', () => {
process.env['CONFIG_ENCRYPTION_KEY'] = confKey;
process.env['NODE_ENV'] = 'production';
const conf = require('../secure-config')({ directory: path.join(process.cwd(), 'test/configurations') });
expect(conf.info).toEqual('production-custom-dir');
expect(conf.database.host).toBe('db.prod.com');
expect(conf.database.user).toBe('SecretUser-Prod');
expect(conf.database.password).toBe('SecretPassword-Prod');
expect(conf.filestorage.type).toBe('local');
expect(conf.filestorage.params.folder).toBe('/tmp/storage');
expect(conf.filestorage.params.storagepass).toBe('StoragePassword-Prod');
expect(conf.testarray.length).toEqual(2);
expect(conf.testarray[0].arrayItemKey).toEqual('itemValue1');
expect(conf.testarray[1].arrayItemKey).toEqual('itemValue2');
});
it('tests a successful production configuration retrieval with custom file prefix and custom directory', () => {
process.env['CONFIG_ENCRYPTION_KEY'] = myconfKey;
const conf = require('../secure-config')({ prefix: 'myconf', directory: path.join(process.cwd(), 'test/configurations') });
expect(conf.info).toEqual('myconf-custom-dir');
expect(conf.database.host).toBe('127.0.0.1');
expect(conf.database.user).toBe('SecretUser');
expect(conf.database.password).toBe('SecretPassword');
expect(conf.filestorage.type).toBe('local');
expect(conf.filestorage.params.folder).toBe('/tmp/storage');
expect(conf.filestorage.params.storagepass).toBe('StoragePassword');
expect(conf.testarray).toBeDefined();
expect(Array.isArray(conf.testarray)).toBeTruthy();
expect(conf.testarray.length).toBe(6);
expect(conf.testarray[0]).toEqual('one');
expect(conf.testarray[1]).toEqual('two');
expect(conf.testarray[2]).toEqual('three');
expect(conf.testarray[3].arrayItemKey).toEqual('itemValue1');
expect(conf.testarray[3].additionalItem1).toEqual('value1');
expect(conf.testarray[4].arrayItemKey).toEqual('itemValue2');
expect(conf.testarray[4].additionalItem1).toEqual('value1');
expect(conf.testarray[4].additionalItem2).toEqual(12);
expect(conf.testarray[5].length).toEqual(1);
expect(conf.testarray[5][0].subArrayItemKey).toEqual('subArrayItemValue');
expect(conf.nullvalue).toBe(null);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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