Metadata-Version: 2.5
Name: bookai-cli
Version: 0.2.0
Summary: Command-line client for the bookai group-sales back office API
Requires-Python: >=3.9
Requires-Dist: click<9,>=8
Requires-Dist: httpx<1,>=0.27
Requires-Dist: keyring>=24
Requires-Dist: rich>=13
Provides-Extra: dev
Requires-Dist: pytest<9,>=8; extra == 'dev'
Requires-Dist: respx<1,>=0.21; extra == 'dev'
Description-Content-Type: text/markdown

# bookai-cli

Command-line client for the bookai group-sales back office API — manage venue
pricing and view confirmed orders from the terminal or a script, instead of
clicking through the admin web app.

This is a thin HTTP client: it talks only to the public, authenticated JSON
API and contains no business logic or backend code.

## Install

```bash
pip install bookai-cli
```

## Authenticate

```bash
bookai login
```

Opens your browser to authorize this machine, then saves the key locally
(your OS keychain, or a `0600` file under your user config dir if no keychain
is available) — no copy-pasting a raw key required. **The environment you
just logged into also becomes your default** for every later command that
doesn't explicitly pass `--env`/`--base-url` (see
[Environments](#environments) below) — run `bookai login` again any time to
re-authorize, switch accounts, or switch which environment is your default.

Check what's currently active any time with:

```bash
bookai whoami
```

For scripting/CI, skip `login` and use a key directly instead — mint one from
the back office's **API Keys** page and set it as an environment variable:

```bash
export GROUPSALES_API_KEY=gsk_...
```

`--api-key` (or `GROUPSALES_API_KEY`) always takes priority over a
`bookai login`-saved key when both are present.

`bookai logout` removes the locally saved key (add `--all` to clear every
environment at once). This only forgets the key on this machine — it stays
valid until you revoke it from the back office's API Keys page.

## Environments

This project runs three environments:

| `--env`   | Base URL                       |
|-----------|---------------------------------|
| `prod`    | `https://b2b.bookai.now`           |
| `sandbox` | `https://b2b-sandbox.bookai.now`   |
| `local`   | `http://localhost:8001`            |

**You don't need to pass `--env` on every command.** `bookai login` sets the
environment you just authorized as your default (saved to a small local
config file, separate from the key itself) — so once you've run `bookai
--env sandbox login`, every later `bookai venues list` / `bookai pricing ...`
targets sandbox automatically, with no flags needed. Run `bookai whoami` any
time to check which environment and key are currently active.

`--env <name>` (or `--base-url <url>`/`GROUPSALES_BASE_URL` for a fully
custom URL not in the table above) overrides your default **for that one
command only** — it doesn't change what `bookai login` set as your default.
`bookai login` saves a separate key per base URL, so logging into sandbox and
prod don't clobber each other; switching your default just means running
`bookai login` again against the other one.

Before your first `bookai login`, the default is `prod` if nothing else is
set.

Global options (`--api-key`, `--base-url`, `--env`, `--json`) go **before**
the subcommand: `bookai --json venues list`, not `bookai venues list --json`.

## Interactive shell

Run `bookai` with no command to get a prompt — commands run without the
leading `bookai`, and your environment/key from that shell's startup (or from
a `login`/`--env` typed mid-session) stays in effect line to line:

```
$ bookai
bookai interactive shell -- commands run without the leading `bookai` (e.g. `venues list`).
Type `help` for the command list, `whoami` for your current env/key, `exit` to quit.

bookai (sandbox)> venues list
...
bookai (sandbox)> exit
```

`exit`/`quit`/Ctrl-D leaves the shell. This is purely a convenience layer —
every line is dispatched through the exact same commands as one-shot usage,
so anything in [Usage](#usage) below works here too.

## Usage

```bash
bookai venues list
bookai venues create                            # guided prompts -- creates a brand-new venue + your account, no key needed yet

bookai contacts list <venue_id>
bookai contacts get <venue_id> <contact_id>
bookai contacts add <venue_id> --first-name Jamie --last-name Rivera --email jamie@example.com --role Owner
bookai contacts update <venue_id> <contact_id> --first-name Jamie --last-name Rivera --role "Events Manager"
bookai contacts delete <venue_id> <contact_id>

bookai pricing list <venue_id>
bookai pricing get <venue_id> <rule_id>
bookai pricing set <venue_id> --min-group 10 --max-group 50 --min-price 20 --max-price 30
bookai pricing set <venue_id> --min-group 10 --max-group 50 --min-price 20 --max-price 30 \
    --source acme-isv --external-id acme-rule-42   # tag a rule as synced from an external system
bookai pricing update <venue_id> <rule_id> --min-group 10 --max-group 50 --min-price 18 --max-price 28
bookai pricing delete <venue_id> <rule_id>

bookai orders list
bookai orders list --page 2
```

`bookai venues create` is the one command that works with no API key at all —
it's how a brand-new venue's very first account gets created in the first
place (same as signing up in the browser). It asks for the venue's details
and your own name/email/password one at a time, confirms before submitting,
then tells you to run `bookai login` next.

Add `--json` anywhere for machine-readable output instead of a table — useful
for piping into `jq` or scripting in CI.

## Development

```bash
pip install -e ".[dev]"
pytest
```

Tests are fully offline (HTTP is mocked via `respx`) — no server or database
required.
