# @hiyve/cli

Command-line tool for configuring npm to use the private Hiyve SDK registry.

## Quick Start

```bash
# One command to authenticate and configure npm
npx @hiyve/cli login
```

After login, install Hiyve packages normally:

```bash
npm install @hiyve/rtc-client
npm install @hiyve/react @hiyve/react-ui
```

## Commands

### `login`

Authenticate with Hiyve and configure npm for @hiyve packages.

```bash
# Interactive mode (prompts for API key)
npx @hiyve/cli login

# Non-interactive (CI/CD)
npx @hiyve/cli login --key sk_live_your_secret_key_here
```

### `logout`

Remove Hiyve configuration from your ~/.npmrc file.

```bash
npx @hiyve/cli logout
```

### `whoami`

Show current authentication status.

```bash
npx @hiyve/cli whoami
```

### `list`

List all available @hiyve packages.

```bash
npx @hiyve/cli list
```

### `init`

Scaffold a new Hiyve project from a template.

```bash
npx @hiyve/cli init my-app
npx @hiyve/cli init my-app --template ai
```

Templates: `basic`, `ai`, `full`

## Getting Your API Key

1. Log in to the [Hiyve Developer Console](https://api.hiyve.dev)
2. Navigate to **API Keys** in the sidebar
3. Copy your secret key (starts with `sk_test_` or `sk_live_`)

## What Does Login Do?

The `login` command:

1. Validates your API key with the Hiyve registry
2. Adds two lines to your `~/.npmrc` file:
   ```
   @hiyve:registry=https://api.hiyve.dev/registry/
   //api.hiyve.dev/registry/:_authToken=sk_live_...
   ```

This tells npm to fetch `@hiyve/*` packages from the private Hiyve registry instead of the public npm registry.

## CI/CD Setup

For automated deployments, add registry credentials as environment variables in your CI/CD pipeline. Your project `.npmrc` should use variable expansion:

```ini
@hiyve:registry=https://api.hiyve.dev/registry/
//api.hiyve.dev/registry/:_authToken=${HIYVE_API_KEY}
```

Set `HIYVE_API_KEY` in your CI environment (GitHub Actions secrets, AWS SSM, etc.). npm natively expands `${ENV_VAR}` in `.npmrc` files — no custom tooling needed.

## Troubleshooting

### "Invalid API key" error

- Make sure your key starts with `sk_test_` or `sk_live_`
- Verify your account is active in the developer console

### "Connection failed" error

- Check your internet connection
- The registry may be temporarily unavailable

### "401 Unauthorized" when running `npx @hiyve/cli login`

If you've previously logged in and your token has expired, `npx` may fail because npm routes all `@hiyve/*` packages (including the CLI) through the private registry. To fix this, remove the stale registry line from your `~/.npmrc` and re-run login:

```bash
# Remove the stale @hiyve registry config
npm config delete @hiyve:registry

# Now login will work again
npx @hiyve/cli login
```

### Packages not installing

After login, verify your configuration:

```bash
npx @hiyve/cli whoami
```

Or check your `~/.npmrc` manually:

```bash
cat ~/.npmrc | grep hiyve
```

## Security

- Your API key is stored in `~/.npmrc` (standard npm token storage)
- The key is sent only to the Hiyve registry during npm operations
- Run `npx @hiyve/cli logout` to remove your credentials

## Support

- Documentation: https://docs.hiyve.io
- Issues: https://github.com/hiyve/hiyve-sdk/issues
- Email: support@hiyve.io
