Typed keys with the CLI
The @fabric-messaging/cli reads your released message definitions
and generates a typed catalog. Type the SDK client with it and every messages.send / preview call
autocompletes keys and checks the data shape at compile time.
-
Point the CLI at your environment
.env FABRIC_API_KEY=sk_test_replace_with_your_keyThe CLI reads
FABRIC_API_KEYand infers the environment from its prefix, exactly like the SDK. -
Generate the catalog
Terminal window npx @fabric-messaging/cli definitions generate --output fabric.generated.tsThis writes a
FabricCatalogtype describing every released key and its variables. -
Type the client
import { Fabric } from "@fabric-messaging/sdk";import type { FabricCatalog } from "./fabric.generated";const fabric = new Fabric<FabricCatalog>({ apiKey: process.env.FABRIC_API_KEY! });// key is autocompleted; data is checked against the definition's variablesawait fabric.messages.send("order.shipped", {to: "+233201234567",data: { name: "Ama", ref: "GH-4821" },idempotencyKey: "order-shipped:GH-4821",}); -
Guard against drift in CI
Terminal window npx @fabric-messaging/cli definitions checkcheckregenerates in memory and compares against the committed file. It exits non-zero if the catalog has drifted from the released contract, so a definition change that outdates your types fails the build.
The CLI redacts key patterns from its own error output, but treat it like any secret-bearing tool: run it in a trusted shell or CI job, and never commit a key or a generated file containing secrets.