https://github.com/usebarekey/sdk
Typescript SDK for Barekey
https://github.com/usebarekey/sdk
Last synced: 10 days ago
JSON representation
Typescript SDK for Barekey
- Host: GitHub
- URL: https://github.com/usebarekey/sdk
- Owner: usebarekey
- License: bsd-3-clause
- Created: 2026-03-05T13:15:54.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2026-03-23T21:01:26.000Z (3 months ago)
- Last Synced: 2026-03-25T19:36:36.778Z (3 months ago)
- Language: TypeScript
- Homepage: https://npmx.dev/package/@barekey/sdk
- Size: 233 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @barekey/sdk
TypeScript SDK for Barekey.
## Install
```bash
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`:
```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:
```bash
barekey login
```
Use the SDK:
```ts
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:
```bash
barekey typegen
```
Watch mode:
```bash
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
```ts
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:
```ts
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
```bash
bun install
bun run build
bun run typecheck
bun test
```