kazana-config
Advanced tools
Comparing version 2.0.0 to 3.0.0
10
index.js
@@ -12,11 +12,1 @@ var config = require('./lib/config'); | ||
module.exports = config(); | ||
/** | ||
* exports method to set custom defaults for config | ||
* | ||
* var config = require('kazana-config')({appPort: 1234}) | ||
* config.appPort // 1234 by default | ||
* | ||
* @return Function | ||
*/ | ||
module.exports.defaults = config; |
module.exports = getConfig; | ||
module.exports.parseConfig = require('12factor-config'); | ||
var _ = require('lodash'); | ||
/** | ||
* parses [12config](https://www.npmjs.com/package/12factor-config)-compatible configuration | ||
* | ||
* @param {Object} defaults optional default properties to overwrite config defaults | ||
*/ | ||
function getConfig (defaults) { | ||
var config = module.exports.parseConfig({ | ||
function getConfig () { | ||
return module.exports.parseConfig({ | ||
appPort: { | ||
@@ -18,57 +14,64 @@ env: 'KAZANA_APP_PORT', | ||
}, | ||
accountPort: { | ||
env: 'KAZANA_ACCOUNTS_PORT', | ||
backendPort: { | ||
env: 'KAZANA_BACKEND_PORT', | ||
type: 'integer', | ||
default: 5001 | ||
default: 4999, | ||
description: 'Does not apply if KAZANA_BACKEND_NAME="couchdb"' | ||
}, | ||
rawDataPort: { | ||
env: 'KAZANA_IMPORTER_PORT', | ||
type: 'integer', | ||
default: 5002 | ||
adminUser: { | ||
env: 'KAZANA_ADMIN_USER', | ||
default: 'kazana' | ||
}, | ||
pouchdbAdapter: { | ||
env: 'KAZANA_POUCHDB_ADAPTER', | ||
// TODO: make this leveldb by default, to drop CouchDB dependency | ||
default: 'http' | ||
adminPass: { | ||
env: 'KAZANA_ADMIN_PASS', | ||
default: 'secret' | ||
}, | ||
pouchdbServerPort: { | ||
env: 'KAZANA_POUCHDB_SERVER_PORT', | ||
default: 4999 | ||
backendName: { | ||
env: 'KAZANA_BACKEND_NAME', | ||
description: 'When undefined, defaults to pouchdb-server\'s built-in "leveldown". Can be set to "couchdb" or any levelup storage back-ends: https://github.com/Level/levelup/wiki/Modules#storage-back-ends' | ||
}, | ||
pouchdbDataPath: { | ||
env: 'KAZANA_POUCHDB_DATA_PATH', | ||
default: './.db' | ||
backendLocation: { | ||
env: 'KAZANA_BACKEND_LOCATION', | ||
default: './.db/', | ||
description: 'location option as it gets passed to levelup https://github.com/Level/levelup#leveluplocation-options-callback If KAZANA_BACKEND_NAME="couchdb", set the couchdb url without credententials, e.g. "https://my.couch.com"' | ||
}, | ||
pouchdbHttpUrl: { | ||
env: 'KAZANA_POUCHDB_HTTP_URL' | ||
backendLogFile: { | ||
env: 'KAZANA_BACKEND_LOG_FILE', | ||
default: './.db/pouch.log', | ||
description: 'Does not apply if KAZANA_BACKEND_NAME="couchdb"' | ||
}, | ||
pouchdbHttpAdminUser: { | ||
env: 'KAZANA_POUCHDB_HTTP_ADMIN_USER', | ||
default: 'kazana' | ||
backendLogLevel: { | ||
env: 'KAZANA_BACKEND_LOG_LEVEL', | ||
default: 'info', | ||
description: 'Does not apply if KAZANA_BACKEND_NAME="couchdb"' | ||
}, | ||
pouchdbHttpAdminPass: { | ||
env: 'KAZANA_POUCHDB_HTTP_ADMIN_PASS', | ||
default: 'secret' | ||
backendConfigFile: { | ||
env: 'KAZANA_BACKEND_CONFIG_FILE', | ||
default: './.db/config.json', | ||
description: 'Does not apply if KAZANA_BACKEND_NAME="couchdb"' | ||
}, | ||
dbRawData: { | ||
env: 'KAZANA_DB_RAW_DATA', | ||
default: 'kazana-raw-data' | ||
default: 'kazana-raw-data', | ||
description: 'Name of database containing submitted raw data' | ||
}, | ||
dbIntegratedData: { | ||
env: 'KAZANA_DB_INTEGRATED_DATA', | ||
default: 'kazana-integrated-data' | ||
default: 'kazana-integrated-data', | ||
description: 'Name of database containing integrated data' | ||
}, | ||
emailService: { | ||
env: 'KAZANA_EMAIL_SERVICE', | ||
default: 'gmail' | ||
default: 'gmail', | ||
description: 'Nodemailer Email Service' | ||
}, | ||
emailAuthUsername: { | ||
env: 'KAZANA_EMAIL_AUTH_USERNAME' | ||
env: 'KAZANA_EMAIL_AUTH_USERNAME', | ||
description: 'Nodemailer Email Service Username' | ||
}, | ||
emailAuthPassword: { | ||
env: 'KAZANA_EMAIL_AUTH_PASSWORD' | ||
env: 'KAZANA_EMAIL_AUTH_PASSWORD', | ||
description: 'Nodemailer Email Service Password' | ||
} | ||
}); | ||
return _.merge(config, defaults); | ||
} |
{ | ||
"name": "kazana-config", | ||
"version": "2.0.0", | ||
"description": "Kazana core module for environment based configuration", | ||
@@ -9,10 +8,9 @@ "main": "index.js", | ||
"docs": "doxx --source ./ --target docs --ignore coverage,bin,node_modules,tests", | ||
"postpublish": "semantic-release post", | ||
"predeploydocs": "./bin/authorise-push.js", | ||
"predocs": "rimraf docs/build", | ||
"prepublish": "semantic-release pre", | ||
"test": "semistandard && npm run test:node | tap-spec", | ||
"test:coverage": "istanbul cover tests", | ||
"test:coverage:upload": "istanbul-coveralls", | ||
"test:node": "node tests" | ||
"test:node": "node tests", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post" | ||
}, | ||
@@ -37,16 +35,17 @@ "gh-pages-deploy": { | ||
"dependencies": { | ||
"12factor-config": "^1.0.0", | ||
"lodash": "^3.6.0" | ||
"12factor-config": "^1.0.1", | ||
"lodash": "^3.10.1" | ||
}, | ||
"devDependencies": { | ||
"doxx": "^1.4.0", | ||
"doxx": "^1.5.0", | ||
"gh-pages-deploy": "^0.3.0", | ||
"istanbul": "^0.3.17", | ||
"istanbul-coveralls": "^1.0.3", | ||
"rimraf": "^2.4.1", | ||
"semantic-release": "^3.3.2", | ||
"semistandard": "^6.1.2", | ||
"rimraf": "^2.4.2", | ||
"semantic-release": "^4.0.3", | ||
"semistandard": "^7.0.2", | ||
"tap-spec": "^4.0.2", | ||
"tape": "^4.0.0" | ||
} | ||
} | ||
"tape": "^4.1.0" | ||
}, | ||
"version": "3.0.0" | ||
} |
@@ -16,10 +16,2 @@ # kazana-config | ||
Defaults can be passed | ||
```js | ||
var config = require('kazana-config').defaults({ | ||
couchdbUrl: 'http://localhost:1234' | ||
}) | ||
``` | ||
Parse [12factor-config](https://www.npmjs.com/package/12factor-config) | ||
@@ -66,48 +58,76 @@ compatible configurations | ||
<td colspan="2"> | ||
<strong>kazanaAccountPort</strong><br> | ||
KAZANA_ACCOUNTS_PORT | ||
<strong>backendPort</strong><br> | ||
KAZANA_BACKEND_PORT | ||
</td> | ||
<td><code>5001</code></td> | ||
<td><code>4999</code></td> | ||
</tr> | ||
<tr> | ||
<td colspan="2"> | ||
<strong>kazanaRawDataPort</strong><br> | ||
KAZANA_IMPORTER_PORT | ||
<td> | ||
<strong>adminUser</strong><br> | ||
KAZANA_ADMIN_USER | ||
</td> | ||
<td><code>5002</code></td> | ||
<td> | ||
CouchDB admin username | ||
</td> | ||
<td><code>kazana</code></td> | ||
</tr> | ||
<tr> | ||
<td colspan="2"> | ||
<strong>pouchdbAdapter</strong><br> | ||
KAZANA_POUCHDB_ADAPTER | ||
<td> | ||
<strong>adminPass</strong><br> | ||
KAZANA_ADMIN_PASS | ||
</td> | ||
<td><code>http</code> <em>(<strong>Note</strong>: only http supperted so far)</em></td> | ||
<td> | ||
CouchDB admin password | ||
</td> | ||
<td><code>secret</code></td> | ||
</tr> | ||
<tr> | ||
<td colspan="2"> | ||
<strong>pouchdbLeveldb</strong><br> | ||
KAZANA_POUCHDB_LEVELDB_PATH | ||
<td> | ||
<strong>backendName</strong><br> | ||
KAZANA_BACKEND_NAME | ||
</td> | ||
<td> | ||
When undefined, defaults to pouchdb-server's built-in "leveldown". Can be set to "couchdb" or any levelup storage back-ends: https://github.com/Level/levelup/wiki/Modules#storage-back-ends | ||
</td> | ||
<td><code>-no default-</code></td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<strong>backendLocation</strong><br> | ||
KAZANA_BACKEND_LOCATION | ||
</td> | ||
<td> | ||
Location option as it gets passed to levelup https://github.com/Level/levelup#leveluplocation-options-callback If KAZANA_BACKEND_NAME="couchdb", set the couchdb url without credententials, e.g. "https://my.couch.com" | ||
</td> | ||
<td><code>./.db</code></td> | ||
</tr> | ||
<tr> | ||
<td colspan="2"> | ||
<strong>pouchdbHttpUrl</strong><br> | ||
KAZANA_POUCHDB_HTTP_URL | ||
<td> | ||
<strong>backendLogFile</strong><br> | ||
KAZANA_BACKEND_LOG_FILE | ||
</td> | ||
<td><code>http://localhost:5984</code></td> | ||
<td> | ||
Does not apply if KAZANA_BACKEND_NAME="couchdb" | ||
</td> | ||
<td><code>./.db/pouch.log</code></td> | ||
</tr> | ||
<tr> | ||
<td colspan="2"> | ||
<strong>pouchdbHttpAdminUser</strong><br> | ||
KAZANA_POUCHDB_HTTP_ADMIN_USER | ||
<td> | ||
<strong>backendLogLevel</strong><br> | ||
KAZANA_BACKEND_LOG_LEVEL | ||
</td> | ||
<td><code>kazana</code></td> | ||
<td> | ||
Does not apply if KAZANA_BACKEND_NAME="couchdb" | ||
</td> | ||
<td><code>info</code></td> | ||
</tr> | ||
<tr> | ||
<td colspan="2"> | ||
<strong>pouchdbHttpAdminPass</strong><br> | ||
KAZANA_POUCHDB_HTTP_ADMIN_PASS | ||
<td> | ||
<strong>backendConfigFile</strong><br> | ||
KAZANA_BACKEND_CONFIG_FILE | ||
</td> | ||
<td><code>secret</code></td> | ||
<td> | ||
Does not apply if KAZANA_BACKEND_NAME="couchdb" | ||
</td> | ||
<td><code>./.db/config.json</code></td> | ||
</tr> | ||
@@ -151,2 +171,3 @@ <tr> | ||
Nodemailer Email Service Username | ||
</td> | ||
<td>e.g. <code>joe@example.com</code></td> | ||
@@ -161,2 +182,3 @@ </tr> | ||
Nodemailer Email Service Password | ||
</td> | ||
<td>e.g. <code>secret</code></td> | ||
@@ -163,0 +185,0 @@ </tr> |
require('./specs/config'); | ||
require('./specs/defaults'); | ||
require('./specs/parse'); |
@@ -5,125 +5,56 @@ var test = require('tape'); | ||
t.plan(1); | ||
delete process.env.KAZANA_APP_PORT; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.appPort, 5000, 'defaults to 5000'); | ||
t.is(require('../../index.js').appPort, 5000, 'defaults to 5000'); | ||
}); | ||
test('config.accountPort', function (t) { | ||
test('config.backendPort', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_ACCOUNTS_PORT; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.accountPort, 5001, 'defaults to 5001'); | ||
t.is(require('../../index.js').backendPort, 4999, 'defaults to 4999'); | ||
}); | ||
test('config.rawDataPort', function (t) { | ||
test('config.adminUser', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_IMPORTER_PORT; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.rawDataPort, 5002, 'defaults to 5002'); | ||
t.is(require('../../index.js').adminUser, 'kazana', 'defaults to kazana'); | ||
}); | ||
test('config.pouchdbAdapter', function (t) { | ||
test('config.adminPass', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_POUCHDB_ADAPTER; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.pouchdbAdapter, 'http', 'defaults to http'); | ||
t.is(require('../../index.js').adminPass, 'secret', 'defaults to secret'); | ||
}); | ||
test('config.pouchdbServerPort', function (t) { | ||
test('config.backendName', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_POUCHDB_LEVELDB_PATH; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.pouchdbServerPort, 4999, 'defaults to ./.db'); | ||
t.is(require('../../index.js').backendName, undefined, 'defaults to <undefined>'); | ||
}); | ||
test('config.pouchdbDataPath', function (t) { | ||
test('config.backendLocation', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_POUCHDB_LEVELDB_PATH; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.pouchdbDataPath, './.db', 'defaults to ./.db'); | ||
t.is(require('../../index.js').backendLocation, './.db/', 'defaults to "./.db/"'); | ||
}); | ||
test('config.pouchdbHttpUrl', function (t) { | ||
test('config.backendLogFile', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_POUCHDB_HTTP_URL; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.pouchdbHttpUrl, undefined, 'defaults to undefined'); | ||
t.is(require('../../index.js').backendLogFile, './.db/pouch.log', 'defaults to "./.db/pouch.log"'); | ||
}); | ||
test('config.pouchdbHttpAdminUser', function (t) { | ||
test('config.backendLogLevel', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_POUCHDB_HTTP_ADMIN_USER; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.pouchdbHttpAdminUser, 'kazana', 'defaults to kazana'); | ||
t.is(require('../../index.js').backendLogLevel, 'info', 'defaults to "info"'); | ||
}); | ||
test('config.pouchdbHttpAdminPass', function (t) { | ||
test('config.backendConfigFile', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_POUCHDB_HTTP_ADMIN_PASS; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.pouchdbHttpAdminPass, 'secret', 'defaults to secret'); | ||
t.is(require('../../index.js').backendConfigFile, './.db/config.json', 'defaults to "./.db/config.json"'); | ||
}); | ||
test('config.dbRawData', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_DB_RAW_DATA; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.dbRawData, 'kazana-raw-data', 'defaults to kazana-raw-data'); | ||
t.is(require('../../index').dbRawData, 'kazana-raw-data', 'defaults to kazana-raw-data'); | ||
}); | ||
test('config.dbIntegratedData', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_DB_INTEGRATED_DATA; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.dbIntegratedData, 'kazana-integrated-data', 'defaults to kazana-integrated-data'); | ||
t.is(require('../../index').dbIntegratedData, 'kazana-integrated-data', 'defaults to kazana-integrated-data'); | ||
}); | ||
test('config.emailService', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_EMAIL_SERVICE; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.emailService, 'gmail', 'defaults to gmail'); | ||
t.is(require('../../index').emailService, 'gmail', 'defaults to gmail'); | ||
}); | ||
test('config.emailAuthUsername', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_EMAIL_AUTH_USERNAME; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.emailAuthUsername, undefined, 'defaults to undefined'); | ||
t.is(require('../../index').emailAuthUsername, undefined, 'defaults to undefined'); | ||
}); | ||
test('config.emailAuthPassword', function (t) { | ||
t.plan(1); | ||
delete process.env.KAZANA_EMAIL_AUTH_PASSWORD; | ||
require.cache = {}; | ||
var config = require('../../index'); | ||
t.is(config.emailAuthPassword, undefined, 'defaults to undefined'); | ||
t.is(require('../../index').emailAuthPassword, undefined, 'defaults to undefined'); | ||
}); | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 13 instances in 1 package
212
4
13454
178
2
Updated12factor-config@^1.0.1
Updatedlodash@^3.10.1