Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/admin-crm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@freeticket/cli": minor
---

New `ft admin crm` commands for the master CRM (admin contract 1.7.0): list and inspect campaigns, search shows and dates, read options and the WhatsApp quota, preview an audience, launch a campaign (`--ignore-window` to send WhatsApp now outside 9:00-20:00), send or stop WhatsApp batches and cancel a scheduled campaign. Every write previews its target and asks for confirmation (`--yes` in scripts), none is retried automatically, and `PAYLOAD_TOO_LARGE` (413) is explained.
5 changes: 5 additions & 0 deletions .changeset/admin-service-token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@freeticket/cli": minor
---

`ft admin` authenticates with a platform service token: set `FT_ADMIN_TOKEN` and it is sent as `Authorization: Bearer`, ahead of the session cookie.
5 changes: 5 additions & 0 deletions .changeset/contract-1-55-admin-1-9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@freeticket/cli": minor
---

Contract sync to v1 1.55.0 and admin 1.9.0. New `ft admin settlements` (list, get, upload, create, regenerate, attach, send, mark-paid, delete) for organizer settlements across workspaces; every write shows the settlement, asks for confirmation (`--yes` in scripts) and sends `confirm: true`. New `ft admin crm test-send`, `suppressions list|add|remove`, `organizations` and `people search`. New `ft courtesy-requests create` for enterprise landings, and `ft settlements list --kind EVENT|MEMBERSHIP` with a `kind` column. Fixes `ft admin users list --workspace` and `ft admin audit-log list --actor`, which were silently ignored.
162 changes: 161 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,18 @@ ft sales list --status CONFIRMED --json
| `ft reports by-event` · `timeseries` · `inventory` | Revenue/tickets by event, over time, and capacity/availability | VIEWER |
| `ft reports export buyers\|attendees\|subscribers\|reconciliation` | Exports as CSV (filters `--event` `--event-date` `--from` `--to` `--status`) | ADMIN |
| `ft reports reconciliation` · `financials` | CFO reconciliation (Mercado Pago vs sale vs Siigo invoice) · per-function P&L | ADMIN |
| `ft settlements list` · `get <id>` · `document <id>` | Settlements paid to the organizer · signed download URL for the PDF, 5 min TTL (`--proof <fileName>` for a payment proof) | ADMIN |
| `ft settlements list` · `get <id>` · `document <id>` | Settlements paid to the organizer (`--kind EVENT\|MEMBERSHIP`, `--event`, `--status`; membership rows carry `period` / `membershipPlan`) · signed download URL for the PDF, 5 min TTL (`--proof <fileName>` for a payment proof) | ADMIN |
| `ft content-videos list` · `content-posts list\|create` · `content-lives list\|get\|playback-token` | Organization content; `content-posts create --data` publishes a post or article | ADMIN |
| `ft waitlist list [--city <name>]` · `waitlist create --data` | Per-city waitlist of an enterprise landing (export with personal data); `create` needs an enterprise service key | ADMIN |
| `ft courtesy-requests create --data '{"fullName":"…","email":"…","companion":{"fullName":"…"}}'` | Courtesy invitation request from an enterprise landing (enterprise service key; one per email, a resubmit is 409). The list lives in the dashboard (`/dashboard/cortesias`) | service key |
| `ft merch products list` | Merch store products of the workspace's organization, DRAFT and PUBLISHED, with variants (Legend plan) | ADMIN / MERCH_MANAGER |
| `ft merch products create` | Create product(s) as DRAFT: `--name` `--price <cop>` `--sizes XS,S,M` `--stock <n>` `--image <path>` (repeatable, uploaded through a signed URL) `--publish`; `--from-json <file>` for several (image paths relative to the file, no symlinks). The whole batch is validated first; `--json` prints `{ created, failed }` | ADMIN / MERCH_MANAGER |
| `ft merch products images <id> --image <path>…` | Replace a product's photos with local files (repairs a partial `create`) | ADMIN / MERCH_MANAGER |
| `ft merch products publish <id>` · `unpublish <id>` | Show / hide a product in the store (publishing needs the store setup done and an active variant) | ADMIN / MERCH_MANAGER |
| `ft api-keys create <name>` · `list` · `revoke <id>` | Self-service API keys (the secret is shown once, never stored) | ADMIN |
| `ft admin login` · `me` · `workspaces` · `users` · `plans` · `feature-flags` · `tokens` · `audit-log` | Superadmin, cross-tenant — needs a SUPER_ADMIN session, not an API key. Includes `admin workspaces plan <id>` (assisted plan assignment), `plan-show <id>` (current plan) and `delete <id>` (soft delete; suspend first) and `webTemplate` / `customDomain` on `update` | SUPER_ADMIN |
| `ft admin settlements list` · `get` · `upload` · `create` · `regenerate` · `attach` · `send` · `mark-paid` · `delete` | Organizer settlements across workspaces: create, send, mark as paid. See [`ft admin settlements`](#ft-admin-settlements) | SUPER_ADMIN |
| `ft admin crm campaigns` · `batches` · `events` · `options` · `quota` · `preview` · `launch` · `test-send` · `suppressions` · `organizations` · `people search` | Master CRM: email / WhatsApp campaigns to buyers across workspaces. See [`ft admin crm`](#ft-admin-crm) | SUPER_ADMIN |

> **Write operations** (`create`/`update`/`delete` and actions like `publish`,
> `cancel`, `refund`) send a JSON body via `--data <inline-json>` or
Expand All @@ -147,6 +150,161 @@ ft sales list --status CONFIRMED --json
| `--csv` | list commands | CSV output for spreadsheets/accounting |
| `--data <json>` `--yes` | write commands | JSON body (inline or `@file`) · skip delete confirmation |

## `ft admin crm`

The master CRM for the internal team: email and WhatsApp campaigns to buyers,
across every workspace, against `/api/admin/crm`. It needs a SUPER_ADMIN
credential — `FT_ADMIN_TOKEN` (a service token from `ft admin tokens create`)
or `ft admin login --session`.

```bash
ft admin crm campaigns list [--channel EMAIL|WHATSAPP] [--status S] [--limit N]
ft admin crm campaigns get <id>
ft admin crm campaigns cancel <id> [--yes]
ft admin crm batches next <id> [--ignore-window] [--yes]
ft admin crm batches stop <id> [--yes]
ft admin crm events search <query> [--purpose scope|promote|except] [--sender <workspaceId>]
ft admin crm events dates <eventId...>
ft admin crm options
ft admin crm quota
ft admin crm preview --filter @filter.json [--sender freeticket|<workspaceId>]
ft admin crm launch --data @campaign.json [--ignore-window] [--yes]
ft admin crm test-send --data @message.json [--sender freeticket|<workspaceId>] [--yes]
ft admin crm suppressions list [--query <email part>] [--scope global|all] [--limit 1-500]
ft admin crm suppressions add <email>
ft admin crm suppressions remove <email> [--yes]
ft admin crm organizations [query]
ft admin crm people search <query> [--scope '{"level":"orgs","workspaceIds":["…"]}']
```

`test-send` sends the composed message, with subject `[Prueba]`, to **you**:
your email, or by WhatsApp the phone on your staff profile (it uses 1 of the
daily WhatsApp quota). It takes the same fields as `launch` minus the filter
and timing, asks first and sends `confirm: true`. `suppressions add` stops a
person from getting master CRM campaigns (idempotent; it does not touch an
organizer's own campaigns); `suppressions remove` re-enables them, asks first,
and only works on unsubscribes the team added (`reason: admin`). `people
search` returns the full email (what the filter's `people` condition takes);
`organizations` gives ids for `scope.level: "orgs"` or `sender.workspaceId`.

**Writes send real messages.** `launch`, `campaigns cancel`, `batches next` and
`batches stop` first show what they are about to touch — `launch` runs the
audience preview with the same filter and sender (total, how many have email
or reachable WhatsApp, the estimated days at the daily quota); the others show
the campaign — and then ask for confirmation. Without a TTY they refuse unless
you pass `--yes`. The CLI never retries a write on its own: if a `launch`
times out, check `campaigns list` before launching again (the backend rejects
the same channel + sender + subject within 10 minutes with
`DUPLICATE_CAMPAIGN` and prints the existing id).

Named errors get a next step: `OUTSIDE_SEND_WINDOW` (WhatsApp sends only
9:00-20:00 Bogotá) prints when the window opens and suggests `--ignore-window` (on `batches next`, and on a
`launch` by WhatsApp with `timing.mode` `now`);
`QUOTA_EXHAUSTED` prints when the quota frees up; `INVALID_STATE` means the
campaign no longer allows that action; a 422 lists each `details[].path`; a 413 `PAYLOAD_TOO_LARGE` means the body is over
256 KB.

Find the ids for a filter with `events search` and `events dates`, and the
cities, genre/format codes, plans and WhatsApp templates with `options`.

### `filter.json` (audience filter v2)

```json
{
"version": 2,
"scope": { "level": "platform" },
"include": [
{ "type": "purchased", "eventIds": ["evt_123"], "window": { "kind": "last_days", "days": 90 } }
],
"except": [
{ "type": "received_campaign", "days": 7, "channel": "any" }
]
}
```

- `scope` (default `platform`): `{ "level": "orgs", "workspaceIds": [...] }` or
`{ "level": "events", "eventIds": [...] }`.
- `include` conditions combine with AND; `except` with OR, evaluated across the
whole platform. Up to 12 per block, 50 ids per list.
- Condition types: `purchased`, `abandoned`, `checked_in` (with optional
`eventIds`, `dateIds` + `dateEventIds`, `window`), `city` (`cities`),
`facet` (`dimension`: `genre` | `format`, `codes`), `membership` (`state`:
`active` | `expiring` | `cancelled`, `withinDays` for `expiring`, `planIds`),
`spend` (`minCop`, `maxCop`), `received_campaign` (`except` only: `days`,
`channel`), `people` (`include` only: `emails`).
- `window`: `{ "kind": "any" }` (default), `{ "kind": "last_days", "days": 7|30|90 }`
or `{ "kind": "range", "from": "2026-09-01", "to": "2026-09-30" }` (Bogotá dates).
- Without a state condition (`purchased`, `abandoned`, `checked_in`,
`membership`, `people`) in `include`, the audience defaults to confirmed
buyers plus active members.

### `campaign.json`

```json
{
"channel": "WHATSAPP",
"sender": { "kind": "freeticket" },
"templateName": "promo_show",
"subject": "New date in Medellín",
"body": "We just opened a second show. Get your tickets before they are gone.",
"promotedEventId": "evt_123",
"filter": {
"version": 2,
"include": [{ "type": "purchased", "eventIds": ["evt_123"] }],
"except": []
},
"timing": { "mode": "batches", "firstAt": "2026-11-03T10:00:00-05:00", "batchSize": 50, "perDay": 3, "intervalMinutes": 120 }
}
```

- `sender`: `{ "kind": "freeticket" }` or `{ "kind": "organization", "workspaceId": "..." }`.
FreeTicket is mandatory when the scope spans the platform, several
organizations or events of more than one owner (`preview` tells you).
- WhatsApp needs an approved `templateName` (see `options`); email rejects one.
`imageUrl` for WhatsApp must come from the media library.
- `ignoreSendWindow` (or `--ignore-window`): WhatsApp with `timing.mode` `now`
only; sends even outside 9:00-20:00 Bogotá instead of failing with
`OUTSIDE_SEND_WINDOW`.
- `timing`: `{ "mode": "now" }` (sends on response), `{ "mode": "scheduled", "at": "<ISO with offset>" }`
or `batches` (WhatsApp only, daily cap 150 when FreeTicket signs, 200 for an
organization). WhatsApp times are moved into the 9:00-20:00 Bogotá window;
the response's `scheduledAt` is the real one.

## `ft admin settlements`

Settlements of every organization for the internal team, against
`/api/admin/settlements` (admin contract 1.9). Same SUPER_ADMIN credential as
`ft admin crm`. `list` shows EVENT settlements only, like the panel.

```bash
ft admin settlements list [--status S] [--organization <id>] [--all]
ft admin settlements get <id>
ft admin settlements upload <file.pdf> --organization <id> # prints storagePath
ft admin settlements create --data '{"mode":"auto","eventDateId":"…"}' [--yes]
ft admin settlements create --data @manual.json --pdf liquidacion.pdf [--yes]
ft admin settlements regenerate <id> [--commission-rate 2.9916] [--fixed-fee 500] [--yes]
ft admin settlements attach <id> --pdf <file> [--amount N] [--yes] # legacy DRAFT → GENERATED
ft admin settlements send <id> [--yes] # GENERATED → SENT, emails the organizer
ft admin settlements mark-paid <id> --proof a.pdf --proof b.pdf [--yes] # AWAITING_PAYMENT → PAID
ft admin settlements delete <id> [--yes]
```

`get` and `list` cover event settlements only; a membership settlement id
returns 404 there. The organizer email on `send` and `mark-paid` is
best-effort: a 200 means the state changed, not that the email arrived, and a
retry returns 409 `INVALID_STATE` instead of resending.

**Every write moves money or notifies the organizer.** Each one shows the
settlement (or the body it will create) and asks; without a TTY it refuses
unless you pass `--yes`. `send`, `mark-paid` and `delete` send the contract's
`confirm: true` (`attach` only with `--amount`). PDFs (max 3 MB, checked for
`%PDF` locally) go up with `POST /settlements/files` after you confirm;
`--pdf` / `--proof` do that for you, or pass an already uploaded `storagePath`
(`attach --storage-path`, `mark-paid --proofs '[{"storagePath":…,"fileName":…}]'`).
`create` starts in GENERATED and does not notify anyone; a function with an
active settlement answers `DUPLICATE_SETTLEMENT` with the existing id. Nothing
is retried automatically.

## Configuration

`ft` resolves configuration in this precedence order:
Expand All @@ -160,6 +318,8 @@ flags > environment variables > ~/.freeticket/config.json > defaults
| `FT_API_URL` | `https://admin.appfreeticket.com` | API base URL (without `/api/v1`) |
| `FT_API_KEY` | — | CI/headless only — a backend-issued `ft_live_...` token. Browser login (`ft login`) needs no key. When set it is the **only** account: stored logins are ignored, nothing fans out across them, and `--account` is rejected. A workspace pinned with `ft workspace use` still applies |
| `FT_WORKSPACE_ID` | *home* | Default active workspace |
| `FT_ADMIN_TOKEN` | — | `ft admin` only — a platform service token (`ft admin tokens create`), sent as `Authorization: Bearer`. Takes precedence over the session cookie |
| `FT_ADMIN_SESSION` | — | `ft admin` only — a SUPER_ADMIN `better-auth.session_token` cookie (same as `ft admin login --session`) |
| `FT_NO_UPDATE_CHECK` | — | Set to disable the "update available" notice (checked at most once a day; also off in CI, without a TTY, and with `--json`/`--raw`/`--csv`) |

Logins are stored per account under `accounts` in `~/.freeticket/config.json`
Expand Down
Loading
Loading