import { BarekeyClient } from "@barekey/sdk/server";export const barekey = new BarekeyClient();
Because barekey.json is present, the client can resolve:
organization
project
environment
And because you already logged in with the CLI, the SDK can reuse the local CLI session for auth during local development.Read your variable:
import { barekey } from "./barekey";const databaseUrl = await barekey.get("DATABASE_URL");console.log(databaseUrl);
If you want stronger startup guarantees, pass a schema directly:
import { z } from "zod";import { BarekeyClient } from "@barekey/sdk/server";const barekey = new BarekeyClient({ requirements: z.object({ DATABASE_URL: z.string().url(), }),});
await barekey.get("DATABASE_URL") returns the parsed value for the variable’s declared type.If you want metadata too, use inspect():
const result = await barekey.get("DATABASE_URL").inspect();console.log(result.value);console.log(result.rawValue);console.log(result.kind);console.log(result.visibility);
This updates generated types inside your installed @barekey/sdk package so known keys become typed in your editor.In development, you can keep it fresh: