@freeticket/cli 0.6.0 → 0.7.1

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 +12 -4
  2. package/dist/index.js +134 -25
  3. package/package.json +3 -1
package/README.md CHANGED
@@ -113,11 +113,11 @@ ft sales list --status CONFIRMED --json
113
113
 
114
114
  | Flag | Applies to | Description |
115
115
  |---|---|---|
116
- | `--json` | all commands | Raw JSON output, ideal for `jq` and scripts |
116
+ | `--json` | all commands | Raw JSON, ideal for `jq`/scripts. On **lists this is the data array only** — use `--raw` for the paginated envelope |
117
117
  | `--workspace <id>` | all commands | Run the command against another workspace |
118
118
  | `--limit <n>` `--cursor <id>` | list commands | Cursor pagination (1-100, default 20) |
119
119
  | `--all` | list commands | Auto-paginate: fetch every page (ignores `--cursor`) |
120
- | `--raw` | list commands | JSON output including the `page` pagination metadata |
120
+ | `--raw` | list commands | JSON `{ data, page }` envelope, including `page.nextCursor` for scripted pagination |
121
121
  | `--columns <a,b,c>` `--full` | list commands | Pick specific columns · show every field |
122
122
  | `--csv` | list commands | CSV output for spreadsheets/accounting |
123
123
  | `--data <json>` `--yes` | write commands | JSON body (inline or `@file`) · skip delete confirmation |
@@ -133,11 +133,12 @@ flags > environment variables > ~/.freeticket/config.json > defaults
133
133
  | Variable | Default | Description |
134
134
  |---|---|---|
135
135
  | `FT_API_URL` | `https://admin.appfreeticket.com` | API base URL (without `/api/v1`) |
136
- | `FT_API_KEY` | — | Your `ft_live_...` key |
136
+ | `FT_API_KEY` | — | CI/headless only — a backend-issued `ft_live_...` token. Browser login (`ft login`) needs no key |
137
137
  | `FT_WORKSPACE_ID` | *home* | Default active workspace |
138
+ | `FT_NO_UPDATE_CHECK` | — | Set to disable the "update available" notice |
138
139
 
139
140
  The `~/.freeticket/config.json` file is created with `0600` permissions (only
140
- your user can read it) because it stores the API key. See [`.env.example`](./.env.example).
141
+ your user can read it) because it stores your credentials. See [`.env.example`](./.env.example).
141
142
 
142
143
  ## Pagination, errors, and money
143
144
 
@@ -160,6 +161,13 @@ pnpm test # vitest
160
161
  pnpm lint # biome
161
162
  ```
162
163
 
164
+ ### Releases
165
+
166
+ Use `pnpm changeset` for every user-facing CLI change and commit the generated
167
+ file in `.changeset/`. Once the change is merged to `main`, GitHub publishes the
168
+ new package version to npm automatically with provenance. The version and
169
+ changelog update are committed to `main`; no npm token or manual tag is required.
170
+
163
171
  ### Keeping the client in sync with the backend
164
172
 
165
173
  The contract is committed in [`openapi.json`](./openapi.json). When the backend
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.6.0",
9
+ version: "0.7.1",
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",
@@ -48,6 +48,7 @@ var package_default = {
48
48
  test: "vitest run",
49
49
  "test:watch": "vitest",
50
50
  typecheck: "tsc --noEmit",
51
+ changeset: "changeset",
51
52
  prepublishOnly: "pnpm build"
52
53
  },
53
54
  dependencies: {
@@ -58,6 +59,7 @@ var package_default = {
58
59
  },
59
60
  devDependencies: {
60
61
  "@biomejs/biome": "^2.2.0",
62
+ "@changesets/cli": "^2.31.0",
61
63
  "@hey-api/openapi-ts": "^0.64.0",
62
64
  "@types/node": "^22.10.0",
63
65
  tsup: "^8.4.0",
@@ -807,6 +809,9 @@ var postTicketsTicketCodeResend = (options) => {
807
809
  });
808
810
  };
809
811
 
812
+ // src/commands/admin.ts
813
+ import chalk2 from "chalk";
814
+
810
815
  // src/admin-client/client.gen.ts
811
816
  import { createClient as createClient2, createConfig as createConfig2 } from "@hey-api/client-fetch";
812
817
  var client2 = createClient2(createConfig2({
@@ -1127,7 +1132,10 @@ function saveConfig(patch) {
1127
1132
  function configureClient(workspaceOverride) {
1128
1133
  const cfg = loadConfig();
1129
1134
  if (!cfg.apiKey) {
1130
- fail("No API key configured. Run `ft login` or export FT_API_KEY.");
1135
+ fail(
1136
+ "Not logged in. Run `ft login` to sign in through your browser.",
1137
+ "CI / headless only: set FT_API_KEY (or `ft login --key`) with a backend-issued token."
1138
+ );
1131
1139
  }
1132
1140
  const workspaceId = workspaceOverride ?? cfg.workspaceId;
1133
1141
  client.setConfig({
@@ -1172,7 +1180,7 @@ function unwrap(res) {
1172
1180
  function hintFor(status) {
1173
1181
  switch (status) {
1174
1182
  case 401:
1175
- return "Invalid, revoked, or expired API key. Run `ft login`.";
1183
+ return "Your session is invalid, revoked, or expired. Run `ft login`.";
1176
1184
  case 403:
1177
1185
  return "Your role or workspace does not allow this action.";
1178
1186
  case 404:
@@ -1251,17 +1259,19 @@ function print(data, opts = {}) {
1251
1259
  process.stdout.write(`${JSON.stringify(data, null, 2)}
