Skip to content

usebarekey/sdk

Repository files navigation

@barekey/sdk

TypeScript SDK for Barekey.

Install

npm install @barekey/sdk

Entrypoints

  • @barekey/sdk: root export for BarekeyClient, PublicBarekeyClient, and shared types
  • @barekey/sdk/server: optional explicit server subpath
  • @barekey/sdk/public: optional explicit public-variable subpath

Server quickstart

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 login

Use 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();

Auth resolution

In centralized mode the server client uses:

  1. BAREKEY_ACCESS_TOKEN
  2. a stored CLI session from barekey login

Optional:

  • BAREKEY_API_URL overrides the API base URL

barekey.json

Supported keys:

  • $schema
  • organization or org
  • project
  • environment or stage
  • config.mode: "centralized" or "standalone"
  • config.typegen: "semantic" or "minimal"
  • config.disallow_ambigious_keys: boolean (defaults to true)

Typegen

Generate SDK types into the installed package:

barekey typegen

Watch mode:

barekey typegen --watch

semantic typegen keeps Barekey metadata in the generated Env<...> wrapper, including Kind, Visibility, and Rollout. minimal only emits the resolved value type.

Public client

import { PublicBarekeyClient } from "@barekey/sdk";

const publicBarekey = new PublicBarekeyClient({
  organization: "acme",
  project: "web",
  environment: "production",
});

const title = await publicBarekey.get("PUBLIC_TITLE");

Requirements schemas

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(),
  }),
});

Development

bun install
bun run build
bun run typecheck
bun test

About

Typescript SDK for Barekey

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors