@freeticket/cli 0.4.0 → 0.5.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.
Files changed (3) hide show
  1. package/README.md +33 -13
  2. package/dist/index.js +190 -14
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -51,16 +51,20 @@ ft --version
51
51
  ## Quickstart
52
52
 
53
53
  ```bash
54
- # 1. Issue an API key in the backend (server side):
55
- # pnpm api:key you@example.com
56
- # -> returns an ft_live_xxxxx key (shown only once)
54
+ # 1. Log in through the browser (OAuth device flow). Prints a code, opens your
55
+ # browser, you approve, and the session is stored in ~/.freeticket/config.json.
56
+ ft login
57
57
 
58
- # 2. Log in (stores the key in ~/.freeticket/config.json and verifies it)
59
- ft login --key ft_live_xxxxx
58
+ # CI / automation: skip the browser with a backend-issued key instead.
59
+ # ft login --key ft_live_xxxxx
60
60
 
61
- # 3. Who am I, and which workspaces can I access?
61
+ # 2. Who am I, and which workspaces can I access?
62
62
  ft whoami
63
63
 
64
+ # 3. Pick the workspace you want to operate on (persisted locally).
65
+ ft workspace list
66
+ ft workspace use my-workspace-slug
67
+
64
68
  # 4. Start exploring
65
69
  ft events list
66
70
  ft reports summary --period 30d
@@ -71,20 +75,29 @@ ft sales list --status CONFIRMED --json
71
75
 
72
76
  | Command | What it does | Minimum role |
73
77
  |---|---|---|
74
- | `ft login --key <key>` | Stores and verifies your API key | VIEWER |
78
+ | `ft login` | Browser login (device flow); `--key <key>` for CI | VIEWER |
75
79
  | `ft whoami` | Active user and accessible workspaces | VIEWER |
76
80
  | `ft config` · `ft logout` | Show config (masked key) · remove key | — |
81
+ | `ft workspace list` · `use <id\|slug>` · `show` | List, switch, and show the active workspace | VIEWER |
77
82
  | `ft events list` · `get <id>` | Workspace events | VIEWER |
83
+ | `ft events create` · `update <id>` · `delete <id>` | Manage events (`--data <json>`) | ADMIN |
84
+ | `ft events publish <id>` | Publish an event | ADMIN |
85
+ | `ft event-dates list` · `create` · `update` · `delete` | Event dates | ADMIN |
78
86
  | `ft ticket-types list` · `get <id>` | Ticket types (`--event-date-id`) | VIEWER |
87
+ | `ft ticket-types create` · `update <id>` · `delete <id>` | Manage ticket types (`--data <json>`) | ADMIN |
79
88
  | `ft sales list` · `get <id>` | Sales (`--status`) | STAFF |
89
+ | `ft sales cancel <id>` · `refund <id>` | Cancel / refund a sale (`--data` for partial refund) | ADMIN |
80
90
  | `ft plans list` · `get <id>` | Membership plans | VIEWER |
91
+ | `ft plans create` · `update <id>` · `delete <id>` | Manage membership plans (`--data <json>`) | ADMIN |
81
92
  | `ft venues list` · `get <id>` | Venues | VIEWER |
82
- | `ft staff list` | Workspace staff | ADMIN |
93
+ | `ft venues create` · `update <id>` · `delete <id>` | Manage venues (`--data <json>`) | ADMIN |
94
+ | `ft staff list` · `create` · `set-role <id>` | Workspace staff (`--data <json>`) | ADMIN |
83
95
  | `ft reports summary` | KPIs (`--period 7d\|30d\|90d\|1y`) | VIEWER |
84
96
  | `ft reports export buyers\|subscribers` | Export buyers / subscribers | ADMIN |
85
97
 
86
- > **Write operations** (create/update/delete) are declared in the contract but
87
- > currently return `501`. They are planned for **phase 2**.
98
+ > **Write operations** (`create`/`update`/`delete` and actions like `publish`,
99
+ > `cancel`, `refund`) send a JSON body via `--data <inline-json>` or
100
+ > `--data @file.json`. `delete` prompts for confirmation unless you pass `--yes`.
88
101
 
89
102
  ### Common flags
90
103
 
@@ -93,6 +106,11 @@ ft sales list --status CONFIRMED --json
93
106
  | `--json` | all commands | Raw JSON output, ideal for `jq` and scripts |
94
107
  | `--workspace <id>` | all commands | Run the command against another workspace |
95
108
  | `--limit <n>` `--cursor <id>` | list commands | Cursor pagination (1-100, default 20) |
109
+ | `--all` | list commands | Auto-paginate: fetch every page (ignores `--cursor`) |
110
+ | `--raw` | list commands | JSON output including the `page` pagination metadata |
111
+ | `--columns <a,b,c>` `--full` | list commands | Pick specific columns · show every field |
112
+ | `--csv` | list commands | CSV output for spreadsheets/accounting |
113
+ | `--data <json>` `--yes` | write commands | JSON body (inline or `@file`) · skip delete confirmation |
96
114
 
97
115
  ## Configuration
98
116
 
@@ -113,8 +131,10 @@ your user can read it) because it stores the API key. See [`.env.example`](./.en
113
131
 
114
132
  ## Pagination, errors, and money
115
133
 
116
- - **Pagination:** list responses include `page.nextCursor`. The CLI prints the
117
- `--cursor <id>` hint to *stderr* so `--json` stays clean on *stdout*.
134
+ - **Pagination:** list responses include `page.nextCursor` / `page.hasMore`. The
135
+ CLI prints the `--cursor <id>` hint to *stderr* so `--json` stays clean on
136
+ *stdout*. Use `--all` to auto-paginate every page, or `--raw` to emit the full
137
+ `{ data, page }` envelope (metadata included) as JSON.
118
138
  - **Errors:** uniform format `{ error: { code, message, details } }`. The CLI
119
139
  translates `401/403/404/501` into actionable messages and exits with code `1`.
120
140
  - **Money:** number in the resource currency (`currency`, usually `COP`).
@@ -170,7 +190,7 @@ CLI QA, and release/devops. See the [agents README](./.claude/agents/README.md).
170
190
  ## Requirements
171
191
 
172
192
  - Node.js **>= 20**
173
- - A FreeTicket API key (`ft_live_...`)
193
+ - A FreeTicket account (`ft login` opens the browser; no API key needed)
174
194
 
175
195
  ## License
176
196
 
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@freeticket/cli",
9
- version: "0.4.0",
9
+ version: "0.5.0",
10
10
  description: "Official FreeTicket CLI \u2014 consumes the B2B REST API for events, sales, tickets, memberships, venues, staff, and reports.",
11
11
  keywords: [
12
12
  "freeticket",
@@ -74,6 +74,22 @@ var client = createClient(createConfig({
74
74
  }));
75
75
 
76
76
  // src/client/sdk.gen.ts
77
+ var postAuthDeviceCode = (options) => {
78
+ return (options?.client ?? client).post({
79
+ url: "/auth/device/code",
80
+ ...options
81
+ });
82
+ };
83
+ var postAuthDeviceToken = (options) => {
84
+ return (options.client ?? client).post({
85
+ url: "/auth/device/token",
86
+ ...options,
87
+ headers: {
88
+ "Content-Type": "application/json",
89
+ ...options?.headers
90
+ }
91
+ });
92
+ };
77
93
  var getMe = (options) => {
78
94
  return (options?.client ?? client).get({
79
95
  security: [
@@ -930,7 +946,7 @@ function hintFor(status) {
930
946
  case 404:
931
947
  return "The resource does not exist or belongs to another workspace.";
932
948
  case 501:
933
- return "Write operation: planned for CLI phase 2.";
949
+ return "The backend has not implemented this operation yet.";
934
950
  }
935
951
  }
936
952
  function fail(message, hint) {
@@ -1017,6 +1033,13 @@ function toCsv(rows, columns) {
1017
1033
  );
1018
1034
  return [head, ...body].join("\n");
1019
1035
  }
1036
+ function resolveColumns(opts, fallback) {
1037
+ if (opts.full) return void 0;
1038
+ if (opts.columns) {
1039
+ return opts.columns.split(",").map((c2) => c2.trim()).filter(Boolean);
1040
+ }
1041
+ return fallback;
1042
+ }
1020
1043
  function printNextCursor(page) {
1021
1044
  if (page?.nextCursor) {
1022
1045
  console.error(chalk.dim(`
