mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-24 16:06:34 +00:00
feat(cli): add hyperframes auth login --api-key, status, logout (#1081)
## What
Introduces the `hyperframes auth` command group + a shared credential
store library that hyperframes-CLI and heygen-cli will both read from.
- `hyperframes auth login --api-key` saves a HeyGen API key to
`~/.heygen/credentials.json` (stdin pipe or hidden-input prompt).
- `hyperframes auth status` resolves the active credential (env vars
→ file) and verifies it against `GET /v3/users/me`, printing
identity + billing.
- `hyperframes auth logout` removes the credential (`--keep-api-key`
drops only the OAuth block).
Internals (`packages/cli/src/auth/`):
- `paths.ts` — `~/.heygen` layout, `HEYGEN_CONFIG_DIR` override.
- `store.ts` — read/write `credentials.json` (file 0600, dir 0700)
with legacy single-line plaintext fallback so existing heygen-cli
users don't lose their session.
- `resolver.ts` — chain: `HEYGEN_API_KEY` → `HYPERFRAMES_API_KEY` →
file (unexpired OAuth wins over api_key).
- `client.ts` — hand-written typed wrapper for `GET /v3/users/me`
(intentionally not OpenAPI codegen — single endpoint).
- `errors.ts` — typed `AuthError` with discriminating `code`.
## Why
This is the foundation for `hyperframes cloud render`. Splitting it
out keeps the cloud-render PR small and lets users sign in today.
The plan originally called for a library-only PR followed by a
commands PR. The `fallow` dead-code gate flagged the library-only
shape as unused exports, so I bundled them — the library and its
first consumers ship together. PR 3 (OAuth PKCE) and PR 4
(heygen-cli read-side JSON support) follow.
## How
- Credential file format: JSON with optional `api_key` + `oauth`
blocks. Both CLIs read it; the resolver picks the freshest valid
credential.
- Auth header selection happens in the HTTP client: OAuth →
`Authorization: Bearer ...`, API key → `x-api-key: ...`.
- `HEYGEN_API_URL` lets dev testing target `api.dev.heygen.com`
without rebuilding.
- The new `auth` command lazy-loads its subverbs (same pattern as
`lambda`).
## Test plan
- [x] Unit tests added (`vitest`) for paths, store, resolver,
client, and errors — 45 tests, all green.
- [x] `bunx tsc --noEmit -p packages/cli/tsconfig.json` clean.
- [x] `bunx oxlint` + `bunx oxfmt --check` clean.
- [x] `bunx fallow audit --base origin/main --fail-on-issues` —
zero new findings.
- [ ] Smoke test against dev API:
`HEYGEN_API_URL=https://api.dev.heygen.com hyperframes auth login --api-key`
then `hyperframes auth status`.
This commit is contained in:
@@ -860,6 +860,63 @@ This is suppressed in CI environments, non-TTY shells, and when `HYPERFRAMES_NO_
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
## hyperframes auth
|
||||
|
||||
Sign in to HeyGen and manage credentials. Credentials are stored in
|
||||
`~/.heygen/credentials` (mode `0600`) and are **shared with the
|
||||
`heygen` CLI** — sign in with one and the other picks up the session.
|
||||
|
||||
Resolution order (first match wins):
|
||||
|
||||
1. `HEYGEN_API_KEY` environment variable
|
||||
2. `HYPERFRAMES_API_KEY` environment variable (hyperframes alias)
|
||||
3. `~/.heygen/credentials`
|
||||
|
||||
### Subcommands
|
||||
|
||||
#### `auth login --api-key`
|
||||
|
||||
Save a HeyGen API key. The key is verified against `GET /v3/users/me`
|
||||
before the command reports success; a rejected key is not left on disk.
|
||||
|
||||
```bash
|
||||
# Interactive hidden-input prompt
|
||||
hyperframes auth login --api-key
|
||||
|
||||
# Pipe a key from stdin (CI-friendly)
|
||||
echo "$HEYGEN_API_KEY" | hyperframes auth login --api-key
|
||||
```
|
||||
|
||||
#### `auth status`
|
||||
|
||||
Show the active credential's source, type, and verified identity
|
||||
(account + billing snapshot). Exits non-zero when nothing is configured
|
||||
or the API rejects the credential, so scripts can check sign-in state.
|
||||
|
||||
```bash
|
||||
hyperframes auth status
|
||||
hyperframes auth status --json # machine-readable
|
||||
```
|
||||
|
||||
#### `auth logout`
|
||||
|
||||
Remove the stored credential. Prompts for confirmation on a TTY.
|
||||
|
||||
```bash
|
||||
hyperframes auth logout
|
||||
hyperframes auth logout --keep-api-key # clear only an OAuth session
|
||||
hyperframes auth logout --yes # skip the confirmation prompt
|
||||
```
|
||||
|
||||
### Environment variables
|
||||
|
||||
| Variable | Description |
|
||||
|----------|-------------|
|
||||
| `HEYGEN_API_KEY` | Override the stored credential. |
|
||||
| `HYPERFRAMES_API_KEY` | Alias for `HEYGEN_API_KEY`. |
|
||||
| `HEYGEN_API_URL` | API base URL (default `https://api.heygen.com`). |
|
||||
| `HEYGEN_CONFIG_DIR` | Credentials directory (default `~/.heygen`). |
|
||||
|
||||
## hyperframes lambda
|
||||
|
||||
Deploy HyperFrames distributed rendering to AWS Lambda and drive renders from your laptop or CI.
|
||||
|
||||
Reference in New Issue
Block a user