1252
1260
  `);
1253
1261
  }
1262
+ function csvEsc(v) {
1263
+ if (v === null || v === void 0) return "";
1264
+ const s = typeof v === "object" ? JSON.stringify(v) : String(v);
1265
+ return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
1266
+ }
1254
1267
  function toCsv(rows, columns) {
1255
- if (!Array.isArray(rows) || rows.length === 0) return "";
1268
+ if (!Array.isArray(rows) || rows.length === 0) {
1269
+ return columns?.length ? columns.map(csvEsc).join(",") : "";
1270
+ }
1256
1271
  const cols = columns ?? Object.keys(rows[0]);
1257
- const esc = (v) => {
1258
- if (v === null || v === void 0) return "";
1259
- const s = typeof v === "object" ? JSON.stringify(v) : String(v);
1260
- return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
1261
- };
1262
- const head = cols.map(esc).join(",");
1272
+ const head = cols.map(csvEsc).join(",");
1263
1273
  const body = rows.map(
1264
- (r) => cols.map((c2) => esc(r[c2])).join(",")
1274
+ (r) => cols.map((c2) => csvEsc(r[c2])).join(",")
1265
1275
  );
1266
1276
  return [head, ...body].join("\n");
1267
1277
  }
@@ -1289,7 +1299,41 @@ function fmt(v) {
1289
1299
 
1290
1300
  // src/commands/admin.ts
1291
1301
  function registerAdmin(program2) {
1292
- const admin = program2.command("admin").description("Superadmin (cross-tenant) \u2014 requires FT_ADMIN_SESSION");
1302
+ const admin = program2.command("admin").description("Superadmin (cross-tenant) \u2014 SUPER_ADMIN session required");
1303
+ admin.command("login").description(
1304
+ "Save a SUPER_ADMIN session and validate it against /api/admin/me"
1305
+ ).requiredOption(
1306
+ "--session <token>",
1307
+ "the `better-auth.session_token` cookie value from an authenticated admin browser session"
1308
+ ).option(
1309
+ "--url <url>",
1310
+ "API base URL (default: https://admin.appfreeticket.com)"
1311
+ ).action(async (opts) => {
1312
+ if (opts.url) saveConfig({ apiUrl: opts.url });
1313
+ saveConfig({ adminSession: opts.session });
1314
+ configureAdminClient();
1315
+ const me = unwrap(await getMe2({})).data;
1316
+ console.log(
1317
+ `${chalk2.green("\u2713")} Admin session saved in ${chalk2.dim(CONFIG_PATH)}`
1318
+ );
1319
+ print(me, {});
1320
+ });
1321
+ admin.command("logout").description("Remove the stored superadmin session").action(() => {
1322
+ saveConfig({ adminSession: void 0 });
1323
+ console.log(
1324
+ `${chalk2.green("\u2713")} Admin session removed from ${chalk2.dim(CONFIG_PATH)}`
1325
+ );
1326
+ });
1327
+ admin.command("config").description("Show admin configuration (the session is masked)").action(() => {
1328
+ const cfg = loadConfig();
1329
+ print(
1330
+ {
1331
+ apiUrl: cfg.apiUrl,
1332
+ adminSession: cfg.adminSession ? `${cfg.adminSession.slice(0, 12)}\u2026` : null
1333
+ },
1334
+ {}
1335
+ );
1336
+ });
1293
1337
  admin.command("me").description("Current superadmin identity (GET /api/admin/me)").option("--json", "raw JSON output").action(async (opts) => {
1294
1338
  configureAdminClient();
1295
1339
  const body = unwrap(await getMe2({}));
@@ -1475,7 +1519,7 @@ function camel(s) {
1475
1519
 
1476
1520
  // src/commands/auth.ts
1477
1521
  import { spawn } from "child_process";
1478
- import chalk2 from "chalk";
1522
+ import chalk3 from "chalk";
1479
1523
  function registerAuth(program2) {
1480
1524
  program2.command("login").description(
1481
1525
  "Log in via the browser (device flow) and store the session in ~/.freeticket/config.json"
@@ -1496,7 +1540,7 @@ function registerAuth(program2) {
1496
1540
  configureClient(workspaceId);
1497
1541
  const me = unwrap(await getMe({})).data;
1498
1542
  console.log(
1499
- `${chalk2.green("\u2713")} Session saved in ${chalk2.dim(CONFIG_PATH)}`
1543
+ `${chalk3.green("\u2713")} Session saved in ${chalk3.dim(CONFIG_PATH)}`
1500
1544
  );
1501
1545
  print(me, {});
1502
1546
  });
@@ -1505,18 +1549,19 @@ function registerAuth(program2) {
1505
1549
  const me = unwrap(await getMe({})).data;
1506
1550
  print(me, { json: opts.json });
1507
1551
  });
1508
- program2.command("logout").description("Remove the stored API key").action(() => {
1552
+ program2.command("logout").description("Log out and remove the stored session").action(() => {
1509
1553
  saveConfig({ apiKey: void 0 });
1510
1554
  console.log(
1511
- `${chalk2.green("\u2713")} API key removed from ${chalk2.dim(CONFIG_PATH)}`
1555
+ `${chalk3.green("\u2713")} Logged out \u2014 session removed from ${chalk3.dim(CONFIG_PATH)}`
1512
1556
  );
1513
1557
  });
1514
- program2.command("config").description("Show active configuration (the API key is masked)").action(() => {
1558
+ program2.command("config").description("Show active configuration (the credential is masked)").action(() => {
1515
1559
  const cfg = loadConfig();
1516
1560
  print(
1517
1561
  {
1518
1562
  apiUrl: cfg.apiUrl,
1519
- apiKey: cfg.apiKey ? `${cfg.apiKey.slice(0, 12)}\u2026` : null,
1563
+ // Same field whether it's a device-flow session or a CI API key.
1564
+ session: cfg.apiKey ? `${cfg.apiKey.slice(0, 12)}\u2026` : null,
1520
1565
  workspaceId: cfg.workspaceId ?? null
1521
1566
  },
1522
1567
  {}
@@ -1537,11 +1582,11 @@ async function deviceLogin() {
1537
1582
  const start = unwrap(await postAuthDeviceCode({}));
1538
1583
  console.log(
1539
1584
  `
