@freeticket/cli 0.4.1 → 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.
- package/README.md +26 -6
- package/dist/index.js +101 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,7 +61,11 @@ ft login
|
|
|
61
61
|
# 2. Who am I, and which workspaces can I access?
|
|
62
62
|
ft whoami
|
|
63
63
|
|
|
64
|
-
# 3.
|
|
64
|
+
# 3. Pick the workspace you want to operate on (persisted locally).
|
|
65
|
+
ft workspace list
|
|
66
|
+
ft workspace use my-workspace-slug
|
|
67
|
+
|
|
68
|
+
# 4. Start exploring
|
|
65
69
|
ft events list
|
|
66
70
|
ft reports summary --period 30d
|
|
67
71
|
ft sales list --status CONFIRMED --json
|
|
@@ -74,17 +78,26 @@ ft sales list --status CONFIRMED --json
|
|
|
74
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
|
|
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
|
|
87
|
-
>
|
|
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
|
|
117
|
-
`--cursor <id>` hint to *stderr* so `--json` stays clean on
|
|
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`).
|
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.
|
|
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",
|
|
@@ -946,7 +946,7 @@ function hintFor(status) {
|
|
|
946
946
|
case 404:
|
|
947
947
|
return "The resource does not exist or belongs to another workspace.";
|
|
948
948
|
case 501:
|
|
949
|
-
return "
|
|
949
|
+
return "The backend has not implemented this operation yet.";
|
|
950
950
|
}
|
|
951
951
|
}
|
|
952
952
|
function fail(message, hint) {
|
|
@@ -1033,6 +1033,13 @@ function toCsv(rows, columns) {
|
|
|
1033
1033
|
);
|
|
1034
1034
|
return [head, ...body].join("\n");
|
|
1035
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
|
+
}
|
|
1036
1043
|
function printNextCursor(page) {
|
|
1037
1044
|
if (page?.nextCursor) {
|
|
1038
1045
|
console.error(chalk.dim(`
|
|
@@ -1451,10 +1458,11 @@ function registerResource(program2, spec) {
|
|
|
1451
1458
|
const singular = spec.name.replace(/s$/, "");
|
|
1452
1459
|
if (spec.list) {
|
|
1453
1460
|
const list = spec.list;
|
|
1454
|
-
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)");
|
|
1455
1462
|
for (const f of spec.listFlags ?? []) cmd.option(f.flag, f.describe);
|
|
1456
1463
|
cmd.action(async (opts) => {
|
|
1457
1464
|
configureClient(opts.workspace);
|
|
1465
|
+
const columns = resolveColumns(opts, spec.columns);
|
|
1458
1466
|
const query = {
|
|
1459
1467
|
limit: Number(opts.limit),
|
|
1460
1468
|
cursor: opts.cursor
|
|
@@ -1463,13 +1471,42 @@ function registerResource(program2, spec) {
|
|
|
1463
1471
|
const v = opts[camel2(f.query)];
|
|
1464
1472
|
if (v !== void 0) query[f.query] = v;
|
|
1465
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
|
+
}
|
|
1466
1499
|
const body = unwrap(await list({ query }));
|
|
1500
|
+
if (opts.raw) {
|
|
1501
|
+
print(body, { json: true });
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1467
1504
|
if (opts.csv) {
|
|
1468
|
-
process.stdout.write(`${toCsv(body.data,
|
|
1505
|
+
process.stdout.write(`${toCsv(body.data, columns)}
|
|
1469
1506
|
`);
|
|
1470
1507
|
return;
|
|
1471
1508
|
}
|
|
1472
|
-
print(body.data, { json: opts.json, columns
|
|
1509
|
+
print(body.data, { json: opts.json, columns });
|
|
1473
1510
|
if (!opts.json) printNextCursor(body.page);
|
|
1474
1511
|
});
|
|
1475
1512
|
}
|
|
@@ -1529,6 +1566,60 @@ function camel2(s) {
|
|
|
1529
1566
|
return s.replace(/-([a-z])/g, (_, c2) => c2.toUpperCase());
|
|
1530
1567
|
}
|
|
1531
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
|
+
|
|
1532
1623
|
// src/lib/banner.ts
|
|
1533
1624
|
import { Chalk } from "chalk";
|
|
1534
1625
|
var YELLOW = "#FFD500";
|
|
@@ -1551,6 +1642,7 @@ function banner() {
|
|
|
1551
1642
|
var program = new Command();
|
|
1552
1643
|
program.name("ft").description("Official FreeTicket CLI").version(package_default.version, "-v, --version").addHelpText("beforeAll", banner());
|
|
1553
1644
|
registerAuth(program);
|
|
1645
|
+
registerWorkspace(program);
|
|
1554
1646
|
registerResource(program, {
|
|
1555
1647
|
name: "events",
|
|
1556
1648
|
describe: "Events",
|
|
@@ -1562,7 +1654,8 @@ registerResource(program, {
|
|
|
1562
1654
|
actions: [
|
|
1563
1655
|
{ name: "publish", describe: "Publish an event", fn: postEventsIdPublish }
|
|
1564
1656
|
],
|
|
1565
|
-
|
|
1657
|
+
// startsAt lives on EventDate, not Event — use createdAt for a temporal column.
|
|
1658
|
+
columns: ["id", "name", "status", "createdAt"]
|
|
1566
1659
|
});
|
|
1567
1660
|
registerEventDates(program, {
|
|
1568
1661
|
list: getEventsIdDates,
|
|
@@ -1597,7 +1690,7 @@ registerResource(program, {
|
|
|
1597
1690
|
create: postTicketTypes,
|
|
1598
1691
|
update: patchTicketTypesId,
|
|
1599
1692
|
del: deleteTicketTypesId,
|
|
1600
|
-
columns: ["id", "name", "price", "currency", "
|
|
1693
|
+
columns: ["id", "name", "price", "currency", "capacity"],
|
|
1601
1694
|
listFlags: [
|
|
1602
1695
|
{
|
|
1603
1696
|
flag: "--event-date-id <id>",
|
|
@@ -1614,7 +1707,7 @@ registerResource(program, {
|
|
|
1614
1707
|
create: postMembershipPlans,
|
|
1615
1708
|
update: patchMembershipPlansId,
|
|
1616
1709
|
del: deleteMembershipPlansId,
|
|
1617
|
-
columns: ["id", "name", "price", "currency", "
|
|
1710
|
+
columns: ["id", "name", "price", "currency", "billingCycle"]
|
|
1618
1711
|
});
|
|
1619
1712
|
registerResource(program, {
|
|
1620
1713
|
name: "venues",
|
package/package.json
CHANGED