TypeScript SDK for Barekey.
npm install @barekey/sdk@barekey/sdk: root export forBarekeyClient,PublicBarekeyClient, and shared types@barekey/sdk/server: optional explicit server subpath@barekey/sdk/public: optional explicit public-variable subpath
Create barekey.json:
{
"$schema": "./node_modules/@barekey/sdk/dist/barekey.schema.json",
"organization": "acme",
"project": "web",
"environment": "development",
"config": {
"mode": "centralized",
"typegen": "semantic",
"disallow_ambigious_keys": true
}
}Log in locally:
barekey loginUse the SDK:
import { BarekeyClient } from "@barekey/sdk";
const barekey = new BarekeyClient();
const databaseUrl = await barekey.get("DATABASE_URL");
const details = await barekey.get("DATABASE_URL").inspect();In centralized mode the server client uses:
BAREKEY_ACCESS_TOKEN- a stored CLI session from
barekey login
Optional:
BAREKEY_API_URLoverrides the API base URL
Supported keys:
$schemaorganizationororgprojectenvironmentorstageconfig.mode:"centralized"or"standalone"config.typegen:"semantic"or"minimal"config.disallow_ambigious_keys:boolean(defaults totrue)
Generate SDK types into the installed package:
barekey typegenWatch mode:
barekey typegen --watchsemantic typegen keeps Barekey metadata in the generated Env<...> wrapper, including Kind, Visibility, and Rollout. minimal only emits the resolved value type.
import { PublicBarekeyClient } from "@barekey/sdk";
const publicBarekey = new PublicBarekeyClient({
organization: "acme",
project: "web",
environment: "production",
});
const title = await publicBarekey.get("PUBLIC_TITLE");Pass a Standard Schema v1 validator directly:
import { z } from "zod";
import { BarekeyClient } from "@barekey/sdk";
const barekey = new BarekeyClient({
requirements: z.object({
DATABASE_URL: z.string().url(),
DEBUG_MODE: z.boolean(),
}),
});bun install
bun run build
bun run typecheck
bun test