1540
- Open ${chalk2.cyan(start.verification_uri)} and enter the code:
1585
+ Open ${chalk3.cyan(start.verification_uri)} and enter the code:
1541
1586
 
1542
- ${chalk2.bold(start.user_code)}
1587
+ ${chalk3.bold(start.user_code)}
1543
1588
 
1544
- ${chalk2.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1589
+ ${chalk3.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1545
1590
  `
1546
1591
  );
1547
1592
  openBrowser(start.verification_uri_complete);
@@ -1561,7 +1606,7 @@ ${chalk2.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1561
1606
  if (workspaces.length > 1 && active) {
1562
1607
  console.log(
1563
1608
  `
1564
- ${chalk2.dim("Workspaces:")} ${workspaces.map((w) => w.slug).join(", ")} ${chalk2.dim(`(using ${active.slug}; switch with --workspace)`)}`
1609
+ ${chalk3.dim("Workspaces:")} ${workspaces.map((w) => w.slug).join(", ")} ${chalk3.dim(`(using ${active.slug}; switch with --workspace)`)}`
1565
1610
  );
1566
1611
  }
1567
1612
  return { apiKey: access_token, workspaceId: active?.id };
@@ -1883,7 +1928,7 @@ function registerTickets(program2) {
1883
1928
  }
1884
1929
 
1885
1930
  // src/commands/workspace.ts
