@kindgi/env-schema
v0.8.1
Published
Machine-readable registry of the Kindgi runtime's operator-facing env vars. Single source of truth for boot-time validation (validateEnvForTarget), .env.example scaffolding (renderEnvExample), and tools or coding agents introspecting deployment config. Ad
Readme
@kindgi/env-schema
Machine-readable registry of the Kindgi runtime's operator-facing env vars. Single source of truth for:
- Boot-time validation —
validateEnvForTargetreports the required vars a deployment target is missing. .env.examplescaffolding —renderEnvExamplerendersKINDGI_ENV_SCHEMA(or a filtered part of it) as an.env.examplebody.- Tools and coding agents —
import { KINDGI_ENV_SCHEMA }to introspect deployment-config surface without parsing source.
Adding a new env var
Append one entry to KINDGI_ENV_SCHEMA in
packages/env-schema/src/schema.ts. A KINDGI_* var that is not
declared there is invisible to envVarsForTarget,
validateEnvForTarget and renderEnvExample.
{
name: 'KINDGI_MY_NEW_VAR',
description: 'One-line human-readable explanation.',
example: 'realistic-placeholder',
required: true, // false = optional (default applies)
appliesTo: (t) => t.secretsBackend === 'postgres',
group: 'secrets',
allowedValues: ['a', 'b', 'c'], // optional enum hint
},Targets
An EnvTarget narrows the vars to one deployment's choices. Every
field is optional:
component: which process reads the env, the Kindgiserver(the default) or thepack-service, the separate process that runs a pack's code (its tools and guardrail checks). The pack service's target listsKINDGI_PACK_SERVICE_TOKEN,KINDGI_PACK_INDEX,KINDGI_PACK_SERVICE_MAX_CONCURRENCY,KINDGI_PACK_ENV_CHECK,KINDGI_PACK_ENV_FILTER,KINDGI_PACK_ENV_DECLAREDandKINDGI_PACK_TENANT_ID(the one tenant it serves, when set), and none of the server's vars. It also listens onPORT(default 8080), the platform convention, which isn't a Kindgi variable.secretsBackend,secretsBackendKms: the server's secrets backend and its KMS vendor.packTransport:httpwhen the server calls a pack service atKINDGI_PACK_SERVICE_URL. Its token (KINDGI_PACK_SERVICE_TOKEN, shared with the pack service) is then required, andKINDGI_PACK_CALL_TIMEOUT_MSandKINDGI_PACK_SERVICE_AUTHapply. The server'sKINDGI_PACK_ROUTING(singleby default, orper-deployment, which needsKINDGI_PACK_ENDPOINT_HOSTS, andKINDGI_PACK_ENDPOINT_KMS_KEYunless the secrets backend ispostgres) picks the pack service for each call; their parsers (parsePackRouting,parsePackEndpointHosts,packEndpointHostAllowed,parsePackEndpointKmsKey,parsePackTenantId) are exported, so the server and the pack service read them the same way.
What lives here
KINDGI_*(operator-facing) → declared here. Anything an operator sets in their Docker Compose / K8s ConfigMap /.envfile.- Internal opt-in switches that are not deployment config are not declared here.
API
import {
KINDGI_ENV_SCHEMA,
envVarsForTarget,
renderEnvExample,
validateEnvForTarget,
type EnvTarget,
type EnvVarSpec,
} from '@kindgi/env-schema';
// Filter to just vars that apply to a target.
const target: EnvTarget = { secretsBackend: 'postgres', secretsBackendKms: 'gcp' };
const vars = envVarsForTarget(target);
// Render as .env.example body.
const body = renderEnvExample(vars);
writeFileSync('.env.example', body);
// Validate a resolved env at boot.
const result = validateEnvForTarget(process.env, target);
if (!result.ok) {
throw new Error(`Missing required env vars: ${result.missing.join(', ')}`);
}Dependencies
Apache 2.0. Its one dependency is @kindgi/types (for the shared UUID
check), which has none, so tooling and the runtime can both consume it.
