Env and config
Your workspace code reads values from the environment with env(). The variables the
engine, the API and the workspace service read are in
Environment variables.
env()
A workspace author wraps a value with env("NAME") instead of reading
process.env directly at module-eval time. This keeps the pipeline
declaration, and anything that reads ChainRegistry.defs(), free of
resolved secrets:
import { env, isEnvRef } from "@health-samurai/interbox";
env("AIDBOX_CLIENT_SECRET"); // => { $env: "AIDBOX_CLIENT_SECRET" }
isEnvRef(env("X")); // => true
isEnvRef("literal-value"); // => false
interface EnvRef { readonly $env: string; readonly $default?: string }
function env(name: string, fallback?: string): EnvRef; // fallback = default when unset
function isEnvRef(value: unknown): value is EnvRef;
The engine resolves an EnvRef against its own process environment. A
workspace author never resolves one by hand. When the engine reads one depends on
where it sits:
| where | read |
|---|---|
aidbox(): url and the auth fields | as each send starts, so an unset variable with no default fails that send, and its items are tried again |
mllpSource(): port, host | checked when the workspace loads, so an unset variable with no default parks the pipeline, and read again when the source starts |
webhookSource(): path, secret | when the workspace loads, so an unset variable with no default parks the pipeline. A changed value applies at the next reload. A webhook source takes no port: the engine's INTERBOX_WEBHOOK_PORT sets the one port every webhook source listens on |
a source written with defineSource: its config | checked when the workspace loads, so an unset variable with no default parks the pipeline, and read again when the source starts |
.webhook(): url | when the workspace loads. An unset variable with no default parks the pipeline |
pullSender(): secret | when the workspace loads. An unset or empty variable parks the pipeline. It takes no default, so the secret stays out of the workspace code |
.webhook(): secret | as each delivery is sent. An unset variable fails that delivery for good |
a system declared with defineSystem | when the workspace loads. An unset variable with no default refuses the load |
Authoring types: Str / Num
Config fields that accept either a literal or env() use these two unions
instead of string/number:
type Str = string | EnvRef;
type Num = number | EnvRef;
The SDK's configs use them, for example MllpSourceConfig.port: Num and
AidboxConfig.url: Str (see Built-in sources, steps and senders).
Resolved<T>
A mapped type that strips every EnvRef branch out of an authoring config,
recursively. Str collapses to string, Num to number, and arrays and
nested objects are walked:
type Resolved<T> = T extends EnvRef
? never
: T extends readonly (infer U)[]
? Resolved<U>[]
: T extends object
? { [K in keyof T]: Resolved<T[K]> }
: T;
The engine uses it to derive its own factory config type from the SDK's
authoring config type (Resolved<FhirSystemConfig> for the fhirSystem
connector, for instance). That avoids a second, parallel "resolved" interface, written by hand,
that could drift from the authoring one.