1886
- import chalk3 from "chalk";
1931
+ import chalk4 from "chalk";
1887
1932
  function registerWorkspace(program2) {
1888
1933
  const root = program2.command("workspace").description("List, switch, and show the active workspace");
1889
1934
  root.command("list").alias("ls").description("List the workspaces you can access (marks the active one)").option("--json", "raw JSON output").action(async (opts) => {
@@ -1917,7 +1962,7 @@ function registerWorkspace(program2) {
1917
1962
  }
1918
1963
  saveConfig({ workspaceId: match.id });
1919
1964
  console.log(
1920
- `${chalk3.green("\u2713")} Active workspace: ${chalk3.bold(match.name)} ${chalk3.dim(`(${match.slug})`)}`
1965
+ `${chalk4.green("\u2713")} Active workspace: ${chalk4.bold(match.name)} ${chalk4.dim(`(${match.slug})`)}`
1921
1966
  );
1922
1967
  });
1923
1968
  root.command("show").description("Show the active workspace").option("--json", "raw JSON output").action(async (opts) => {
@@ -1954,6 +1999,70 @@ function banner() {
1954
1999
  ].join("\n");
1955
2000
  }
1956
2001
 
2002
+ // src/lib/update-check.ts
2003
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
2004
+ import { homedir as homedir2 } from "os";
2005
+ import { dirname as dirname2, join as join2 } from "path";
2006
+ import chalk5 from "chalk";
2007
+ var CACHE_PATH = join2(homedir2(), ".freeticket", "update-check.json");
2008
+ var REGISTRY = "https://registry.npmjs.org/@freeticket/cli/latest";
2009
+ var ONE_DAY = 24 * 60 * 60 * 1e3;
2010
+ var FETCH_TIMEOUT = 1500;
2011
+ async function notifyUpdate(current) {
2012
+ if (!process.stderr.isTTY || process.env.FT_NO_UPDATE_CHECK || process.env.CI) {
2013
+ return;
2014
+ }
2015
+ try {
2016
+ const latest = await getLatest();
2017
+ if (latest && isNewer(latest, current)) {
2018
+ process.stderr.write(
2019
+ `
2020
+ ${chalk5.yellow(`\u26A0 Update available: @freeticket/cli ${current} \u2192 ${latest}`)}
2021
+ ${chalk5.dim(" npm i -g @freeticket/cli@latest \xB7 or use npx @freeticket/cli@latest")}
2022
+
2023
+ `
2024
+ );
2025
+ }
2026
+ } catch {
2027
+ }
2028
+ }
2029
+ async function getLatest() {
2030
+ const cached = readCache();
2031
+ if (cached && Date.now() - cached.at < ONE_DAY) return cached.latest;
2032
+ const res = await fetch(REGISTRY, {
2033
+ signal: AbortSignal.timeout(FETCH_TIMEOUT),
2034
+ headers: { Accept: "application/vnd.npm.install-v1+json" }
2035
+ });
2036
+ if (!res.ok) throw new Error(`registry ${res.status}`);
2037
+ const latest = (await res.json()).version ?? null;
2038
+ if (latest) writeCache({ at: Date.now(), latest });
2039
+ return latest;
2040
+ }
2041
+ function readCache() {
2042
+ if (!existsSync2(CACHE_PATH)) return null;
2043
+ try {
2044
+ return JSON.parse(readFileSync3(CACHE_PATH, "utf8"));
2045
+ } catch {
2046
+ return null;
2047
+ }
2048
+ }
2049
+ function writeCache(v) {
2050
+ try {
2051
+ mkdirSync2(dirname2(CACHE_PATH), { recursive: true });
2052
+ writeFileSync2(CACHE_PATH, JSON.stringify(v));
2053
+ } catch {
2054
+ }
2055
+ }
2056
+ function isNewer(a, b) {
2057
+ const parse = (v) => {
2058
+ const [maj, min, pat] = (v.replace(/^v/, "").split("-")[0] ?? "").split(".").map((n) => Number.parseInt(n, 10) || 0);
2059
+ return [maj ?? 0, min ?? 0, pat ?? 0];
2060
+ };
2061
+ const [aM, aN, aP] = parse(a);
2062
+ const [bM, bN, bP] = parse(b);
2063
+ return aM > bM || aM === bM && (aN > bN || aN === bN && aP > bP);
2064
+ }
2065
+
1957
2066
  // src/index.ts
1958
2067
  var program = new Command();
1959
2068
  program.name("ft").description("Official FreeTicket CLI").version(package_default.version, "-v, --version").addHelpText("beforeAll", banner());
@@ -2134,7 +2243,7 @@ if (process.argv.length <= 2) {
2134
2243
  program.outputHelp();
2135
2244
  process.exit(0);
2136
2245
  }
2137
- program.parseAsync().catch((err) => {
2246
+ program.parseAsync().then(() => notifyUpdate(package_default.version)).catch((err) => {
2138
2247
  console.error(err instanceof Error ? err.message : err);
2139
2248
  process.exit(1);
2140
2249
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freeticket/cli",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
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",
@@ -42,6 +42,7 @@
42
42
  "test": "vitest run",
43
43
  "test:watch": "vitest",
44
44
  "typecheck": "tsc --noEmit",
45
+ "changeset": "changeset",
45
46
  "prepublishOnly": "pnpm build"
46
47
  },
47
48
  "dependencies": {
@@ -52,6 +53,7 @@
52
53
  },
53
54
  "devDependencies": {
54
55
  "@biomejs/biome": "^2.2.0",
56
+ "@changesets/cli": "^2.31.0",
55
57
  "@hey-api/openapi-ts": "^0.64.0",
56
58
  "@types/node": "^22.10.0",
57
59
  "tsup": "^8.4.0",