# Saiops Key System

Node.js + SQLite key licensing API with admin and key lookup pages.

## Quick start

```powershell
npm install
# optional: create .env with ADMIN_SECRET, PORT, DB_FILE, ALLOWED_ORIGINS
npm start
```

Open:
- `http://localhost:3000/admin` for admin UI
- `http://localhost:3000/key` for key lookup UI

## Environment

- `ADMIN_SECRET` (required): Bearer token for admin routes
- `PORT` (optional): API port, default `3000`
- `DB_FILE` (optional): SQLite file path, default `data.sqlite`
- `ALLOWED_ORIGINS` (optional): Comma-separated list of allowed origins (defaults to `https://saiops.cc, https://key.saiops.cc`)

## API

- `POST /validate`
- `POST /ping`
- `GET /keyinfo?key=...`
- `POST /admin/services/create` (Bearer token)
- `GET /admin/services` (Bearer token)
- `POST /admin/providers/create` (Bearer token)
- `GET /admin/providers?service_id=...` (Bearer token)
- `POST /admin/generate` (Bearer token)
- `GET /admin/keys` (Bearer token)
- `GET /service/:slug`
- `POST /service/:slug/generate`

## Notes

- Keys are 36 characters with dashes (UUID-style) and start with a configurable prefix (default `SAIOPS`).
- Admin key generation accepts an optional `key_prefix` (up to 8 alphanumeric chars).
- Durations are stored and sent in minutes (`duration_minutes`).
- CORS is restricted to the configured `ALLOWED_ORIGINS` list.
- Admin UI stores the token in `localStorage`.
- When running locally, the UI targets the same origin to avoid cross-origin requests.
