@freeticket/cli 0.6.0 → 0.7.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 +5 -4
  2. package/dist/index.js +132 -25
  3. package/package.json +1 -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
 
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.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",
@@ -807,6 +807,9 @@ var postTicketsTicketCodeResend = (options) => {
807
807
  });
808
808
  };
809
809
 
810
+ // src/commands/admin.ts
811
+ import chalk2 from "chalk";
812
+
810
813
  // src/admin-client/client.gen.ts
811
814
  import { createClient as createClient2, createConfig as createConfig2 } from "@hey-api/client-fetch";
812
815
  var client2 = createClient2(createConfig2({
@@ -1127,7 +1130,10 @@ function saveConfig(patch) {
1127
1130
  function configureClient(workspaceOverride) {
1128
1131
  const cfg = loadConfig();
1129
1132
  if (!cfg.apiKey) {
1130
- fail("No API key configured. Run `ft login` or export FT_API_KEY.");
1133
+ fail(
1134
+ "Not logged in. Run `ft login` to sign in through your browser.",
1135
+ "CI / headless only: set FT_API_KEY (or `ft login --key`) with a backend-issued token."
1136
+ );
1131
1137
  }
1132
1138
  const workspaceId = workspaceOverride ?? cfg.workspaceId;
1133
1139
  client.setConfig({
@@ -1172,7 +1178,7 @@ function unwrap(res) {
1172
1178
  function hintFor(status) {
1173
1179
  switch (status) {
1174
1180
  case 401:
1175
- return "Invalid, revoked, or expired API key. Run `ft login`.";
1181
+ return "Your session is invalid, revoked, or expired. Run `ft login`.";
1176
1182
  case 403:
1177
1183
  return "Your role or workspace does not allow this action.";
1178
1184
  case 404:
@@ -1251,17 +1257,19 @@ function print(data, opts = {}) {
1251
1257
  process.stdout.write(`${JSON.stringify(data, null, 2)}
1252
1258
  `);
1253
1259
  }
1260
+ function csvEsc(v) {
1261
+ if (v === null || v === void 0) return "";
1262
+ const s = typeof v === "object" ? JSON.stringify(v) : String(v);
1263
+ return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
1264
+ }
1254
1265
  function toCsv(rows, columns) {
1255
- if (!Array.isArray(rows) || rows.length === 0) return "";
1266
+ if (!Array.isArray(rows) || rows.length === 0) {
1267
+ return columns?.length ? columns.map(csvEsc).join(",") : "";
1268
+ }
1256
1269
  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(",");
1270
+ const head = cols.map(csvEsc).join(",");
1263
1271
  const body = rows.map(
1264
- (r) => cols.map((c2) => esc(r[c2])).join(",")
1272
+ (r) => cols.map((c2) => csvEsc(r[c2])).join(",")
1265
1273
  );
1266
1274
  return [head, ...body].join("\n");
1267
1275
  }
@@ -1289,7 +1297,41 @@ function fmt(v) {
1289
1297
 
1290
1298
  // src/commands/admin.ts
1291
1299
  function registerAdmin(program2) {
1292
- const admin = program2.command("admin").description("Superadmin (cross-tenant) \u2014 requires FT_ADMIN_SESSION");
1300
+ const admin = program2.command("admin").description("Superadmin (cross-tenant) \u2014 SUPER_ADMIN session required");
1301
+ admin.command("login").description(
1302
+ "Save a SUPER_ADMIN session and validate it against /api/admin/me"
1303
+ ).requiredOption(
1304
+ "--session <token>",
1305
+ "the `better-auth.session_token` cookie value from an authenticated admin browser session"
1306
+ ).option(
1307
+ "--url <url>",
1308
+ "API base URL (default: https://admin.appfreeticket.com)"
1309
+ ).action(async (opts) => {
1310
+ if (opts.url) saveConfig({ apiUrl: opts.url });
1311
+ saveConfig({ adminSession: opts.session });
1312
+ configureAdminClient();
1313
+ const me = unwrap(await getMe2({})).data;
1314
+ console.log(
1315
+ `${chalk2.green("\u2713")} Admin session saved in ${chalk2.dim(CONFIG_PATH)}`
1316
+ );
1317
+ print(me, {});
1318
+ });
1319
+ admin.command("logout").description("Remove the stored superadmin session").action(() => {
1320
+ saveConfig({ adminSession: void 0 });
1321
+ console.log(
1322
+ `${chalk2.green("\u2713")} Admin session removed from ${chalk2.dim(CONFIG_PATH)}`
1323
+ );
1324
+ });
1325
+ admin.command("config").description("Show admin configuration (the session is masked)").action(() => {
1326
+ const cfg = loadConfig();
1327
+ print(
1328
+ {
1329
+ apiUrl: cfg.apiUrl,
1330
+ adminSession: cfg.adminSession ? `${cfg.adminSession.slice(0, 12)}\u2026` : null
1331
+ },
1332
+ {}
1333
+ );
1334
+ });
1293
1335
  admin.command("me").description("Current superadmin identity (GET /api/admin/me)").option("--json", "raw JSON output").action(async (opts) => {
1294
1336
  configureAdminClient();
1295
1337
  const body = unwrap(await getMe2({}));
@@ -1475,7 +1517,7 @@ function camel(s) {
1475
1517
 
1476
1518
  // src/commands/auth.ts
1477
1519
  import { spawn } from "child_process";
1478
- import chalk2 from "chalk";
1520
+ import chalk3 from "chalk";
1479
1521
  function registerAuth(program2) {
1480
1522
  program2.command("login").description(
1481
1523
  "Log in via the browser (device flow) and store the session in ~/.freeticket/config.json"
@@ -1496,7 +1538,7 @@ function registerAuth(program2) {
1496
1538
  configureClient(workspaceId);
1497
1539
  const me = unwrap(await getMe({})).data;
1498
1540
  console.log(
1499
- `${chalk2.green("\u2713")} Session saved in ${chalk2.dim(CONFIG_PATH)}`
1541
+ `${chalk3.green("\u2713")} Session saved in ${chalk3.dim(CONFIG_PATH)}`
1500
1542
  );
1501
1543
  print(me, {});
1502
1544
  });
@@ -1505,18 +1547,19 @@ function registerAuth(program2) {
1505
1547
  const me = unwrap(await getMe({})).data;
1506
1548
  print(me, { json: opts.json });
1507
1549
  });
1508
- program2.command("logout").description("Remove the stored API key").action(() => {
1550
+ program2.command("logout").description("Log out and remove the stored session").action(() => {
1509
1551
  saveConfig({ apiKey: void 0 });
1510
1552
  console.log(
1511
- `${chalk2.green("\u2713")} API key removed from ${chalk2.dim(CONFIG_PATH)}`
1553
+ `${chalk3.green("\u2713")} Logged out \u2014 session removed from ${chalk3.dim(CONFIG_PATH)}`
1512
1554
  );
1513
1555
  });
1514
- program2.command("config").description("Show active configuration (the API key is masked)").action(() => {
1556
+ program2.command("config").description("Show active configuration (the credential is masked)").action(() => {
1515
1557
  const cfg = loadConfig();
1516
1558
  print(
1517
1559
  {
1518
1560
  apiUrl: cfg.apiUrl,
1519
- apiKey: cfg.apiKey ? `${cfg.apiKey.slice(0, 12)}\u2026` : null,
1561
+ // Same field whether it's a device-flow session or a CI API key.
1562
+ session: cfg.apiKey ? `${cfg.apiKey.slice(0, 12)}\u2026` : null,
1520
1563
  workspaceId: cfg.workspaceId ?? null
1521
1564
  },
1522
1565
  {}
@@ -1537,11 +1580,11 @@ async function deviceLogin() {
1537
1580
  const start = unwrap(await postAuthDeviceCode({}));
1538
1581
  console.log(
1539
1582
  `
1540
- Open ${chalk2.cyan(start.verification_uri)} and enter the code:
1583
+ Open ${chalk3.cyan(start.verification_uri)} and enter the code:
1541
1584
 
1542
- ${chalk2.bold(start.user_code)}
1585
+ ${chalk3.bold(start.user_code)}
1543
1586
 
1544
- ${chalk2.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1587
+ ${chalk3.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1545
1588
  `
1546
1589
  );
1547
1590
  openBrowser(start.verification_uri_complete);
@@ -1561,7 +1604,7 @@ ${chalk2.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1561
1604
  if (workspaces.length > 1 && active) {
1562
1605
  console.log(
1563
1606
  `
1564
- ${chalk2.dim("Workspaces:")} ${workspaces.map((w) => w.slug).join(", ")} ${chalk2.dim(`(using ${active.slug}; switch with --workspace)`)}`
1607
+ ${chalk3.dim("Workspaces:")} ${workspaces.map((w) => w.slug).join(", ")} ${chalk3.dim(`(using ${active.slug}; switch with --workspace)`)}`
1565
1608
  );
1566
1609
  }
1567
1610
  return { apiKey: access_token, workspaceId: active?.id };
@@ -1883,7 +1926,7 @@ function registerTickets(program2) {
1883
1926
  }
1884
1927
 
1885
1928
  // src/commands/workspace.ts
1886
- import chalk3 from "chalk";
1929
+ import chalk4 from "chalk";
1887
1930
  function registerWorkspace(program2) {
1888
1931
  const root = program2.command("workspace").description("List, switch, and show the active workspace");
1889
1932
  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 +1960,7 @@ function registerWorkspace(program2) {
1917
1960
  }
1918
1961
  saveConfig({ workspaceId: match.id });
1919
1962
  console.log(
1920
- `${chalk3.green("\u2713")} Active workspace: ${chalk3.bold(match.name)} ${chalk3.dim(`(${match.slug})`)}`
1963
+ `${chalk4.green("\u2713")} Active workspace: ${chalk4.bold(match.name)} ${chalk4.dim(`(${match.slug})`)}`
1921
1964
  );
1922
1965
  });
1923
1966
  root.command("show").description("Show the active workspace").option("--json", "raw JSON output").action(async (opts) => {
@@ -1954,6 +1997,70 @@ function banner() {
1954
1997
  ].join("\n");
1955
1998
  }
1956
1999
 
2000
+ // src/lib/update-check.ts
2001
+ import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
2002
+ import { homedir as homedir2 } from "os";
2003
+ import { dirname as dirname2, join as join2 } from "path";
2004
+ import chalk5 from "chalk";
2005
+ var CACHE_PATH = join2(homedir2(), ".freeticket", "update-check.json");
2006
+ var REGISTRY = "https://registry.npmjs.org/@freeticket/cli/latest";
2007
+ var ONE_DAY = 24 * 60 * 60 * 1e3;
2008
+ var FETCH_TIMEOUT = 1500;
2009
+ async function notifyUpdate(current) {
2010
+ if (!process.stderr.isTTY || process.env.FT_NO_UPDATE_CHECK || process.env.CI) {
2011
+ return;
2012
+ }
2013
+ try {
2014
+ const latest = await getLatest();
2015
+ if (latest && isNewer(latest, current)) {
2016
+ process.stderr.write(
2017
+ `
2018
+ ${chalk5.yellow(`\u26A0 Update available: @freeticket/cli ${current} \u2192 ${latest}`)}
2019
+ ${chalk5.dim(" npm i -g @freeticket/cli@latest \xB7 or use npx @freeticket/cli@latest")}
2020
+
2021
+ `
2022
+ );
2023
+ }
2024
+ } catch {
2025
+ }
2026
+ }
2027
+ async function getLatest() {
2028
+ const cached = readCache();
2029
+ if (cached && Date.now() - cached.at < ONE_DAY) return cached.latest;
2030
+ const res = await fetch(REGISTRY, {
2031
+ signal: AbortSignal.timeout(FETCH_TIMEOUT),
2032
+ headers: { Accept: "application/vnd.npm.install-v1+json" }
2033
+ });
2034
+ if (!res.ok) throw new Error(`registry ${res.status}`);
2035
+ const latest = (await res.json()).version ?? null;
2036
+ if (latest) writeCache({ at: Date.now(), latest });
2037
+ return latest;
2038
+ }
2039
+ function readCache() {
2040
+ if (!existsSync2(CACHE_PATH)) return null;
2041
+ try {
2042
+ return JSON.parse(readFileSync3(CACHE_PATH, "utf8"));
2043
+ } catch {
2044
+ return null;
2045
+ }
2046
+ }
2047
+ function writeCache(v) {
2048
+ try {
2049
+ mkdirSync2(dirname2(CACHE_PATH), { recursive: true });
2050
+ writeFileSync2(CACHE_PATH, JSON.stringify(v));
2051
+ } catch {
2052
+ }
2053
+ }
2054
+ function isNewer(a, b) {
2055
+ const parse = (v) => {
2056
+ const [maj, min, pat] = (v.replace(/^v/, "").split("-")[0] ?? "").split(".").map((n) => Number.parseInt(n, 10) || 0);
2057
+ return [maj ?? 0, min ?? 0, pat ?? 0];
2058
+ };
2059
+ const [aM, aN, aP] = parse(a);
2060
+ const [bM, bN, bP] = parse(b);
2061
+ return aM > bM || aM === bM && (aN > bN || aN === bN && aP > bP);
2062
+ }
2063
+
1957
2064
  // src/index.ts
1958
2065
  var program = new Command();
1959
2066
  program.name("ft").description("Official FreeTicket CLI").version(package_default.version, "-v, --version").addHelpText("beforeAll", banner());
@@ -2134,7 +2241,7 @@ if (process.argv.length <= 2) {
2134
2241
  program.outputHelp();
2135
2242
  process.exit(0);
2136
2243
  }
2137
- program.parseAsync().catch((err) => {
2244
+ program.parseAsync().then(() => notifyUpdate(package_default.version)).catch((err) => {
2138
2245
  console.error(err instanceof Error ? err.message : err);
2139
2246
  process.exit(1);
2140
2247
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freeticket/cli",
3
- "version": "0.6.0",
3
+ "version": "0.7.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",