@health-samurai/interbox
Subpaths
| import | what it is |
|---|---|
@health-samurai/interbox | env, the error taxonomy, defineSystem, provenanceId (below), and the 1.x pipeline DSL (see 1.x API) |
@health-samurai/interbox/chain | the 2.0 pipeline DSL: pipeline, defineStep, defineState, defineLookup, NotReady, postgresStore, defineSender, pullSender, mllpSource, webhookSource, the bridges and ChainRegistry. See Steps and batches, A queue consumers poll for pullSender, Built-in sources, steps and senders for the two sources, and Reference lookups for defineLookup and NotReady |
@health-samurai/interbox/hl7v2 | generated HL7v2 domain model, parser and the hl7v2Parser() step. See /hl7v2 |
@health-samurai/interbox/xml | the xmlReader() step and readXml(), which read an XML document with XPath, and the xmlWriter() step and writeXml(), which write one. See Built-in sources, steps and senders |
@health-samurai/interbox/aidbox | the fhirItems() and skipUnchanged() steps and the aidbox() sender. See Built-in sources, steps and senders |
@health-samurai/interbox/admin | functions a workspace script reads and changes units with. See Admin scripts |
@health-samurai/interbox/core | shared stage contracts, rarely imported directly. See /core |
@health-samurai/interbox/builtins | typed descriptors for the engine's built-ins: the system connectors, and the 1.x stages (see 1.x API). See /builtins |
@health-samurai/interbox/postgres | postgresConfig() and forgetRefusedCredential(): the engine's PostgreSQL connection settings for a workspace script or action, see Admin scripts and Databricks Lakebase |
@health-samurai/interbox/files | fileDropSource, its transports and the steps that split a file. See /files |
@health-samurai/interbox/fhir | FHIR R4 core types and profile helpers. See /fhir |
@health-samurai/interbox/fhir/4.0.1 | same, pinned to the 4.0.1 subpath explicitly |
@health-samurai/interbox/fhir/4.0.1/profiles | generated profile classes |
@health-samurai/interbox/fhir/4.0.1/profile-helpers | runtime helpers profile classes call |
Root exports
Pipeline authoring
See Pipelines.
A 2.0 pipeline is declared with pipeline from @health-samurai/interbox/chain,
not with the root's. The engine reads the pipelines from the ChainRegistry
that the workspace's src/index.ts exports. It reads the declared systems from SystemRegistry and the
reference lookups its
steps may use from LookupRegistry:
export { ChainRegistry } from "@health-samurai/interbox/chain";
export { SystemRegistry } from "@health-samurai/interbox";
export const LookupRegistry = { providers };
LookupRegistry is optional. It is a plain object of your own whose values
are the handles defineLookup returned, and anything else in it fails the load.
A workspace whose entry does not export ChainRegistry fails to load. The
root's own pipeline and PipelineRegistry are the 1.x DSL. See
1.x API.
ChainRegistry holds every pipeline the workspace declares:
| member | what it does |
|---|---|
defs() | every declared pipeline as a PipelineDef, the serialisable shape the engine plans its workers from. Throws on a pipeline with no sender, and on a bridge whose two ends do not match |
handlers(name) | the functions of one pipeline: its steps, in order, and its sender's run. A worker calls it after importing the bundle, because functions do not cross threads |
legacy() | { pipelines, mappers }: the names of the 1.x pipelines and mappers that the root pipeline() and defineMapper of the same SDK copy registered. The engine refuses to load a workspace for which either is not empty |
clear() | forgets every declaration, for tests |
interface PipelineDef {
readonly name: string;
readonly source: SourceDef | BridgeSourceDef;
readonly steps: readonly StepDef[];
readonly store: StoreDef;
readonly sender: SenderDef;
readonly webhooks: readonly WebhookDef[];
}
interface StepDef {
readonly name: string;
readonly position: number;
readonly side: "before" | "after";
}
SDK_VERSION
const SDK_VERSION: string; // sourced from this package's own package.json
The version an engine runs is shown on the dashboard's Instances page.
ChainRegistry carries this version as ChainRegistry.SDK_VERSION, and the
engine compares it with its own on every load: see
Keep the workspace SDK compatible.
A workspace written for 1.x fails to load because it registers pipelines or
mappers with the 1.x DSL.
Env
See Env and config.
function env(name: string, fallback?: string): EnvRef;
function isEnvRef(value: unknown): value is EnvRef;
interface EnvRef {
readonly $env: string;
readonly $default?: string;
}
type Str = string | EnvRef;
type Num = number | EnvRef;
Errors
See Errors.
function domainError(group: ErrorGroup, kind: string, message: string): Error;
const ERROR_GROUPS: readonly [
"parse",
"structure",
"field",
"type",
"code",
"unsupported",
"source",
"mapper",
"system",
"sender",
"internal",
];
type ErrorGroup = (typeof ERROR_GROUPS)[number];
Systems
See Systems. defineSystem declares an external API a step calls, and SystemRegistry is
what the workspace exports so the engine can bind it.
provenanceId
See Step context.
function provenanceId(unit: { readonly id: bigint; readonly createdAt: Date }): string;
A Provenance id derived from a unit, ib-<unit id>-<created time in base-36 milliseconds>. A Retry of the unit gives the same id.
1.x exports
The root still exports the 1.x pipeline DSL, and /builtins the 1.x stage descriptors. The 2.x engine runs none of them. They are documented in 1.x API.
A 2.0 pipeline's source is MLLP (mllpSource),
HTTP (webhookSource), files from storage (fileDropSource from /files, see
Reading files from storage), another pipeline
(fromPipeline) or a source you define
with the defineSource of @health-samurai/interbox/chain, which takes the
same shape as the 1.x one with receive in place of writeBatch, and ends a
push source when its run returns (see
Writing your own source).
Logging
Workspace code logs with console: a 2.0 pipeline's steps and sender, and a
1.x source, mapper or sender alike. There is no logger to import and none on a
stage's context. Each stage runs in its own worker thread, and the engine
captures that thread's console.log, info,
warn, error, debug and trace as JSON log lines in the same stream as
the engine's own:
| call | level |
|---|---|
console.log, console.info | info (30) |
console.warn | warn (40) |
console.error | error (50) |
console.debug, console.trace | debug (20) |
At the default level, info, debug lines are not written. The engine's
LOG_LEVEL environment variable lowers it. console.trace writes no stack.
Every line carries the identity of the stage that wrote it:
| stage | fields |
|---|---|
| 2.0 source, which runs the steps before the store | stage: "chain-source", pipeline (its name), instance (the engine's INTERBOX_INSTANCE_ID, or its host name) |
| 2.0 segment, which runs the steps after the store | stage: "chain-segment", pipeline, instance |
| 2.0 sender | stage: "chain-sender", pipeline, instance |
| 2.0 webhook dispatcher | stage: "chain-webhook-dispatcher" |
| 1.x source | stage: "source", source (its id), type (its source type) |
| 1.x mapper | stage: "mapper", mapper (its type) |
| 1.x sender | stage: "sender", sender (its type) |
A field of yours with one of those names is dropped and the stage's own value stands, so a line cannot claim to come from another stage.
The arguments become the line like this:
- The message is formatted the way
console.logformats it, soconsole.log("read %d files from %s", count, dir)works. - A trailing plain object becomes the line's fields and is left out of the
message. Put it last: an object anywhere else is formatted into the message,
and so is a trailing array,
null, or a class instance such as aDate. - An
Errorbecomes theerrfield (its type, message and stack) and is left out of the message. AnErrorthat a%sin the format string consumes is formatted into the message instead. Only the first remainingErroris taken, and a second one is formatted into the message.console.error(err)on its own uses the error's message as the line's message. - A field of yours named
level,time,msg,pid,tid,hostnameorvis moved under aconsoleobject, so it cannot change the line's own level, time or message.
console.warn("delivery deferred", { key: "a.hl7", attempt: 2 });
console.error("cycle failed", new Error("connection reset"));
{"level":40,"time":1790573959774,"pid":71776,"tid":1,"stage":"source","source":"lab-drop-1","type":"lab-drop","key":"a.hl7","attempt":2,"msg":"delivery deferred"}
{"level":50,"time":1790573959774,"pid":71776,"tid":1,"stage":"source","source":"lab-drop-1","type":"lab-drop","err":{"type":"Error","message":"connection reset","stack":"Error: connection reset\n at …"},"msg":"cycle failed"}
Code the engine runs while it loads the workspace, outside any stage, is not captured. That covers a
source's prepareConfig and describeConfig. Its console
output is written as plain text, without a stage's identity.