Skip to content

Commit 4be3c3d

Browse files
refactor(openapi-client): rename @bunny.net/api to @bunny.net/openapi-client (#63)
1 parent 6ba0a54 commit 4be3c3d

88 files changed

Lines changed: 177 additions & 163 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/fair-planets-wonder.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@bunny.net/openapi-client": patch
3+
"@bunny.net/app-config": patch
4+
"@bunny.net/cli": patch
5+
---
6+
7+
Internal: rename `@bunny.net/api` workspace package to `@bunny.net/openapi-client` for clarity. No user-facing CLI changes.

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- uses: actions/checkout@v5
1212
- uses: oven-sh/setup-bun@v2
1313
- run: bun install
14-
- run: bun run api:generate
14+
- run: bun run openapi:generate
1515
- run: bun run lint:ci
1616
- run: bun run typecheck
1717
- run: bun test

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dist
77
*.tgz
88

99
# generated API types
10-
packages/api/src/generated
10+
packages/openapi-client/src/generated
1111

1212
# code coverage
1313
coverage

AGENTS.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ Bun replaces the entire Node.js toolchain. There are no separate tools for trans
7272

7373
This is a Bun workspace monorepo with four packages:
7474

75-
- **`@bunny.net/api`** (`packages/api/`) — Standalone, type-safe API client SDK for bunny.net. Zero CLI dependencies. Publishable to npm.
75+
- **`@bunny.net/openapi-client`** (`packages/openapi-client/`) — Standalone, type-safe OpenAPI client for bunny.net, generated from OpenAPI specs. Zero CLI dependencies. Publishable to npm.
7676
- **`@bunny.net/app-config`** (`packages/app-config/`) — Shared app configuration schemas (Zod), inferred types, JSON Schema generation, and API conversion functions. Used by the CLI and potentially other tools.
7777
- **`@bunny.net/database-shell`** (`packages/database-shell/`) — Standalone interactive SQL shell for libSQL databases. Framework-agnostic REPL, dot-commands, formatting, masking, and history. Also usable as a standalone CLI (binary: `bsql`).
78-
- **`@bunny.net/cli`** (`packages/cli/`) — The CLI. Depends on `@bunny.net/api`, `@bunny.net/app-config`, and `@bunny.net/database-shell`.
78+
- **`@bunny.net/cli`** (`packages/cli/`) — The CLI. Depends on `@bunny.net/openapi-client`, `@bunny.net/app-config`, and `@bunny.net/database-shell`.
7979

8080
```
8181
bunny-cli/
8282
├── packages/
83-
│ ├── api/ # @bunny.net/api package
83+
│ ├── openapi-client/ # @bunny.net/openapi-client package
8484
│ │ ├── package.json
8585
│ │ ├── tsconfig.json
8686
│ │ ├── redocly.yaml # Multi-spec config for openapi-typescript
@@ -144,7 +144,7 @@ bunny-cli/
144144
│ │ ├── client-options.ts # clientOptions() helper — builds ClientOptions from ResolvedConfig
145145
│ │ ├── define-command.ts # Command factory (see "Command Pattern" below)
146146
│ │ ├── define-namespace.ts # Namespace/group factory for subcommand trees
147-
│ │ ├── errors.ts # Re-exports UserError/ApiError from @bunny.net/api + ConfigError
147+
│ │ ├── errors.ts # Re-exports UserError/ApiError from @bunny.net/openapi-client + ConfigError
148148
│ │ ├── format.ts # Shared table/key-value rendering (text, table, csv, markdown)
149149
│ │ ├── format.test.ts # Tests for format utilities
150150
│ │ ├── logger.ts # Chalk-based structured logger
@@ -266,7 +266,7 @@ bunny-cli/
266266

267267
### Conventions
268268

269-
- **Monorepo with Bun workspaces.** `packages/api/` is the standalone API client SDK; `packages/app-config/` provides shared Zod schemas, types, and API conversion functions for `bunny.jsonc`; `packages/database-shell/` is the standalone SQL shell engine; `packages/cli/` is the CLI.
269+
- **Monorepo with Bun workspaces.** `packages/openapi-client/` is the standalone API client SDK; `packages/app-config/` provides shared Zod schemas, types, and API conversion functions for `bunny.jsonc`; `packages/database-shell/` is the standalone SQL shell engine; `packages/cli/` is the CLI.
270270
- **API clients use `ClientOptions`** — an options object with `apiKey`, `baseUrl`, `verbose`, `userAgent`, and `onDebug`. The CLI provides a `clientOptions(config, verbose)` helper to build this from `ResolvedConfig`.
271271
- **One command per file.** Each file in `commands/` exports a single command or namespace.
272272
- **Commands are grouped by domain** in subdirectories (`config/`, `db/`, `scripts/`).
@@ -275,8 +275,8 @@ bunny-cli/
275275
- **Top-level commands** (`login`, `logout`, `whoami`) are registered directly in `cli.ts` without a namespace.
276276
- **Shared internal code lives in `packages/cli/src/core/`** — command factories, errors, logger, format utilities, UI helpers, and shared types. Keep this flat (no nested subdirectories).
277277
- **Config logic lives in `packages/cli/src/config/`** — schema, file resolution, and profile management.
278-
- **Error classes are split.** `UserError` and `ApiError` live in `@bunny.net/api` (the SDK needs them). `ConfigError` lives in the CLI and extends `UserError`. The CLI's `errors.ts` re-exports `UserError` and `ApiError` from `@bunny.net/api`.
279-
- **Import API clients from `@bunny.net/api`**, not relative paths. Import generated types from `@bunny.net/api/generated/<spec>.d.ts`.
278+
- **Error classes are split.** `UserError` and `ApiError` live in `@bunny.net/openapi-client` (the SDK needs them). `ConfigError` lives in the CLI and extends `UserError`. The CLI's `errors.ts` re-exports `UserError` and `ApiError` from `@bunny.net/openapi-client`.
279+
- **Import API clients from `@bunny.net/openapi-client`**, not relative paths. Import generated types from `@bunny.net/openapi-client/generated/<spec>.d.ts`.
280280

281281
---
282282

@@ -508,7 +508,7 @@ Creates an `ora` spinner. Automatically silenced in non-TTY environments (`isSil
508508

509509
### API error normalization
510510

511-
The Bunny APIs use two different error response formats. The shared `authMiddleware()` in `packages/api/src/middleware.ts` normalizes both into `ApiError` via an `onResponse` handler, so command code never deals with raw HTTP errors.
511+
The Bunny APIs use two different error response formats. The shared `authMiddleware()` in `packages/openapi-client/src/middleware.ts` normalizes both into `ApiError` via an `onResponse` handler, so command code never deals with raw HTTP errors.
512512

513513
| API | Error schema | Fields |
514514
| ---------------- | ------------------------- | ----------------------------------------------------------------------------------- |
@@ -803,7 +803,7 @@ API calls use `openapi-fetch` with types generated from OpenAPI specs by `openap
803803
| Database | `createDbClient()` | `https://api.bunny.net/database` | Account `AccessKey` |
804804
| Magic Containers | `createMcClient()` | `https://api.bunny.net/mc` | Account `AccessKey` |
805805

806-
All clients accept a `ClientOptions` object and inject `AccessKey` and `User-Agent` headers via shared `authMiddleware()` in `packages/api/src/middleware.ts`.
806+
All clients accept a `ClientOptions` object and inject `AccessKey` and `User-Agent` headers via shared `authMiddleware()` in `packages/openapi-client/src/middleware.ts`.
807807

808808
### ClientOptions
809809

@@ -823,7 +823,7 @@ The CLI provides a `clientOptions()` helper (`packages/cli/src/core/client-optio
823823

824824
### Undocumented endpoints (`CustomPaths`)
825825

826-
Some Bunny API endpoints are not included in the public OpenAPI specs. These are typed manually via a `CustomPaths` type in `packages/api/src/core-client.ts`, which is intersected with the generated `paths`:
826+
Some Bunny API endpoints are not included in the public OpenAPI specs. These are typed manually via a `CustomPaths` type in `packages/openapi-client/src/core-client.ts`, which is intersected with the generated `paths`:
827827

828828
```typescript
829829
const client = createClient<paths & CustomPaths>({ baseUrl });
@@ -847,29 +847,29 @@ Only fall back to `string`, `any`, or `number` when no generated type exists (e.
847847

848848
### OpenAPI specs
849849

850-
Specs are committed as JSON files in `packages/api/specs/`. Generated types go to `packages/api/src/generated/` (gitignored). The `redocly.yaml` config and `openapi-typescript` devDependency live in the `@bunny.net/api` package.
850+
Specs are committed as JSON files in `packages/openapi-client/specs/`. Generated types go to `packages/openapi-client/src/generated/` (gitignored). The `redocly.yaml` config and `openapi-typescript` devDependency live in the `@bunny.net/openapi-client` package.
851851

852852
| Spec file | Source URL |
853853
| ------------------------------------------ | ------------------------------------------------------------- |
854-
| `packages/api/specs/core.json` | `https://core-api-public-docs.b-cdn.net/docs/v3/public.json` |
855-
| `packages/api/specs/compute.json` | `https://core-api-public-docs.b-cdn.net/docs/v3/compute.json` |
856-
| `packages/api/specs/database.json` | `https://api.bunny.net/database/docs/private/api.json` |
857-
| `packages/api/specs/magic-containers.json` | `https://api-mc.opsbunny.net/docs/public/swagger.json` |
854+
| `packages/openapi-client/specs/core.json` | `https://core-api-public-docs.b-cdn.net/docs/v3/public.json` |
855+
| `packages/openapi-client/specs/compute.json` | `https://core-api-public-docs.b-cdn.net/docs/v3/compute.json` |
856+
| `packages/openapi-client/specs/database.json` | `https://api.bunny.net/database/docs/private/api.json` |
857+
| `packages/openapi-client/specs/magic-containers.json` | `https://api-mc.opsbunny.net/docs/public/swagger.json` |
858858

859859
To regenerate types after updating specs:
860860

861861
```bash
862-
bun run api:generate # from root (delegates to @bunny.net/api)
862+
bun run openapi:generate # from root (delegates to @bunny.net/openapi-client)
863863
# or
864-
cd packages/api && bun run generate
864+
cd packages/openapi-client && bun run generate
865865
```
866866

867-
This reads `packages/api/redocly.yaml` and outputs `.d.ts` files to `packages/api/src/generated/`.
867+
This reads `packages/openapi-client/redocly.yaml` and outputs `.d.ts` files to `packages/openapi-client/src/generated/`.
868868

869869
### Usage in commands
870870

871871
```typescript
872-
import { createCoreClient } from "@bunny.net/api";
872+
import { createCoreClient } from "@bunny.net/openapi-client";
873873
import { resolveConfig } from "../../config/index.ts";
874874
import { clientOptions } from "../../core/client-options.ts";
875875

@@ -885,10 +885,10 @@ handler: async ({ profile, apiKey, verbose }) => {
885885

886886
### Adding a new API
887887

888-
1. Add the spec JSON to `packages/api/specs/`.
889-
2. Add an entry to `packages/api/redocly.yaml`.
890-
3. Run `bun run api:generate`.
891-
4. Create a client factory in `packages/api/src/` following the existing pattern and export it from `packages/api/src/index.ts`.
888+
1. Add the spec JSON to `packages/openapi-client/specs/`.
889+
2. Add an entry to `packages/openapi-client/redocly.yaml`.
890+
3. Run `bun run openapi:generate`.
891+
4. Create a client factory in `packages/openapi-client/src/` following the existing pattern and export it from `packages/openapi-client/src/index.ts`.
892892

893893
---
894894

CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test("example", () => {
2828

2929
This is a Bun workspace monorepo with four packages:
3030

31-
- `packages/api/` (`@bunny.net/api`) — standalone API client SDK, zero CLI deps
31+
- `packages/openapi-client/` (`@bunny.net/openapi-client`) — standalone, type-safe OpenAPI client, zero CLI deps
3232
- `packages/app-config/` (`@bunny.net/app-config`) — shared Zod schemas, types, and JSON Schema for `bunny.jsonc`
3333
- `packages/database-shell/` (`@bunny.net/database-shell`) — standalone SQL shell engine (REPL, formatting, masking)
3434
- `packages/cli/` (`@bunny.net/cli`) — the CLI, depends on all three
@@ -43,7 +43,7 @@ This is a Bun workspace monorepo with four packages:
4343
- Handle `--output json` first in every handler, then pass `output` to format functions.
4444
- Use `logger` from `packages/cli/src/core/logger.ts` for all user-facing output.
4545
- Throw `UserError` for expected errors.
46-
- Import API clients from `@bunny.net/api`, not relative paths. Import generated types from `@bunny.net/api/generated/<spec>.d.ts`.
46+
- Import API clients from `@bunny.net/openapi-client`, not relative paths. Import generated types from `@bunny.net/openapi-client/generated/<spec>.d.ts`.
4747
- Use `clientOptions(config, verbose)` from `packages/cli/src/core/client-options.ts` when creating API clients in command handlers.
4848
- Database commands use v2 API endpoints (`/v2/databases/...`).
4949
- Apps (Magic Containers) commands use `bunny.jsonc` as the single source of truth. App ID is stored in the config (no separate manifest file). Use `resolveAppId()` and `resolveContainerId()` from `packages/cli/src/commands/apps/config.ts`. Types and conversion functions come from `@bunny.net/app-config`.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Monorepo for the [bunny.net](https://bunny.net) CLI and supporting packages.
77
| Package | Name | Description |
88
| ------------------------------------------------------------------------ | ------------------------------------ | ------------------------------------------------------------ |
99
| [`packages/cli/`](packages/cli/) | `@bunny.net/cli` | Command-line interface for bunny.net |
10-
| [`packages/api/`](packages/api/) | `@bunny.net/api` | Standalone, type-safe API client SDK |
10+
| [`packages/openapi-client/`](packages/openapi-client/) | `@bunny.net/openapi-client` | Standalone, type-safe OpenAPI client for bunny.net |
1111
| [`packages/app-config/`](packages/app-config/) | `@bunny.net/app-config` | Shared Zod schemas, types, and JSON Schema for `bunny.jsonc` |
1212
| [`packages/database-shell/`](packages/database-shell/) | `@bunny.net/database-shell` | Standalone interactive SQL shell for libSQL databases |
1313
| [`packages/database-openapi/`](packages/database-openapi/) | `@bunny.net/database-openapi` | Generate OpenAPI 3.0 specs from a database schema |
@@ -57,10 +57,10 @@ bun test
5757
bun run build
5858

5959
# Update OpenAPI specs and regenerate types
60-
bun run api:update
60+
bun run openapi:update
6161

6262
# Regenerate types from existing specs
63-
bun run api:generate
63+
bun run openapi:generate
6464
```
6565

6666
### Changesets

0 commit comments

Comments
 (0)