0.10.0 • Published 5 years ago

@brickblock/strong-config v0.10.0

Weekly downloads
100
License
MIT
Repository
-
Last release
5 years ago

@brickblock/strong-config

strong-config is a library that does 4 things:

  1. Loads a file (yaml or json) into memory as an object
  2. Optionally, decrypts a sops encrypted file
  3. Optionally, validates the config against a schema defined in json-schema
  4. Substitutes environment variables with the loaded and decrypted values from memory

Installation

The library should be installed as a dependency:

yarn add @brickblock/strong-config

Conventions

  • strong-config will read the config from config/${NODE_ENV}.[yml|yaml|json]
  • If the config file contains a sops key, it is assumed to be encrypted and it will be decrypted using sops. sops must already be available on your $PATH
  • If a config/schema.[yml|yaml|json] exists, the resulting config object is validated against the schema using json-schema
  • If the config file has any instances of ${ENV_VAR} it will be substituted with the value defined in the environment.

Usage

NODE_ENV=production yarn start
/* config/production.json */

"logger": {
  "name": "my-prod-logger"
  "level": "INFO"
}
/* index.js */

const config = require('@brickblock/strong-config').load()
// config = { logger: { name: 'my-prod-logger', level: 'INFO' }}

const logger = bunyan.createLogger(config.logger)

Flow Types for Schemas

When given a valid json-schema, this package will automatically generate a flow type of the schema to allow strongly-typing the config-object in consuming applications.

Caveats

  1. The consuming application must be executed with NODE_ENV=development to trigger the flow type generation
  2. Schema must be a JSON file

Using the type

When using .load(), flow will automatically pick up the auto-generated type definition at @brickblock/strong-config/build/index.flow and will use it to strongly-type the config-object:

/* ./src/index.js */

// @flow
const config = require('@brickblock/strong-config').load()

// flow will warn that the `config` object doesn't have the key `nonExistentConfigKey`!
const ProblematicComponent = () => <div>{config.nonExistentConfigKey}</div>

Next Steps

Follow the Onboarding tutorial

0.10.0

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.4

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago