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

app-etc

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

app-etc - npm Package Compare versions

Comparing version 0.0.5 to 1.0.0

1

lib/defaults.json
{
"local": "./etc",
"defaultsFile": "defaults",
"schemaFile": "",
"etc": "/etc",

@@ -5,0 +6,0 @@ "etcFile": "",

@@ -32,2 +32,3 @@ 'use strict';

* @param {String} [options.defaultsFile='defaults'] - basename of a file within the local application configuration directory which contains default application settings
* @param {String} [options.schemaFile] - basename of a file within the local application configuration directory which contains a configuration schema
* @param {String} [options.etc="/etc"] - application configuration directory

@@ -46,2 +47,3 @@ * @param {String} [options.etcFile] - basename of a file within the application configuration directory which contains application settings

var config,
schema,
fname,

@@ -54,2 +56,3 @@ uopts,

env,
out,
x,

@@ -76,5 +79,18 @@ i;

// Create a new application configuration:
config = createConfig();
// Attempt to load a configuration schema...
if ( opts.schemaFile ) {
debug( 'Attempting to load a configuration schema.' );
schema = load( ldir, opts.schemaFile );
if ( !schema ) {
debug( 'Unable to load a configuration schema. Ensure that a schema file exists and that the file is an accepted format.' );
}
}
// Create a new application configuration...
if ( schema ) {
config = createConfig({
'schema': schema
});
} else {
config = createConfig();
}
// Load configuration files...

@@ -126,2 +142,12 @@ debug( 'Loading configuration files.' );

debug( 'Finished loading configuration files.' );
if ( schema ) {
debug( 'Validating configuration.' );
out = config.validate();
if ( out !== true ) {
throw new Error( 'invalid configuration. Encountered the following errors during validation: ' + JSON.stringify( out ) + '.' );
}
debug( 'Configuration is valid.' );
}
debug( 'Done.' );
return config;

@@ -128,0 +154,0 @@ } // end FUNCTION etc()

@@ -20,2 +20,3 @@ 'use strict';

* @param {String} [options.defaultsFile] - basename of a file within the local application configuration directory which contains default application settings
* @param {String} [options.schemaFile] - basename of a file within the local application configuration directory which contains a configuration schema
* @param {String} [options.etc] - application configuration directory

@@ -48,2 +49,8 @@ * @param {String} [options.etcFile] - basename of a file within the application configuration directory which contains application settings

}
if ( options.hasOwnProperty( 'schemaFile' ) ) {
opts.schemaFile = options.schemaFile;
if ( !isString( opts.schemaFile ) ) {
return new TypeError( 'invalid option. `schemaFile` option must be a string primitive. Option: `' + opts.schemaFile + '`.' );
}
}
if ( options.hasOwnProperty( 'etc' ) ) {

@@ -50,0 +57,0 @@ opts.etc = options.etc;

7

package.json
{
"name": "app-etc",
"version": "0.0.5",
"version": "1.0.0",
"description": "Application configuration.",

@@ -42,3 +42,6 @@ "author": {

"utils",
"utility"
"utility",
"validate",
"validation",
"schema"
],

@@ -45,0 +48,0 @@ "bugs": {

@@ -33,2 +33,3 @@ etc

* __defaultsFile__: basename of a file within the *local* application configuration directory which contains *default* application settings. Default: `defaults`.
* __schemaFile__: basename of a file within the *local* application configuration directory which contains a [configuration schema](https://github.com/kgryte/node-app-etc-config).
* __etc__: application configuration directory. Default: [`/etc`](https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard).

@@ -274,2 +275,22 @@ * __etcFile__: basename of a file within an application configuration directory which contains application settings. The default value is the application [name](https://github.com/kgryte/resolve-app-pkginfo).

##### Configuration Schema
As more configuration sources are compiled into a single application configuration, the probability of a __misconfiguration__ increases. Misconfiguration can be problematic as downstream application configuration consumers often make assumptions regarding configuration structure, types, and properties. To enforce a configuration schema and ensure that these assumptions are not violated, specify the basename of a [JSON schema](http://json-schema.org/) file located in the __local__ application configuration directory.
``` javascript
var config = etc({
'schemaFile': 'schema.json'
});
```
__Notes__:
* If a `schemaFile` is a valid [JSON schema](http://json-schema.org/), the module validates the application [configuration](https://github.com/kgryte/node-app-etc-config) __after__ loading __all__ configuration sources.
* If a configuration is __invalid__, the module will `throw`.
* If a configuration is __valid__, the module returns an application [configuration](https://github.com/kgryte/node-app-etc-config) as per normal operation.
* If a `schemaFile` does not exist, the module will __not__ perform validation. Depending on your view, you may consider this behavior a __silent__ `error`.
* See the [examples](https://github.com/kgryte/node-app-etc/blob/master/examples/etc/schema.json) for a sample [JSON schema](http://json-schema.org/).
===

@@ -316,3 +337,4 @@ #### etc.parser( extname[, parser] )

var config = etc({
'local': path.join( __dirname, 'etc' )
'local': path.join( __dirname, 'etc' ),
'schemaFile': 'schema.json'
});

@@ -319,0 +341,0 @@ console.dir( config.get() );

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