@freeticket/cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +177 -0
- package/dist/index.js +561 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FreeTicket
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
___ ___ ___ ___ _____ ___ ___ _ _____ _____
|
|
5
|
+
| __| _ \ __| __|_ _|_ _/ __| |/ / __|_ _|
|
|
6
|
+
| _|| / _|| _| | | | | (__| ' <| _| | |
|
|
7
|
+
|_| |_|_\___|___| |_| |___\___|_|\_\___| |_|
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
# FreeTicket CLI
|
|
11
|
+
|
|
12
|
+
**Tu plataforma de eventos, desde la terminal.**
|
|
13
|
+
|
|
14
|
+
Eventos, ventas, tickets, membresías, venues, staff e informes — todo a un comando de distancia.
|
|
15
|
+
|
|
16
|
+
[](https://www.npmjs.com/package/@freeticket/cli)
|
|
17
|
+
[](https://github.com/AppFreeticket/freeticket-cli/actions/workflows/ci.yml)
|
|
18
|
+
[](./LICENSE)
|
|
19
|
+
[](#requisitos)
|
|
20
|
+
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## ✨ Qué es
|
|
26
|
+
|
|
27
|
+
`ft` es el cliente de línea de comandos oficial de **FreeTicket**. Consume la
|
|
28
|
+
**API REST B2B v1** y te deja inspeccionar y operar tu workspace sin abrir el
|
|
29
|
+
dashboard: listar eventos, revisar ventas, exportar compradores, ver KPIs — todo
|
|
30
|
+
con salida legible o `--json` para pipelines y scripts.
|
|
31
|
+
|
|
32
|
+
El cliente se **genera desde el contrato OpenAPI 3.1** del backend, así que cada
|
|
33
|
+
endpoint que existe en la API existe como comando, y nunca queda desincronizado.
|
|
34
|
+
|
|
35
|
+
## 🚀 Instalación
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# global (recomendado)
|
|
39
|
+
npm install -g @freeticket/cli
|
|
40
|
+
|
|
41
|
+
# o sin instalar
|
|
42
|
+
npx @freeticket/cli whoami
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Comprobá que quedó instalado:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ft --version
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## ⚡ Quickstart
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# 1. Emití una API key en el backend (lado servidor):
|
|
55
|
+
# pnpm api:key tu-email@dominio.com
|
|
56
|
+
# → te devuelve una key ft_live_xxxxx (se muestra una sola vez)
|
|
57
|
+
|
|
58
|
+
# 2. Iniciá sesión (guarda la key en ~/.freeticket/config.json y la verifica)
|
|
59
|
+
ft login --key ft_live_xxxxx
|
|
60
|
+
|
|
61
|
+
# 3. ¿Quién soy y a qué workspaces tengo acceso?
|
|
62
|
+
ft whoami
|
|
63
|
+
|
|
64
|
+
# 4. Empezá a explorar
|
|
65
|
+
ft events list
|
|
66
|
+
ft reports summary --period 30d
|
|
67
|
+
ft sales list --status CONFIRMED --json
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 🧭 Comandos
|
|
71
|
+
|
|
72
|
+
| Comando | Qué hace | Rol mínimo |
|
|
73
|
+
|---|---|---|
|
|
74
|
+
| `ft login --key <key>` | Guarda y verifica tu API key | VIEWER |
|
|
75
|
+
| `ft whoami` | Usuario activo + workspaces accesibles | VIEWER |
|
|
76
|
+
| `ft config` · `ft logout` | Ver config (key enmascarada) · borrar key | — |
|
|
77
|
+
| `ft events list` · `get <id>` | Eventos del workspace | VIEWER |
|
|
78
|
+
| `ft ticket-types list` · `get <id>` | Tipos de ticket (`--event-date-id`) | VIEWER |
|
|
79
|
+
| `ft sales list` · `get <id>` | Ventas (`--status`) | STAFF |
|
|
80
|
+
| `ft plans list` · `get <id>` | Planes de membresía | VIEWER |
|
|
81
|
+
| `ft venues list` · `get <id>` | Venues | VIEWER |
|
|
82
|
+
| `ft staff list` | Staff del workspace | ADMIN |
|
|
83
|
+
| `ft reports summary` | KPIs (`--period 7d\|30d\|90d\|1y`) | VIEWER |
|
|
84
|
+
| `ft reports export buyers\|subscribers` | Exporta compradores / suscriptores | ADMIN |
|
|
85
|
+
|
|
86
|
+
> Las **escrituras** (crear/editar/borrar) están declaradas en el contrato pero
|
|
87
|
+
> responden `501` por ahora — llegan en la **fase 2**.
|
|
88
|
+
|
|
89
|
+
### Flags comunes
|
|
90
|
+
|
|
91
|
+
| Flag | Aplica a | Descripción |
|
|
92
|
+
|---|---|---|
|
|
93
|
+
| `--json` | todos | salida JSON cruda, ideal para `jq` y scripts |
|
|
94
|
+
| `--workspace <id>` | todos | ejecuta el comando contra otro workspace |
|
|
95
|
+
| `--limit <n>` `--cursor <id>` | listados | paginación por cursor (1–100, default 20) |
|
|
96
|
+
|
|
97
|
+
## 🔐 Configuración
|
|
98
|
+
|
|
99
|
+
`ft` resuelve su config en este orden de precedencia:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
flags > variables de entorno > ~/.freeticket/config.json > defaults
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
| Variable | Default | Descripción |
|
|
106
|
+
|---|---|---|
|
|
107
|
+
| `FT_API_URL` | `https://admin.appfreeticket.com` | base de la API (sin `/api/v1`) |
|
|
108
|
+
| `FT_API_KEY` | — | tu key `ft_live_…` |
|
|
109
|
+
| `FT_WORKSPACE_ID` | *home* | workspace activo por defecto |
|
|
110
|
+
|
|
111
|
+
El archivo `~/.freeticket/config.json` se crea con permisos `0600` (solo tu
|
|
112
|
+
usuario lo lee) porque guarda la API key. Mirá [`.env.example`](./.env.example).
|
|
113
|
+
|
|
114
|
+
## 🧱 Paginación, errores y dinero
|
|
115
|
+
|
|
116
|
+
- **Paginación:** los listados devuelven `page.nextCursor`. El CLI te imprime la
|
|
117
|
+
pista `--cursor <id>` en *stderr* para que `--json` quede limpio en *stdout*.
|
|
118
|
+
- **Errores:** formato uniforme `{ error: { code, message, details } }`. El CLI
|
|
119
|
+
traduce `401/403/404/501` a mensajes accionables y sale con código `1`.
|
|
120
|
+
- **Dinero:** número en la moneda del recurso (`currency`, normalmente `COP`).
|
|
121
|
+
- **Fechas:** ISO 8601 UTC.
|
|
122
|
+
|
|
123
|
+
## 🛠️ Desarrollo
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
pnpm install
|
|
127
|
+
pnpm generate # genera src/client/ desde openapi.json
|
|
128
|
+
pnpm build # bundle a dist/ con tsup
|
|
129
|
+
pnpm test # vitest
|
|
130
|
+
pnpm lint # biome
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Mantener el cliente en sync con el backend
|
|
134
|
+
|
|
135
|
+
El contrato vive commiteado en [`openapi.json`](./openapi.json). Cuando el backend
|
|
136
|
+
cambia la API:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
FT_OPENAPI_URL=https://admin.appfreeticket.com/api/v1/openapi.json pnpm sync-openapi
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Esto descarga el spec, lo reescribe en `openapi.json` (el diff queda en git como
|
|
143
|
+
contrato explícito entre equipos) y regenera `src/client/`. Si un `operationId`
|
|
144
|
+
desaparece, TypeScript falla en compilación — el cambio incompatible se ve antes
|
|
145
|
+
de mergear.
|
|
146
|
+
|
|
147
|
+
> `src/client/` es **generado** y está en `.gitignore`: se reconstruye en cada
|
|
148
|
+
> build y en CI. No lo edites a mano.
|
|
149
|
+
|
|
150
|
+
## 📂 Estructura
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
freeticket-cli/
|
|
154
|
+
├── openapi.json # contrato — fuente de verdad versionada
|
|
155
|
+
├── src/
|
|
156
|
+
│ ├── client/ # generado por @hey-api (gitignored)
|
|
157
|
+
│ ├── commands/ # auth, resource (factory), reports
|
|
158
|
+
│ ├── lib/ # config, api, output, banner
|
|
159
|
+
│ └── index.ts # registra los comandos (commander)
|
|
160
|
+
├── scripts/sync-openapi.ts
|
|
161
|
+
└── .claude/agents/ # subagentes de revisión e integración
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 🤖 Agentes
|
|
165
|
+
|
|
166
|
+
El repo trae subagentes de Claude Code en [`.claude/agents/`](./.claude/agents)
|
|
167
|
+
para su revisión e integración continua: revisor TS/CLI, sincronizador de
|
|
168
|
+
OpenAPI, QA del CLI y release/devops. Ver el [README de agentes](./.claude/agents/README.md).
|
|
169
|
+
|
|
170
|
+
## Requisitos
|
|
171
|
+
|
|
172
|
+
- Node.js **≥ 20**
|
|
173
|
+
- Una API key de FreeTicket (`ft_live_…`)
|
|
174
|
+
|
|
175
|
+
## Licencia
|
|
176
|
+
|
|
177
|
+
[MIT](./LICENSE) © FreeTicket
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
|
|
6
|
+
// package.json
|
|
7
|
+
var package_default = {
|
|
8
|
+
name: "@freeticket/cli",
|
|
9
|
+
version: "0.1.0",
|
|
10
|
+
description: "CLI oficial de FreeTicket \u2014 consume la API REST B2B (eventos, ventas, tickets, membres\xEDas, venues, staff, informes).",
|
|
11
|
+
keywords: ["freeticket", "cli", "ticketing", "eventos", "api"],
|
|
12
|
+
homepage: "https://github.com/AppFreeticket/freeticket-cli#readme",
|
|
13
|
+
bugs: "https://github.com/AppFreeticket/freeticket-cli/issues",
|
|
14
|
+
repository: {
|
|
15
|
+
type: "git",
|
|
16
|
+
url: "git+https://github.com/AppFreeticket/freeticket-cli.git"
|
|
17
|
+
},
|
|
18
|
+
license: "MIT",
|
|
19
|
+
author: "FreeTicket",
|
|
20
|
+
type: "module",
|
|
21
|
+
packageManager: "pnpm@10.33.0",
|
|
22
|
+
bin: {
|
|
23
|
+
ft: "dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
files: ["dist"],
|
|
26
|
+
engines: {
|
|
27
|
+
node: ">=20"
|
|
28
|
+
},
|
|
29
|
+
publishConfig: {
|
|
30
|
+
access: "public"
|
|
31
|
+
},
|
|
32
|
+
scripts: {
|
|
33
|
+
build: "tsup",
|
|
34
|
+
dev: "tsup --watch",
|
|
35
|
+
generate: "openapi-ts",
|
|
36
|
+
"sync-openapi": "tsx scripts/sync-openapi.ts",
|
|
37
|
+
lint: "biome check .",
|
|
38
|
+
format: "biome check --write .",
|
|
39
|
+
test: "vitest run",
|
|
40
|
+
"test:watch": "vitest",
|
|
41
|
+
typecheck: "tsc --noEmit",
|
|
42
|
+
prepublishOnly: "pnpm build"
|
|
43
|
+
},
|
|
44
|
+
dependencies: {
|
|
45
|
+
"@hey-api/client-fetch": "^0.10.0",
|
|
46
|
+
chalk: "^5.4.1",
|
|
47
|
+
"cli-table3": "^0.6.5",
|
|
48
|
+
commander: "^13.1.0"
|
|
49
|
+
},
|
|
50
|
+
devDependencies: {
|
|
51
|
+
"@biomejs/biome": "^2.2.0",
|
|
52
|
+
"@hey-api/openapi-ts": "^0.64.0",
|
|
53
|
+
"@types/node": "^22.10.0",
|
|
54
|
+
tsup: "^8.4.0",
|
|
55
|
+
tsx: "^4.19.0",
|
|
56
|
+
typescript: "^5.7.0",
|
|
57
|
+
vitest: "^3.0.0"
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/client/client.gen.ts
|
|
62
|
+
import { createClient, createConfig } from "@hey-api/client-fetch";
|
|
63
|
+
var client = createClient(createConfig({
|
|
64
|
+
baseUrl: "http://localhost:3000/api/v1"
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
// src/client/sdk.gen.ts
|
|
68
|
+
var getMe = (options) => {
|
|
69
|
+
return (options?.client ?? client).get({
|
|
70
|
+
security: [
|
|
71
|
+
{
|
|
72
|
+
name: "Authorization",
|
|
73
|
+
type: "apiKey"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
url: "/me",
|
|
77
|
+
...options
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
var getEvents = (options) => {
|
|
81
|
+
return (options?.client ?? client).get({
|
|
82
|
+
security: [
|
|
83
|
+
{
|
|
84
|
+
name: "Authorization",
|
|
85
|
+
type: "apiKey"
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
url: "/events",
|
|
89
|
+
...options
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
var getEventsId = (options) => {
|
|
93
|
+
return (options.client ?? client).get({
|
|
94
|
+
security: [
|
|
95
|
+
{
|
|
96
|
+
name: "Authorization",
|
|
97
|
+
type: "apiKey"
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
url: "/events/{id}",
|
|
101
|
+
...options
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
var getTicketTypes = (options) => {
|
|
105
|
+
return (options?.client ?? client).get({
|
|
106
|
+
security: [
|
|
107
|
+
{
|
|
108
|
+
name: "Authorization",
|
|
109
|
+
type: "apiKey"
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
url: "/ticket-types",
|
|
113
|
+
...options
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
var getTicketTypesId = (options) => {
|
|
117
|
+
return (options.client ?? client).get({
|
|
118
|
+
security: [
|
|
119
|
+
{
|
|
120
|
+
name: "Authorization",
|
|
121
|
+
type: "apiKey"
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
url: "/ticket-types/{id}",
|
|
125
|
+
...options
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
var getSales = (options) => {
|
|
129
|
+
return (options?.client ?? client).get({
|
|
130
|
+
security: [
|
|
131
|
+
{
|
|
132
|
+
name: "Authorization",
|
|
133
|
+
type: "apiKey"
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
url: "/sales",
|
|
137
|
+
...options
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
var getSalesId = (options) => {
|
|
141
|
+
return (options.client ?? client).get({
|
|
142
|
+
security: [
|
|
143
|
+
{
|
|
144
|
+
name: "Authorization",
|
|
145
|
+
type: "apiKey"
|
|
146
|
+
}
|
|
147
|
+
],
|
|
148
|
+
url: "/sales/{id}",
|
|
149
|
+
...options
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
var getMembershipPlans = (options) => {
|
|
153
|
+
return (options?.client ?? client).get({
|
|
154
|
+
security: [
|
|
155
|
+
{
|
|
156
|
+
name: "Authorization",
|
|
157
|
+
type: "apiKey"
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
url: "/membership-plans",
|
|
161
|
+
...options
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
var getMembershipPlansId = (options) => {
|
|
165
|
+
return (options.client ?? client).get({
|
|
166
|
+
security: [
|
|
167
|
+
{
|
|
168
|
+
name: "Authorization",
|
|
169
|
+
type: "apiKey"
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
url: "/membership-plans/{id}",
|
|
173
|
+
...options
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
var getVenues = (options) => {
|
|
177
|
+
return (options?.client ?? client).get({
|
|
178
|
+
security: [
|
|
179
|
+
{
|
|
180
|
+
name: "Authorization",
|
|
181
|
+
type: "apiKey"
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
url: "/venues",
|
|
185
|
+
...options
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
var getVenuesId = (options) => {
|
|
189
|
+
return (options.client ?? client).get({
|
|
190
|
+
security: [
|
|
191
|
+
{
|
|
192
|
+
name: "Authorization",
|
|
193
|
+
type: "apiKey"
|
|
194
|
+
}
|
|
195
|
+
],
|
|
196
|
+
url: "/venues/{id}",
|
|
197
|
+
...options
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
var getStaff = (options) => {
|
|
201
|
+
return (options?.client ?? client).get({
|
|
202
|
+
security: [
|
|
203
|
+
{
|
|
204
|
+
name: "Authorization",
|
|
205
|
+
type: "apiKey"
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
url: "/staff",
|
|
209
|
+
...options
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
var getReportsSummary = (options) => {
|
|
213
|
+
return (options?.client ?? client).get({
|
|
214
|
+
security: [
|
|
215
|
+
{
|
|
216
|
+
name: "Authorization",
|
|
217
|
+
type: "apiKey"
|
|
218
|
+
}
|
|
219
|
+
],
|
|
220
|
+
url: "/reports/summary",
|
|
221
|
+
...options
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
var getReportsExportsBuyers = (options) => {
|
|
225
|
+
return (options?.client ?? client).get({
|
|
226
|
+
security: [
|
|
227
|
+
{
|
|
228
|
+
name: "Authorization",
|
|
229
|
+
type: "apiKey"
|
|
230
|
+
}
|
|
231
|
+
],
|
|
232
|
+
url: "/reports/exports/buyers",
|
|
233
|
+
...options
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
var getReportsExportsSubscribers = (options) => {
|
|
237
|
+
return (options?.client ?? client).get({
|
|
238
|
+
security: [
|
|
239
|
+
{
|
|
240
|
+
name: "Authorization",
|
|
241
|
+
type: "apiKey"
|
|
242
|
+
}
|
|
243
|
+
],
|
|
244
|
+
url: "/reports/exports/subscribers",
|
|
245
|
+
...options
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// src/commands/auth.ts
|
|
250
|
+
import chalk2 from "chalk";
|
|
251
|
+
|
|
252
|
+
// src/lib/config.ts
|
|
253
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
254
|
+
import { homedir } from "os";
|
|
255
|
+
import { dirname, join } from "path";
|
|
256
|
+
var CONFIG_DIR = join(homedir(), ".freeticket");
|
|
257
|
+
var CONFIG_PATH = join(CONFIG_DIR, "config.json");
|
|
258
|
+
var DEFAULT_API_URL = "https://admin.appfreeticket.com";
|
|
259
|
+
function readFile() {
|
|
260
|
+
if (!existsSync(CONFIG_PATH)) return {};
|
|
261
|
+
try {
|
|
262
|
+
return JSON.parse(readFileSync(CONFIG_PATH, "utf8"));
|
|
263
|
+
} catch {
|
|
264
|
+
return {};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
function loadConfig() {
|
|
268
|
+
const file = readFile();
|
|
269
|
+
return {
|
|
270
|
+
apiUrl: process.env.FT_API_URL ?? file.apiUrl ?? DEFAULT_API_URL,
|
|
271
|
+
apiKey: process.env.FT_API_KEY ?? file.apiKey,
|
|
272
|
+
workspaceId: process.env.FT_WORKSPACE_ID ?? file.workspaceId
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function saveConfig(patch) {
|
|
276
|
+
const next = { ...readFile(), ...patch };
|
|
277
|
+
mkdirSync(dirname(CONFIG_PATH), { recursive: true });
|
|
278
|
+
writeFileSync(CONFIG_PATH, `${JSON.stringify(next, null, 2)}
|
|
279
|
+
`, {
|
|
280
|
+
mode: 384
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/lib/api.ts
|
|
285
|
+
function configureClient(workspaceOverride) {
|
|
286
|
+
const cfg = loadConfig();
|
|
287
|
+
if (!cfg.apiKey) {
|
|
288
|
+
fail(
|
|
289
|
+
"No hay API key configurada. Ejecuta `ft login` o exporta FT_API_KEY."
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
const workspaceId = workspaceOverride ?? cfg.workspaceId;
|
|
293
|
+
client.setConfig({
|
|
294
|
+
baseUrl: `${cfg.apiUrl.replace(/\/$/, "")}/api/v1`,
|
|
295
|
+
headers: {
|
|
296
|
+
Authorization: `Bearer ${cfg.apiKey}`,
|
|
297
|
+
...workspaceId ? { "X-Workspace-Id": workspaceId } : {}
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function unwrap(res) {
|
|
302
|
+
if (res.data !== void 0) return res.data;
|
|
303
|
+
const status = res.response?.status;
|
|
304
|
+
const err = res.error?.error;
|
|
305
|
+
if (err) {
|
|
306
|
+
const lines = [
|
|
307
|
+
`Error ${status ?? ""} [${err.code ?? "?"}]: ${err.message ?? "fallo desconocido"}`.trim()
|
|
308
|
+
];
|
|
309
|
+
for (const d of err.details ?? [])
|
|
310
|
+
lines.push(` \xB7 ${d.path ?? ""}: ${d.message ?? ""}`.trimEnd());
|
|
311
|
+
fail(lines.join("\n"), hintFor(status));
|
|
312
|
+
}
|
|
313
|
+
fail(`La API respondi\xF3 ${status ?? "un error"} sin cuerpo interpretable.`);
|
|
314
|
+
}
|
|
315
|
+
function hintFor(status) {
|
|
316
|
+
switch (status) {
|
|
317
|
+
case 401:
|
|
318
|
+
return "API key inv\xE1lida, revocada o expirada. Ejecuta `ft login`.";
|
|
319
|
+
case 403:
|
|
320
|
+
return "Tu rol o tu workspace no permiten esta acci\xF3n.";
|
|
321
|
+
case 404:
|
|
322
|
+
return "El recurso no existe o pertenece a otro workspace.";
|
|
323
|
+
case 501:
|
|
324
|
+
return "Operaci\xF3n de escritura: disponible en la fase 2 del CLI.";
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
function fail(message, hint) {
|
|
328
|
+
console.error(message);
|
|
329
|
+
if (hint) console.error(`
|
|
330
|
+
${hint}`);
|
|
331
|
+
process.exit(1);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// src/lib/output.ts
|
|
335
|
+
import chalk from "chalk";
|
|
336
|
+
import Table from "cli-table3";
|
|
337
|
+
function print(data, opts = {}) {
|
|
338
|
+
if (opts.json) {
|
|
339
|
+
process.stdout.write(`${JSON.stringify(data, null, 2)}
|
|
340
|
+
`);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
if (Array.isArray(data) && data.every(isPlainRow)) {
|
|
344
|
+
if (data.length === 0) {
|
|
345
|
+
console.log(chalk.dim("(sin resultados)"));
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const cols = opts.columns ?? Object.keys(data[0]);
|
|
349
|
+
const table = new Table({ head: cols.map((c2) => chalk.hex("#07C2BA")(c2)) });
|
|
350
|
+
for (const row of data) {
|
|
351
|
+
table.push(cols.map((c2) => fmt(row[c2])));
|
|
352
|
+
}
|
|
353
|
+
console.log(table.toString());
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
process.stdout.write(`${JSON.stringify(data, null, 2)}
|
|
357
|
+
`);
|
|
358
|
+
}
|
|
359
|
+
function printNextCursor(page) {
|
|
360
|
+
if (page?.nextCursor) {
|
|
361
|
+
console.error(chalk.dim(`
|
|
362
|
+
M\xE1s resultados: --cursor ${page.nextCursor}`));
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function isPlainRow(v) {
|
|
366
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
367
|
+
}
|
|
368
|
+
function fmt(v) {
|
|
369
|
+
if (v === null || v === void 0) return chalk.dim("\u2014");
|
|
370
|
+
if (typeof v === "object") return JSON.stringify(v);
|
|
371
|
+
return String(v);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// src/commands/auth.ts
|
|
375
|
+
function registerAuth(program2) {
|
|
376
|
+
program2.command("login").description(
|
|
377
|
+
"Guarda la API key y el workspace en ~/.freeticket/config.json"
|
|
378
|
+
).requiredOption(
|
|
379
|
+
"--key <ft_live_\u2026>",
|
|
380
|
+
"API key emitida en el backend (pnpm api:key)"
|
|
381
|
+
).option(
|
|
382
|
+
"--url <url>",
|
|
383
|
+
"base URL de la API (default: https://admin.appfreeticket.com)"
|
|
384
|
+
).option("--workspace <id>", "workspace activo por defecto").action(async (opts) => {
|
|
385
|
+
saveConfig({
|
|
386
|
+
apiKey: opts.key,
|
|
387
|
+
...opts.url ? { apiUrl: opts.url } : {},
|
|
388
|
+
...opts.workspace ? { workspaceId: opts.workspace } : {}
|
|
389
|
+
});
|
|
390
|
+
configureClient(opts.workspace);
|
|
391
|
+
const me = unwrap(await getMe({})).data;
|
|
392
|
+
console.log(
|
|
393
|
+
`${chalk2.green("\u2713")} Sesi\xF3n guardada en ${chalk2.dim(CONFIG_PATH)}`
|
|
394
|
+
);
|
|
395
|
+
print(me, {});
|
|
396
|
+
});
|
|
397
|
+
program2.command("whoami").description("Muestra el usuario autenticado y sus workspaces (GET /me)").option("--json", "salida JSON cruda").action(async (opts) => {
|
|
398
|
+
configureClient();
|
|
399
|
+
const me = unwrap(await getMe({})).data;
|
|
400
|
+
print(me, { json: opts.json });
|
|
401
|
+
});
|
|
402
|
+
program2.command("logout").description("Borra la API key guardada").action(() => {
|
|
403
|
+
saveConfig({ apiKey: void 0 });
|
|
404
|
+
console.log(
|
|
405
|
+
`${chalk2.green("\u2713")} API key eliminada de ${chalk2.dim(CONFIG_PATH)}`
|
|
406
|
+
);
|
|
407
|
+
});
|
|
408
|
+
program2.command("config").description("Muestra la configuraci\xF3n activa (la API key se enmascara)").action(() => {
|
|
409
|
+
const cfg = loadConfig();
|
|
410
|
+
print(
|
|
411
|
+
{
|
|
412
|
+
apiUrl: cfg.apiUrl,
|
|
413
|
+
apiKey: cfg.apiKey ? `${cfg.apiKey.slice(0, 12)}\u2026` : null,
|
|
414
|
+
workspaceId: cfg.workspaceId ?? null
|
|
415
|
+
},
|
|
416
|
+
{}
|
|
417
|
+
);
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// src/commands/reports.ts
|
|
422
|
+
function registerReports(program2) {
|
|
423
|
+
const root = program2.command("reports").description("KPIs y exportaciones");
|
|
424
|
+
root.command("summary").description("Resumen de KPIs del workspace").option("--period <p>", "7d | 30d | 90d | 1y", "30d").option("--workspace <id>", "override del workspace").option("--json", "salida JSON cruda").action(async (opts) => {
|
|
425
|
+
configureClient(opts.workspace);
|
|
426
|
+
const body = unwrap(
|
|
427
|
+
await getReportsSummary({ query: { period: opts.period } })
|
|
428
|
+
);
|
|
429
|
+
print(body.data, { json: opts.json });
|
|
430
|
+
});
|
|
431
|
+
const exp = root.command("export").description("Exporta compradores o suscriptores (CSV)");
|
|
432
|
+
for (const [name, fn, label] of [
|
|
433
|
+
["buyers", getReportsExportsBuyers, "compradores"],
|
|
434
|
+
["subscribers", getReportsExportsSubscribers, "suscriptores"]
|
|
435
|
+
]) {
|
|
436
|
+
exp.command(name).description(`Exporta ${label}`).option("--workspace <id>", "override del workspace").option("--json", "salida JSON cruda").action(async (opts) => {
|
|
437
|
+
configureClient(opts.workspace);
|
|
438
|
+
const body = unwrap(await fn({}));
|
|
439
|
+
print(body.data ?? body, { json: opts.json });
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// src/commands/resource.ts
|
|
445
|
+
function registerResource(program2, spec) {
|
|
446
|
+
const root = program2.command(spec.name).description(spec.describe);
|
|
447
|
+
if (spec.list) {
|
|
448
|
+
const list = spec.list;
|
|
449
|
+
const cmd = root.command("list").description(`Lista ${spec.name} del workspace activo`).option("--limit <n>", "resultados por p\xE1gina (1\u2013100)", "20").option("--cursor <id>", "cursor de paginaci\xF3n").option("--workspace <id>", "override del workspace").option("--json", "salida JSON cruda");
|
|
450
|
+
for (const f of spec.listFlags ?? []) cmd.option(f.flag, f.describe);
|
|
451
|
+
cmd.action(async (opts) => {
|
|
452
|
+
configureClient(opts.workspace);
|
|
453
|
+
const query = {
|
|
454
|
+
limit: Number(opts.limit),
|
|
455
|
+
cursor: opts.cursor
|
|
456
|
+
};
|
|
457
|
+
for (const f of spec.listFlags ?? []) {
|
|
458
|
+
const v = opts[camel(f.query)];
|
|
459
|
+
if (v !== void 0) query[f.query] = v;
|
|
460
|
+
}
|
|
461
|
+
const body = unwrap(await list({ query }));
|
|
462
|
+
print(body.data, { json: opts.json, columns: spec.columns });
|
|
463
|
+
if (!opts.json) printNextCursor(body.page);
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
if (spec.get) {
|
|
467
|
+
const get = spec.get;
|
|
468
|
+
root.command("get <id>").description(`Detalle de un ${spec.name.replace(/s$/, "")} por id`).option("--workspace <id>", "override del workspace").option("--json", "salida JSON cruda").action(async (id, opts) => {
|
|
469
|
+
configureClient(opts.workspace);
|
|
470
|
+
const body = unwrap(await get({ path: { id } }));
|
|
471
|
+
print(body.data, { json: opts.json });
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function camel(s) {
|
|
476
|
+
return s.replace(/-([a-z])/g, (_, c2) => c2.toUpperCase());
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// src/lib/banner.ts
|
|
480
|
+
import { Chalk } from "chalk";
|
|
481
|
+
var YELLOW = "#FFD500";
|
|
482
|
+
var c = new Chalk({ level: 3 });
|
|
483
|
+
var ART = String.raw`
|
|
484
|
+
___ ___ ___ ___ _____ ___ ___ _ _____ _____
|
|
485
|
+
| __| _ \ __| __|_ _|_ _/ __| |/ / __|_ _|
|
|
486
|
+
| _|| / _|| _| | | | | (__| ' <| _| | |
|
|
487
|
+
|_| |_|_\___|___| |_| |___\___|_|\_\___| |_|
|
|
488
|
+
`;
|
|
489
|
+
function banner() {
|
|
490
|
+
return [
|
|
491
|
+
c.hex(YELLOW)(ART),
|
|
492
|
+
c.hex(YELLOW)(" \u25CF ") + c.hex(YELLOW).bold("FreeTicket") + c.hex(YELLOW)(" \u2014 eventos, tickets y ventas desde tu terminal"),
|
|
493
|
+
""
|
|
494
|
+
].join("\n");
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// src/index.ts
|
|
498
|
+
var program = new Command();
|
|
499
|
+
program.name("ft").description("CLI oficial de FreeTicket").version(package_default.version, "-v, --version").addHelpText("beforeAll", banner());
|
|
500
|
+
registerAuth(program);
|
|
501
|
+
registerResource(program, {
|
|
502
|
+
name: "events",
|
|
503
|
+
describe: "Eventos",
|
|
504
|
+
list: getEvents,
|
|
505
|
+
get: getEventsId,
|
|
506
|
+
columns: ["id", "name", "status", "startsAt"]
|
|
507
|
+
});
|
|
508
|
+
registerResource(program, {
|
|
509
|
+
name: "sales",
|
|
510
|
+
describe: "Ventas",
|
|
511
|
+
list: getSales,
|
|
512
|
+
get: getSalesId,
|
|
513
|
+
columns: ["id", "reference", "status", "total", "currency", "createdAt"],
|
|
514
|
+
listFlags: [
|
|
515
|
+
{ flag: "--status <s>", describe: "filtra por estado", query: "status" }
|
|
516
|
+
]
|
|
517
|
+
});
|
|
518
|
+
registerResource(program, {
|
|
519
|
+
name: "ticket-types",
|
|
520
|
+
describe: "Tipos de ticket",
|
|
521
|
+
list: getTicketTypes,
|
|
522
|
+
get: getTicketTypesId,
|
|
523
|
+
columns: ["id", "name", "price", "currency", "stock"],
|
|
524
|
+
listFlags: [
|
|
525
|
+
{
|
|
526
|
+
flag: "--event-date-id <id>",
|
|
527
|
+
describe: "filtra por fecha de evento",
|
|
528
|
+
query: "eventDateId"
|
|
529
|
+
}
|
|
530
|
+
]
|
|
531
|
+
});
|
|
532
|
+
registerResource(program, {
|
|
533
|
+
name: "plans",
|
|
534
|
+
describe: "Planes de membres\xEDa",
|
|
535
|
+
list: getMembershipPlans,
|
|
536
|
+
get: getMembershipPlansId,
|
|
537
|
+
columns: ["id", "name", "price", "currency", "interval"]
|
|
538
|
+
});
|
|
539
|
+
registerResource(program, {
|
|
540
|
+
name: "venues",
|
|
541
|
+
describe: "Venues",
|
|
542
|
+
list: getVenues,
|
|
543
|
+
get: getVenuesId,
|
|
544
|
+
columns: ["id", "name", "city"]
|
|
545
|
+
});
|
|
546
|
+
registerResource(program, {
|
|
547
|
+
name: "staff",
|
|
548
|
+
describe: "Staff del workspace",
|
|
549
|
+
list: getStaff,
|
|
550
|
+
columns: ["id", "name", "email", "role"]
|
|
551
|
+
});
|
|
552
|
+
registerReports(program);
|
|
553
|
+
if (process.argv.length <= 2) {
|
|
554
|
+
console.log(banner());
|
|
555
|
+
program.outputHelp();
|
|
556
|
+
process.exit(0);
|
|
557
|
+
}
|
|
558
|
+
program.parseAsync().catch((err) => {
|
|
559
|
+
console.error(err instanceof Error ? err.message : err);
|
|
560
|
+
process.exit(1);
|
|
561
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@freeticket/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI oficial de FreeTicket — consume la API REST B2B (eventos, ventas, tickets, membresías, venues, staff, informes).",
|
|
5
|
+
"keywords": ["freeticket", "cli", "ticketing", "eventos", "api"],
|
|
6
|
+
"homepage": "https://github.com/AppFreeticket/freeticket-cli#readme",
|
|
7
|
+
"bugs": "https://github.com/AppFreeticket/freeticket-cli/issues",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/AppFreeticket/freeticket-cli.git"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "FreeTicket",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"packageManager": "pnpm@10.33.0",
|
|
16
|
+
"bin": {
|
|
17
|
+
"ft": "dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"files": ["dist"],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"dev": "tsup --watch",
|
|
29
|
+
"generate": "openapi-ts",
|
|
30
|
+
"sync-openapi": "tsx scripts/sync-openapi.ts",
|
|
31
|
+
"lint": "biome check .",
|
|
32
|
+
"format": "biome check --write .",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"prepublishOnly": "pnpm build"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@hey-api/client-fetch": "^0.10.0",
|
|
40
|
+
"chalk": "^5.4.1",
|
|
41
|
+
"cli-table3": "^0.6.5",
|
|
42
|
+
"commander": "^13.1.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@biomejs/biome": "^2.2.0",
|
|
46
|
+
"@hey-api/openapi-ts": "^0.64.0",
|
|
47
|
+
"@types/node": "^22.10.0",
|
|
48
|
+
"tsup": "^8.4.0",
|
|
49
|
+
"tsx": "^4.19.0",
|
|
50
|
+
"typescript": "^5.7.0",
|
|
51
|
+
"vitest": "^3.0.0"
|
|
52
|
+
}
|
|
53
|
+
}
|