@freeticket/cli 0.4.0 → 0.4.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.
package/README.md CHANGED
@@ -51,17 +51,17 @@ 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
- # 4. Start exploring
64
+ # 3. Start exploring
65
65
  ft events list
66
66
  ft reports summary --period 30d
67
67
  ft sales list --status CONFIRMED --json
@@ -71,7 +71,7 @@ ft sales list --status CONFIRMED --json
71
71
 
72
72
  | Command | What it does | Minimum role |
73
73
  |---|---|---|
74
- | `ft login --key <key>` | Stores and verifies your API key | VIEWER |
74
+ | `ft login` | Browser login (device flow); `--key <key>` for CI | VIEWER |
75
75
  | `ft whoami` | Active user and accessible workspaces | VIEWER |
76
76
  | `ft config` · `ft logout` | Show config (masked key) · remove key | — |
77
77
  | `ft events list` · `get <id>` | Workspace events | VIEWER |
@@ -170,7 +170,7 @@ CLI QA, and release/devops. See the [agents README](./.claude/agents/README.md).
170
170
  ## Requirements
171
171
 
172
172
  - Node.js **>= 20**
173
- - A FreeTicket API key (`ft_live_...`)
173
+ - A FreeTicket account (`ft login` opens the browser; no API key needed)
174
174
 
175
175
  ## License
176
176
 
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.4.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",
@@ -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: [
@@ -1219,21 +1235,26 @@ function camel(s) {
1219
1235
  }
1220
1236
 
1221
1237
  // src/commands/auth.ts
1238
+ import { spawn } from "child_process";
1222
1239
  import chalk2 from "chalk";
1223
1240
  function registerAuth(program2) {
1224
- program2.command("login").description("Store the API key and workspace in ~/.freeticket/config.json").requiredOption(
1241
+ program2.command("login").description(
1242
+ "Log in via the browser (device flow) and store the session in ~/.freeticket/config.json"
1243
+ ).option(
1225
1244
  "--key <ft_live_\u2026>",
1226
- "API key issued in the backend (pnpm api:key)"
1245
+ "Skip the browser and use an API key issued in the backend (CI / automation)"
1227
1246
  ).option(
1228
1247
  "--url <url>",
1229
1248
  "API base URL (default: https://admin.appfreeticket.com)"
1230
1249
  ).option("--workspace <id>", "default active workspace").action(async (opts) => {
1250
+ if (opts.url) saveConfig({ apiUrl: opts.url });
1251
+ const cred = opts.key ? { apiKey: opts.key, workspaceId: void 0 } : await deviceLogin();
1252
+ const workspaceId = opts.workspace ?? cred.workspaceId;
1231
1253
  saveConfig({
1232
- apiKey: opts.key,
1233
- ...opts.url ? { apiUrl: opts.url } : {},
1234
- ...opts.workspace ? { workspaceId: opts.workspace } : {}
1254
+ apiKey: cred.apiKey,
1255
+ ...workspaceId ? { workspaceId } : {}
1235
1256
  });
1236
- configureClient(opts.workspace);
1257
+ configureClient(workspaceId);
1237
1258
  const me = unwrap(await getMe({})).data;
1238
1259
  console.log(
1239
1260
  `${chalk2.green("\u2713")} Session saved in ${chalk2.dim(CONFIG_PATH)}`
@@ -1263,6 +1284,68 @@ function registerAuth(program2) {
1263
1284
  );
1264
1285
  });
1265
1286
  }
1287
+ var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
1288
+ function openBrowser(url) {
1289
+ const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
1290
+ try {
1291
+ spawn(cmd, [url], { stdio: "ignore", detached: true }).unref();
1292
+ } catch {
1293
+ }
1294
+ }
1295
+ async function deviceLogin() {
1296
+ const apiUrl = loadConfig().apiUrl.replace(/\/$/, "");
1297
+ client.setConfig({ baseUrl: `${apiUrl}/api/v1` });
1298
+ const start = unwrap(await postAuthDeviceCode({}));
1299
+ console.log(
1300
+ `
1301
+ Open ${chalk2.cyan(start.verification_uri)} and enter the code:
1302
+
1303
+ ${chalk2.bold(start.user_code)}
1304
+
1305
+ ${chalk2.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1306
+ `
1307
+ );
1308
+ openBrowser(start.verification_uri_complete);
1309
+ const deadline = Date.now() + start.expires_in * 1e3;
1310
+ let interval = start.interval;
1311
+ while (Date.now() < deadline) {
1312
+ await sleep(interval * 1e3);
1313
+ const res = await postAuthDeviceToken({
1314
+ body: {
1315
+ device_code: start.device_code,
1316
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code"
1317
+ }
1318
+ });
1319
+ if (res.data) {
1320
+ const { access_token, workspaces } = res.data;
1321
+ const active = workspaces[0];
1322
+ if (workspaces.length > 1 && active) {
1323
+ console.log(
1324
+ `
1325
+ ${chalk2.dim("Workspaces:")} ${workspaces.map((w) => w.slug).join(", ")} ${chalk2.dim(`(using ${active.slug}; switch with --workspace)`)}`
1326
+ );
1327
+ }
1328
+ return { apiKey: access_token, workspaceId: active?.id };
1329
+ }
1330
+ switch (res.error?.error) {
1331
+ case "authorization_pending":
1332
+ break;
1333
+ // keep polling at the same cadence
1334
+ case "slow_down":
1335
+ interval += 5;
1336
+ break;
1337
+ case "access_denied":
1338
+ fail("Login was denied in the browser.");
1339
+ break;
1340
+ case "expired_token":
1341
+ fail("The code expired before approval. Run `ft login` again.");
1342
+ break;
1343
+ default:
1344
+ fail(`Device login failed: ${res.error?.error ?? "unknown error"}.`);
1345
+ }
1346
+ }
1347
+ return fail("The code expired before approval. Run `ft login` again.");
1348
+ }
1266
1349
 
1267
1350
  // src/commands/event-dates.ts
1268
1351
  function registerEventDates(program2, spec) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freeticket/cli",
3
- "version": "0.4.0",
3
+ "version": "0.4.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",