# @mestra-dev/contract

Types-only package exporting the Mestra auth Hono `AppType` for frontend RPC clients.

Published artifact is **only** `dist/index.d.ts` — no runtime JavaScript.

## Install

```bash
bun add @mestra-dev/contract
bun add hono   # peer dependency
```

Or with npm:

```bash
npm install @mestra-dev/contract
npm install hono
```

## Frontend usage

```ts
import type { AppType } from '@mestra-dev/contract'
import { hc } from 'hono/client'

const client = hc<AppType>('https://api.mestra.chat/')

const res = await client.auth.me.$get()

if (res.ok) {
  const data = await res.json()
} else if (res.status === 401) {
  const err = await res.json() // { success: false, error: string }
} else if (res.status === 403) {
  const err = await res.json() // authorization failure, not a dead token
} else if (res.status === 404) {
  const err = await res.json()
}
```

`AppType` includes per-route error bodies (400/403/404/…) plus global middleware errors (JWT, workspace access, rate limit → 400/401/403/404/429/500).

Always use `import type` so the bundler never pulls server code.

## Build (maintainers)

Requires local `services/core` and `services/utils` sources plus core `node_modules` for type resolution. Those packages are **not** published with this contract.

```bash
cd services/hc
bun install
bun run build
```

Output: `dist/index.d.ts` (self-contained; depends on `hono` types only).

## Publish to npmjs

```bash
cd services/hc
bun run build
bun pm version patch   # or: minor / major
bun publish --access public
```

`prepublishOnly` runs `build` automatically before publish.

Shortcut:

```bash
bun run release
```
