An open API service indexing awesome lists of open source software.

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

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
```