@@ -1219,21 +1242,26 @@ function camel(s) {
1219
1242
  }
1220
1243
 
1221
1244
  // src/commands/auth.ts
1245
+ import { spawn } from "child_process";
1222
1246
  import chalk2 from "chalk";
1223
1247
  function registerAuth(program2) {
1224
- program2.command("login").description("Store the API key and workspace in ~/.freeticket/config.json").requiredOption(
1248
+ program2.command("login").description(
1249
+ "Log in via the browser (device flow) and store the session in ~/.freeticket/config.json"
1250
+ ).option(
1225
1251
  "--key <ft_live_\u2026>",
1226
- "API key issued in the backend (pnpm api:key)"
1252
+ "Skip the browser and use an API key issued in the backend (CI / automation)"
1227
1253
  ).option(
1228
1254
  "--url <url>",
1229
1255
  "API base URL (default: https://admin.appfreeticket.com)"
1230
1256
  ).option("--workspace <id>", "default active workspace").action(async (opts) => {
1257
+ if (opts.url) saveConfig({ apiUrl: opts.url });
1258
+ const cred = opts.key ? { apiKey: opts.key, workspaceId: void 0 } : await deviceLogin();
1259
+ const workspaceId = opts.workspace ?? cred.workspaceId;
1231
1260
  saveConfig({
1232
- apiKey: opts.key,
1233
- ...opts.url ? { apiUrl: opts.url } : {},
1234
- ...opts.workspace ? { workspaceId: opts.workspace } : {}
1261
+ apiKey: cred.apiKey,
1262
+ ...workspaceId ? { workspaceId } : {}
1235
1263
  });
1236
- configureClient(opts.workspace);
1264
+ configureClient(workspaceId);
1237
1265
  const me = unwrap(await getMe({})).data;
1238
1266
  console.log(
1239
1267
  `${chalk2.green("\u2713")} Session saved in ${chalk2.dim(CONFIG_PATH)}`
@@ -1263,6 +1291,68 @@ function registerAuth(program2) {
1263
1291
  );
1264
1292
  });
1265
1293
  }
1294
+ var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
1295
+ function openBrowser(url) {
1296
+ const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
1297
+ try {
1298
+ spawn(cmd, [url], { stdio: "ignore", detached: true }).unref();
1299
+ } catch {
1300
+ }
1301
+ }
1302
+ async function deviceLogin() {
1303
+ const apiUrl = loadConfig().apiUrl.replace(/\/$/, "");
1304
+ client.setConfig({ baseUrl: `${apiUrl}/api/v1` });
1305
+ const start = unwrap(await postAuthDeviceCode({}));
1306
+ console.log(
1307
+ `
1308
+ Open ${chalk2.cyan(start.verification_uri)} and enter the code:
1309
+
1310
+ ${chalk2.bold(start.user_code)}
1311
+
1312
+ ${chalk2.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1313
+ `
1314
+ );
1315
+ openBrowser(start.verification_uri_complete);
1316
+ const deadline = Date.now() + start.expires_in * 1e3;
1317
+ let interval = start.interval;
1318
+ while (Date.now() < deadline) {
1319
+ await sleep(interval * 1e3);
1320
+ const res = await postAuthDeviceToken({
1321
+ body: {
1322
+ device_code: start.device_code,
1323
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code"
1324
+ }
1325
+ });
1326
+ if (res.data) {
1327
+ const { access_token, workspaces } = res.data;
1328
+ const active = workspaces[0];
1329
+ if (workspaces.length > 1 && active) {
1330
+ console.log(
1331
+ `
1332
+ ${chalk2.dim("Workspaces:")} ${workspaces.map((w) => w.slug).join(", ")} ${chalk2.dim(`(using ${active.slug}; switch with --workspace)`)}`
1333
+ );
1334
+ }
1335
+ return { apiKey: access_token, workspaceId: active?.id };
1336
+ }
1337
+ switch (res.error?.error) {
1338
+ case "authorization_pending":
1339
+ break;
1340
+ // keep polling at the same cadence
1341
+ case "slow_down":
1342
+ interval += 5;
1343
+ break;
1344
+ case "access_denied":
1345
+ fail("Login was denied in the browser.");
1346
+ break;
1347
+ case "expired_token":
1348
+ fail("The code expired before approval. Run `ft login` again.");
1349
+ break;
1350
+ default:
1351
+ fail(`Device login failed: ${res.error?.error ?? "unknown error"}.`);
1352
+ }
1353
+ }
1354
+ return fail("The code expired before approval. Run `ft login` again.");
1355
+ }
1266
1356
 
1267
1357
  // src/commands/event-dates.ts
1268
1358
  function registerEventDates(program2, spec) {
@@ -1368,10 +1458,11 @@ function registerResource(program2, spec) {
1368
1458
  const singular = spec.name.replace(/s$/, "");
1369
1459
  if (spec.list) {
1370
1460
  const list = spec.list;
1371
- const cmd = root.command("list").description(`List ${spec.name} from the active workspace`).option("--limit <n>", "results per page (1-100)", "20").option("--cursor <id>", "pagination cursor").option("--workspace <id>", "workspace override").option("--csv", "CSV output (for spreadsheets/accounting)").option("--json", "raw JSON output");
1461
+ const cmd = root.command("list").description(`List ${spec.name} from the active workspace`).option("--limit <n>", "results per page (1-100)", "20").option("--cursor <id>", "pagination cursor").option("--all", "auto-paginate: fetch every page (ignores --cursor)").option("--columns <list>", "comma-separated columns to display").option("--full", "show every field instead of the curated columns").option("--workspace <id>", "workspace override").option("--csv", "CSV output (for spreadsheets/accounting)").option("--json", "raw JSON output (data only)").option("--raw", "raw JSON output including pagination metadata (page)");
1372
1462
  for (const f of spec.listFlags ?? []) cmd.option(f.flag, f.describe);
1373
1463
  cmd.action(async (opts) => {
1374
1464
  configureClient(opts.workspace);
1465
+ const columns = resolveColumns(opts, spec.columns);
1375
1466
  const query = {
1376
1467
  limit: Number(opts.limit),
1377
1468
  cursor: opts.cursor
@@ -1380,13 +1471,42 @@ function registerResource(program2, spec) {
1380
1471
  const v = opts[camel2(f.query)];
1381
1472
  if (v !== void 0) query[f.query] = v;
1382
1473
  }
1474
+ if (opts.all) {
1475
+ const rows = [];
1476
+ let cursor;
1477
+ let page;
1478
+ do {
1479
+ const body2 = unwrap(await list({ query: { ...query, cursor } }));
1480
+ rows.push(...body2.data ?? []);
1481
+ page = body2.page;
1482
+ cursor = page?.nextCursor ?? void 0;
1483
+ } while (page?.hasMore && cursor);
1484
+ if (opts.raw) {
1485
+ print(
1486
+ { data: rows, page: { nextCursor: null, hasMore: false } },
1487
+ { json: true }
1488
+ );
1489
+ return;
1490
+ }
1491
+ if (opts.csv) {
1492
+ process.stdout.write(`${toCsv(rows, columns)}
1493
+ `);
1494
+ return;
1495
+ }
1496
+ print(rows, { json: opts.json, columns });
1497
+ return;
1498
+ }
1383
1499
  const body = unwrap(await list({ query }));
1500
+ if (opts.raw) {
1501
+ print(body, { json: true });
1502
+ return;
1503
+ }
1384
1504
  if (opts.csv) {
1385
- process.stdout.write(`${toCsv(body.data, spec.columns)}
1505
+ process.stdout.write(`${toCsv(body.data, columns)}
1386
1506
  `);
1387
1507
  return;
1388
1508
  }
1389
- print(body.data, { json: opts.json, columns: spec.columns });
1509
+ print(body.data, { json: opts.json, columns });
1390
1510
  if (!opts.json) printNextCursor(body.page);
1391
1511
  });
1392
1512
  }
@@ -1446,6 +1566,60 @@ function camel2(s) {
1446
1566
  return s.replace(/-([a-z])/g, (_, c2) => c2.toUpperCase());
1447
1567
  }
1448
1568
 
1569
+ // src/commands/workspace.ts
1570
+ import chalk3 from "chalk";
1571
+ function registerWorkspace(program2) {
1572
+ const root = program2.command("workspace").description("List, switch, and show the active workspace");
1573
+ root.command("list").alias("ls").description("List the workspaces you can access (marks the active one)").option("--json", "raw JSON output").action(async (opts) => {
1574
+ configureClient();
1575
+ const me = unwrap(await getMe({})).data;
1576
+ const activeId = loadConfig().workspaceId ?? me.activeWorkspaceId;
1577
+ const rows = me.workspaces.map((w) => ({
1578
+ active: w.id === activeId ? "*" : "",
1579
+ id: w.id,
1580
+ name: w.name,
1581
+ slug: w.slug
1582
+ }));
1583
+ print(rows, {
1584
+ json: opts.json,
1585
+ columns: ["active", "id", "name", "slug"]
1586
+ });
1587
+ });
1588
+ root.command("use <idOrSlug>").description(
1589
+ "Set the active workspace (persisted in ~/.freeticket/config.json)"
1590
+ ).action(async (idOrSlug) => {
1591
+ configureClient();
1592
+ const me = unwrap(await getMe({})).data;
1593
+ const match = me.workspaces.find(
1594
+ (w) => w.id === idOrSlug || w.slug === idOrSlug
1595
+ );
1596
+ if (!match) {
1597
+ fail(
1598
+ `No workspace matches "${idOrSlug}".`,
1599
+ `Available: ${me.workspaces.map((w) => w.slug).join(", ") || "(none)"}`
1600
+ );
1601
+ }
1602
+ saveConfig({ workspaceId: match.id });
1603
+ console.log(
1604
+ `${chalk3.green("\u2713")} Active workspace: ${chalk3.bold(match.name)} ${chalk3.dim(`(${match.slug})`)}`
1605
+ );
1606
+ });
1607
+ root.command("show").description("Show the active workspace").option("--json", "raw JSON output").action(async (opts) => {
1608
+ configureClient();
1609
+ const cfg = loadConfig();
1610
+ const me = unwrap(await getMe({})).data;
1611
+ const activeId = cfg.workspaceId ?? me.activeWorkspaceId;
1612
+ const active = me.workspaces.find((w) => w.id === activeId);
1613
+ if (!active) {
1614
+ fail(
1615
+ "No active workspace set.",
1616
+ "Pick one with `ft workspace use <slug>`."
1617
+ );
1618
+ }
1619
+ print(active, { json: opts.json });
1620
+ });
1621
+ }
1622
+
1449
1623
  // src/lib/banner.ts
1450
1624
  import { Chalk } from "chalk";
1451
1625
  var YELLOW = "#FFD500";
@@ -1468,6 +1642,7 @@ function banner() {
1468
1642
  var program = new Command();
1469
1643
  program.name("ft").description("Official FreeTicket CLI").version(package_default.version, "-v, --version").addHelpText("beforeAll", banner());
1470
1644
  registerAuth(program);
1645
+ registerWorkspace(program);
1471
1646
  registerResource(program, {
1472
1647
  name: "events",
1473
1648
  describe: "Events",
@@ -1479,7 +1654,8 @@ registerResource(program, {
1479
1654
  actions: [
1480
1655
  { name: "publish", describe: "Publish an event", fn: postEventsIdPublish }
1481
1656
  ],
1482
- columns: ["id", "name", "status", "startsAt"]
1657
+ // startsAt lives on EventDate, not Event — use createdAt for a temporal column.
1658
+ columns: ["id", "name", "status", "createdAt"]
1483
1659
  });
1484
1660
  registerEventDates(program, {
1485
1661
  list: getEventsIdDates,
@@ -1514,7 +1690,7 @@ registerResource(program, {
1514
1690
  create: postTicketTypes,
1515
1691
  update: patchTicketTypesId,
1516
1692
  del: deleteTicketTypesId,
1517
- columns: ["id", "name", "price", "currency", "stock"],
1693
+ columns: ["id", "name", "price", "currency", "capacity"],
1518
1694
  listFlags: [
1519
1695
  {
1520
1696
  flag: "--event-date-id <id>",
@@ -1531,7 +1707,7 @@ registerResource(program, {
1531
1707
  create: postMembershipPlans,
1532
1708
  update: patchMembershipPlansId,
1533
1709
  del: deleteMembershipPlansId,
1534
- columns: ["id", "name", "price", "currency", "interval"]
1710
+ columns: ["id", "name", "price", "currency", "billingCycle"]
1535
1711
  });
1536
1712
  registerResource(program, {
1537
1713
  name: "venues",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freeticket/cli",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Official FreeTicket CLI — consumes the B2B REST API for events, sales, tickets, memberships, venues, staff, and reports.",
5
5
  "keywords": [
6
6
  "freeticket",