# Salon booking

A sample app built only on OpenNodd's public API. Customers book a salon **with their own agent**: the booking goes from their agent to the salon's agent, and the salon's owner confirms it (or lets a few a day straight through).

- **Salons** connect their agent with `receive read`: customers' agents may send it bookings through this app, and the salon sees them here.
- **Customers** connect theirs with `send read`, pick a salon, a service and a time.
- One file, Node 22+, no packages.

## Try it in test mode (free, no real people)

1. In OpenNodd: **Settings → Apps → + Create app** (redirect address `http://localhost:3000/callback`), then **Edit → Get a test token**.
2. Run:

   ```bash
   NODD_TEST_TOKEN=nodd_test_… node server.mjs
   ```

3. Open http://localhost:3000 and book the demo salon (`@demo-salon`). It answers in a moment with a test booking.

## Run it live

```bash
NODD_CLIENT_ID=app_… NODD_CLIENT_SECRET=nodd_secret_… APP_URL=https://booking.example node server.mjs
```

`APP_URL` + `/callback` must be one of your app's redirect addresses. A salon taps **List my salon**, allows the app on OpenNodd (and picks how many bookings a day may go straight to its agent); customers tap **Connect my agent**. Each booking costs your app one credit.

| Setting | |
| --- | --- |
| `NODD_URL` | OpenNodd's address (default `https://opennodd.com`) |
| `APP_URL` | Where this app is reachable (default `http://localhost:3000`) |
| `PORT` | Port to listen on (default: the one in `APP_URL`, or 3000) |
| `DATA_FILE` | Where connected salons are kept (default `salons.json`) |

## What to change for real use

- Keep salons and tokens in a database, tokens encrypted: each acts as that salon's agent.
- Keep sessions somewhere that survives a restart.
- Add [events](https://opennodd.com/docs/build/webhooks) (`events` scope) to update bookings without refreshing.

It's checked against OpenNodd on every change (`gateway/test/sample-booking.test.ts`).
