@stone-js/config-source
v0.8.15
Published
Agnostic configuration sources for Stone.js: load and merge config from env, files (json/yaml), AWS SSM, Secrets Manager, HTTP/GitHub and KMS-decrypted values into the blueprint before boot, with optional live reload.
Downloads
1,580
Maintainers
Readme
Stone.js - Config Source
Agnostic configuration sources for Stone.js. Load and merge configuration from many providers, env vars, JSON/YAML files, AWS SSM Parameter Store, Secrets Manager, an HTTP endpoint (a GitHub raw file, a gist), with KMS-decrypted values, into the blueprint before the app boots, so every blueprint middleware and provider sees the resolved config. Opt into live reload to refresh it on each incoming request.
Installation
npm install @stone-js/config-source
# only the drivers you use (optional peers, imported lazily):
npm install @aws-sdk/client-ssm @aws-sdk/client-secrets-manager @aws-sdk/client-kms js-yamlPeer dependency:
@stone-js/core. The AWS SDKs andjs-yamlare optional peers, imported lazily.
How it plugs in
The framework awaits a @Configuration()'s configure(blueprint) during initBlueprint, before the blueprint middleware run. Load your sources there and the whole app boots with the config already merged in:
import { Configuration } from '@stone-js/core'
import { loadConfigSources, envSource, fileSource, ssmSource, secretsSource, kmsDecryptor } from '@stone-js/config-source'
@Configuration()
export class AppConfig {
async configure (blueprint) {
await loadConfigSources(blueprint, [
envSource({ prefix: 'APP_' }),
fileSource({ path: './config.yaml', optional: true }),
ssmSource({ path: '/my-app/' }),
secretsSource({ secretId: 'my-app/prod' })
], { transform: kmsDecryptor() })
}
}Sources are merged in order (later wins). transform runs on every leaf value, kmsDecryptor() decrypts any string prefixed with kms:.
Live reload
Mark the configuration live and Stone reloads it on every incoming event (its native live-config mechanism), no restart needed:
@Configuration({ live: true })
export class LiveConfig {
async configure (blueprint) {
await loadConfigSources(blueprint, [ssmSource({ path: '/my-app/' })])
}
}Sources
| source | provider |
| ------ | -------- |
| envSource({ prefix?, env? }) | environment variables (prefix stripped) |
| fileSource({ path, format?, optional? }) | local JSON / YAML file |
| ssmSource({ path, region?, client? }) | AWS SSM Parameter Store (nested by path) |
| secretsSource({ secretId, region?, client? }) | AWS Secrets Manager (JSON secret) |
| httpSource({ url, headers?, format?, fetch? }) | any URL (GitHub raw, gist, config server) |
| kmsDecryptor({ region?, prefix? }) | a transform that decrypts kms:-prefixed values |
Use ConfigSourceManager directly for finer control (.add(), .load(), .loadInto(blueprint)).
