Skip to content

@xtandard/kit/cli

@xtandard/kit/cli — building blocks for the products’ CLIs: env (empty counts as unset), parseArgs, buildAuthFromEnv and storageFromEnv (both reject unknown modes/drivers), describeStorage, startServer (Bun or the Node bridge), serve, pkgVersion and the isMainModule self-run guard.

import { … } from "@xtandard/kit/cli";
Name Summary
buildAuthFromEnv Build the auth + authorization providers from env:
describeStorage A log-safe description of where a role persists data, for the startup banner: file and SQLite paths are resolved to absolute paths; drivers with a connection string print only their name (never the URL, which may carry credentials).
driverEnvOf The driver env var of a role.
env Read an env var. An empty value counts as unset (|| semantics), so FOO= in a .env file falls back to the default instead of becoming "".
isMainModule The self-run guard (au 6761a34): true when the module is the program’s entry point (bun src/cli.ts, node dist/cli.mjs), false when it is imported — by the bin/ wrapper, a test or the standalone app — so run() executes exactly once.
isTruthy "1" or "true" (any case).
parseArgs Minimal argv parser:
pkgVersion The version of the package.json at relative to moduleUrl (default ../package.json, which is right for dist/cli.mjs and src/cli.ts), or "unknown".
resolveStorageConfig Resolve a role’s driver and settings from env. An unknown driver throws.
serve The serve command: read the common env (PORT, BASE_PATH, TITLE, LOGO_URL, READONLY), warn on AUTH_MODE=none, build the panel, print the banner and listen. The server owns the process: it never resolves, so the bin doesn’t exit (unless returnServer).
startServer Serve a fetch handler under whatever runtime the CLI runs on: Bun.serve under Bun, a node:http server over the shared Node bridge under Node (multi-value headers, every Set-Cookie, streamed responses). Resolves once listening.
storageFromEnv Build a role’s storage from env (au/en’s allow-list loader, generic over the product’s roles). Unknown drivers fail instead of silently using file.
storageRegistryFrom Build a StorageRegistry from entry-module loaders, with the kit’s env → options mapping. Products pass their own wrapped entries, so the CLI gets the product’s capability layers (webhooks’ claimDue) and persisted defaults (table names), which the kit’s defaultStorageRegistry cannot know. Drivers without a loader are not available.
Name Summary
AuthFromEnv What buildAuthFromEnv returns.
AuthFromEnvOptions Options for buildAuthFromEnv.
ParseArgsOptions Options for parseArgs.
ParsedArgs Parsed argv.
RunningServer A running server.
ServeOptions Options for serve.
ServeSettings The env-derived settings serve passes to buildPanel.
StartServerOptions Options for startServer.
StorageConfig The resolved settings a driver factory receives (connection strings are never logged). An optional field is undefined when neither its env var nor the role’s defaults set it (“no default given”). A field the role gives a default for is always set.
StorageFromEnvOptions Options for storageFromEnv.
StorageRole A storage role: STORAGE, QUEUE, SOURCE, RUNTIME, COUNTERS…
StorageRoleDefaults Per-role defaults. The persisted ones (table, db, collection, paths) are the product’s (ADR 0005).
Name Summary
Env An environment: process.env or a test double.
StorageEntryLoader A lazy loader of a storage entry module (the kit’s, or a product’s wrapper).
StorageEntryLoaders The loaders storageRegistryFrom accepts, by driver name. Each module must export the factory the driver uses: createMemoryStorage, createFileStorage, createSqliteStorage, createLibsqlStorage, createPostgresStorage, createMongoStorage, createRedisStorage / createRedisJSONStorage (redis, redis-json), createUnstorageStorage.
StorageFactory Builds a storage for a driver from the resolved config.
StorageRegistry Driver name → factory.
Name Summary
defaultStorageRegistry The default registry over the kit’s own storage entries: each driver lazily imports its entry, so an optional peer loads only when its driver is chosen. A product with capability layers or persisted defaults in its driver wrappers must pass its own registry instead (see storageRegistryFrom): this one bypasses them.