
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@m1212e/konfigure
Advanced tools
konfigure allows you to easily define a schema for your application config and provides flexible sources and proper helpful errors without the need to manually use and check for any env or config file!
konfigure allows you to easily define a schema for your application config and provides flexible sources and proper helpful errors without the need to manually use and check for any env or config file!
Add the dependency
npm i @m1212e/konfigure
bun add @m1212e/konfigure
Then define a schema with either TypeBox, Zod or Valibot.
import { Type } from "@sinclair/typebox";
const appConfigSchema = Type.Object({
foo: Type.String(),
bar: Type.Optional(Type.Number()),
})
Afterwards, decide on which sources you would like to read for your config and in which order. Oftentimes, you'd have some mix of env vars and config file. Docker secrets are also supported. The available sources are exported from konfigure under the sources object.
import { env } from '@m1212e/konfigure/source/env.js';
import { dockerSecrets } from '@m1212e/konfigure/source/dockerSecrets.js';
import { jsonFile } from '@m1212e/konfigure/source/jsonFile.js';
import { object } from '@m1212e/konfigure/source/object.js';
const appConfigSources = [
env(),
dockerSecrets(),
jsonFile(join(import.meta.dir, "example.json")),
object({
foo: "fallback",
bar: 3,
})
]
Notice how we put the static object in the last place in the array. This results in the fallback values having the lowest priority and therefore beeing overwritten whenever a higher order source has the value present.
Finally, we put together our schema and sources in the konfigure call to read our config.
import { konfigure } from "@m1212e/konfigure";
const configObject = await konfigure({
schema: appConfigSchema,
sources: appConfigSources,
});
This outputs a strongly typed object according to the schema we defined, populated by the sources we decided on.
If you would like to see some more elaborate examples, see the examples directory.
In some cases we have some form of nested objects in our config. Say we want to group the db credentials and the host settings together in an object each. In cases like these you can use a delimeter ('_' per default) to set nested values in e.g. env vars or other sources which do not support nested data structures out of the box. Our konfigure call might look like this.
const configObject = await konfigure({
// delimeter: "_", // optionally, you can change the delimeter
schema: Type.Object({
db: Type.Object({
username: Type.String(),
password: Type.String(),
port: Type.String(),
host: Type.String(),
}),
application: Type.Object({
port: Type.String(),
host: Type.String(),
}),
}),
sources: [
/*
While our env vars are set like this:
db_username: "username",
db_password: "123",
db_port: "8822",
db_host: "localhost",
application_port: "3000",
application_host: "0.0.0.0",
*/
env(),
],
});
FAQs
konfigure allows you to easily define a schema for your application config and provides flexible sources and proper helpful errors without the need to manually use and check for any env or config file!
We found that @m1212e/konfigure demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.