@freeticket/cli 0.7.0 → 0.8.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 +7 -0
  2. package/dist/index.js +182 -18
  3. package/package.json +3 -1
package/README.md CHANGED
@@ -161,6 +161,13 @@ pnpm test # vitest
161
161
  pnpm lint # biome
162
162
  ```
163
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
+
164
171
  ### Keeping the client in sync with the backend
165
172
 
166
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.7.0",
9
+ version: "0.8.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",
@@ -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",
@@ -203,7 +205,11 @@ var postEventsIdDates = (options) => {
203
205
  }
204
206
  ],
205
207
  url: "/events/{id}/dates",
206
- ...options
208
+ ...options,
209
+ headers: {
210
+ "Content-Type": "application/json",
211
+ ...options?.headers
212
+ }
207
213
  });
208
214
  };
209
215
  var deleteEventsIdDatesDateId = (options) => {
@@ -227,7 +233,11 @@ var patchEventsIdDatesDateId = (options) => {
227
233
  }
228
234
  ],
229
235
  url: "/events/{id}/dates/{dateId}",
230
- ...options
236
+ ...options,
237
+ headers: {
238
+ "Content-Type": "application/json",
239
+ ...options?.headers
240
+ }
231
241
  });
232
242
  };
233
243
  var getTicketTypes = (options) => {
@@ -291,7 +301,11 @@ var patchTicketTypesId = (options) => {
291
301
  }
292
302
  ],
293
303
  url: "/ticket-types/{id}",
294
- ...options
304
+ ...options,
305
+ headers: {
306
+ "Content-Type": "application/json",
307
+ ...options?.headers
308
+ }
295
309
  });
296
310
  };
297
311
  var getSales = (options) => {
@@ -419,7 +433,11 @@ var patchMembershipPlansId = (options) => {
419
433
  }
420
434
  ],
421
435
  url: "/membership-plans/{id}",
422
- ...options
436
+ ...options,
437
+ headers: {
438
+ "Content-Type": "application/json",
439
+ ...options?.headers
440
+ }
423
441
  });
424
442
  };
425
443
  var getVenues = (options) => {
@@ -483,7 +501,11 @@ var patchVenuesId = (options) => {
483
501
  }
484
502
  ],
485
503
  url: "/venues/{id}",
486
- ...options
504
+ ...options,
505
+ headers: {
506
+ "Content-Type": "application/json",
507
+ ...options?.headers
508
+ }
487
509
  });
488
510
  };
489
511
  var getStaff = (options) => {
@@ -794,6 +816,46 @@ var getTicketsTicketCodeAccess = (options) => {
794
816
  ...options
795
817
  });
796
818
  };
819
+ var getApiKeys = (options) => {
820
+ return (options?.client ?? client).get({
821
+ security: [
822
+ {
823
+ name: "Authorization",
824
+ type: "apiKey"
825
+ }
826
+ ],
827
+ url: "/api-keys",
828
+ ...options
829
+ });
830
+ };
831
+ var postApiKeys = (options) => {
832
+ return (options.client ?? client).post({
833
+ security: [
834
+ {
835
+ name: "Authorization",
836
+ type: "apiKey"
837
+ }
838
+ ],
839
+ url: "/api-keys",
840
+ ...options,
841
+ headers: {
842
+ "Content-Type": "application/json",
843
+ ...options?.headers
844
+ }
845
+ });
846
+ };
847
+ var deleteApiKeysId = (options) => {
848
+ return (options.client ?? client).delete({
849
+ security: [
850
+ {
851
+ name: "Authorization",
852
+ type: "apiKey"
853
+ }
854
+ ],
855
+ url: "/api-keys/{id}",
856
+ ...options
857
+ });
858
+ };
797
859
  var postTicketsTicketCodeResend = (options) => {
798
860
  return (options.client ?? client).post({
799
861
  security: [
@@ -1515,9 +1577,110 @@ function camel(s) {
1515
1577
  return s.replace(/-([a-z])/g, (_, c2) => c2.toUpperCase());
1516
1578
  }
1517
1579
 
1580
+ // src/commands/api-keys.ts
1581
+ import chalk3 from "chalk";
1582
+ var COLUMNS = [
1583
+ "name",
1584
+ "keyPrefix",
1585
+ "scope",
1586
+ "lastUsedAt",
1587
+ "expiresAt",
1588
+ "revokedAt"
1589
+ ];
1590
+ function registerApiKeys(program2) {
1591
+ const root = program2.command("api-keys").description("Self-service API keys: create, list, revoke");
1592
+ root.command("create <name>").description("Mint a new API key (the secret is shown only once)").option("--scope <read|write>", "key scope", "read").option("--expires <iso>", "expiry as ISO 8601 (e.g. 2027-01-01)").option("--workspace <id>", "workspace override").option("--json", "raw JSON output (includes the plaintext secret)").action(async (name, opts) => {
1593
+ const scope = opts.scope;
1594
+ if (scope !== "read" && scope !== "write") {
1595
+ fail("Invalid --scope. Use `read` or `write`.");
1596
+ }
1597
+ configureClient(opts.workspace);
1598
+ const body = unwrap(
1599
+ await postApiKeys({
1600
+ body: {
1601
+ name,
1602
+ scope,
1603
+ ...opts.expires ? { expiresAt: opts.expires } : {}
1604
+ }
1605
+ })
1606
+ );
1607
+ const key = body.data;
1608
+ if (opts.json) {
1609
+ print(key, { json: true });
1610
+ return;
1611
+ }
1612
+ console.log(
1613
+ `
1614
+ ${chalk3.green("\u2713")} API key "${chalk3.bold(key.name)}" created (scope: ${key.scope}).
1615
+ `
1616
+ );
1617
+ console.log(
1618
+ chalk3.yellow(" Copy your secret now \u2014 it will NOT be shown again:\n")
1619
+ );
1620
+ console.log(` ${chalk3.bold.cyan(key.key)}
1621
+ `);
1622
+ print(
1623
+ {
1624
+ id: key.id,
1625
+ name: key.name,
1626
+ scope: key.scope,
1627
+ keyPrefix: key.keyPrefix,
1628
+ expiresAt: key.expiresAt,
1629
+ createdAt: key.createdAt
1630
+ },
1631
+ {}
1632
+ );
1633
+ });
1634
+ root.command("list").description("List your API keys (the secret is never returned)").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)").option("--json", "raw JSON output (data only)").action(async (opts) => {
1635
+ configureClient(opts.workspace);
1636
+ const columns = resolveColumns(opts, COLUMNS);
1637
+ const query = {
1638
+ limit: opts.limit,
1639
+ cursor: opts.cursor
1640
+ };
1641
+ if (opts.all) {
1642
+ const rows = [];
1643
+ let cursor;
1644
+ let page;
1645
+ do {
1646
+ const body2 = unwrap(
1647
+ await getApiKeys({ query: { ...query, cursor } })
1648
+ );
1649
+ rows.push(...body2.data ?? []);
1650
+ page = body2.page;
1651
+ cursor = page?.nextCursor ?? void 0;
1652
+ } while (page?.hasMore && cursor);
1653
+ if (opts.csv) {
1654
+ process.stdout.write(`${toCsv(rows, columns)}
1655
+ `);
1656
+ return;
1657
+ }
1658
+ print(rows, { json: opts.json, columns });
1659
+ return;
1660
+ }
1661
+ const body = unwrap(await getApiKeys({ query }));
1662
+ if (opts.csv) {
1663
+ process.stdout.write(`${toCsv(body.data, columns)}
1664
+ `);
1665
+ return;
1666
+ }
1667
+ print(body.data, { json: opts.json, columns });
1668
+ if (!opts.json) printNextCursor(body.page);
1669
+ });
1670
+ root.command("revoke <id>").description("Revoke one of your API keys").option("--yes", "skip confirmation").option("--workspace <id>", "workspace override").option("--json", "raw JSON output").action(async (id, opts) => {
1671
+ if (!opts.yes && !await confirm(`Revoke API key ${id}?`)) {
1672
+ console.error("Aborted.");
1673
+ return;
1674
+ }
1675
+ configureClient(opts.workspace);
1676
+ const body = unwrap(await deleteApiKeysId({ path: { id } }));
1677
+ print(body?.data ?? { revoked: id }, { json: opts.json });
1678
+ });
1679
+ }
1680
+
1518
1681
  // src/commands/auth.ts
1519
1682
  import { spawn } from "child_process";
1520
- import chalk3 from "chalk";
1683
+ import chalk4 from "chalk";
1521
1684
  function registerAuth(program2) {
1522
1685
  program2.command("login").description(
1523
1686
  "Log in via the browser (device flow) and store the session in ~/.freeticket/config.json"
@@ -1538,7 +1701,7 @@ function registerAuth(program2) {
1538
1701
  configureClient(workspaceId);
1539
1702
  const me = unwrap(await getMe({})).data;
1540
1703
  console.log(
1541
- `${chalk3.green("\u2713")} Session saved in ${chalk3.dim(CONFIG_PATH)}`
1704
+ `${chalk4.green("\u2713")} Session saved in ${chalk4.dim(CONFIG_PATH)}`
1542
1705
  );
1543
1706
  print(me, {});
1544
1707
  });
@@ -1550,7 +1713,7 @@ function registerAuth(program2) {
1550
1713
  program2.command("logout").description("Log out and remove the stored session").action(() => {
1551
1714
  saveConfig({ apiKey: void 0 });
1552
1715
  console.log(
1553
- `${chalk3.green("\u2713")} Logged out \u2014 session removed from ${chalk3.dim(CONFIG_PATH)}`
1716
+ `${chalk4.green("\u2713")} Logged out \u2014 session removed from ${chalk4.dim(CONFIG_PATH)}`
1554
1717
  );
1555
1718
  });
1556
1719
  program2.command("config").description("Show active configuration (the credential is masked)").action(() => {
@@ -1580,11 +1743,11 @@ async function deviceLogin() {
1580
1743
  const start = unwrap(await postAuthDeviceCode({}));
1581
1744
  console.log(
1582
1745
  `
1583
- Open ${chalk3.cyan(start.verification_uri)} and enter the code:
1746
+ Open ${chalk4.cyan(start.verification_uri)} and enter the code:
1584
1747
 
1585
- ${chalk3.bold(start.user_code)}
1748
+ ${chalk4.bold(start.user_code)}
1586
1749
 
1587
- ${chalk3.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1750
+ ${chalk4.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1588
1751
  `
1589
1752
  );
1590
1753
  openBrowser(start.verification_uri_complete);
@@ -1604,7 +1767,7 @@ ${chalk3.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1604
1767
  if (workspaces.length > 1 && active) {
1605
1768
  console.log(
1606
1769
  `
1607
- ${chalk3.dim("Workspaces:")} ${workspaces.map((w) => w.slug).join(", ")} ${chalk3.dim(`(using ${active.slug}; switch with --workspace)`)}`
1770
+ ${chalk4.dim("Workspaces:")} ${workspaces.map((w) => w.slug).join(", ")} ${chalk4.dim(`(using ${active.slug}; switch with --workspace)`)}`
1608
1771
  );
1609
1772
  }
1610
1773
  return { apiKey: access_token, workspaceId: active?.id };
@@ -1926,7 +2089,7 @@ function registerTickets(program2) {
1926
2089
  }
1927
2090
 
1928
2091
  // src/commands/workspace.ts
1929
- import chalk4 from "chalk";
2092
+ import chalk5 from "chalk";
1930
2093
  function registerWorkspace(program2) {
1931
2094
  const root = program2.command("workspace").description("List, switch, and show the active workspace");
1932
2095
  root.command("list").alias("ls").description("List the workspaces you can access (marks the active one)").option("--json", "raw JSON output").action(async (opts) => {
@@ -1960,7 +2123,7 @@ function registerWorkspace(program2) {
1960
2123
  }
1961
2124
  saveConfig({ workspaceId: match.id });
1962
2125
  console.log(
1963
- `${chalk4.green("\u2713")} Active workspace: ${chalk4.bold(match.name)} ${chalk4.dim(`(${match.slug})`)}`
2126
+ `${chalk5.green("\u2713")} Active workspace: ${chalk5.bold(match.name)} ${chalk5.dim(`(${match.slug})`)}`
1964
2127
  );
1965
2128
  });
1966
2129
  root.command("show").description("Show the active workspace").option("--json", "raw JSON output").action(async (opts) => {
@@ -2001,7 +2164,7 @@ function banner() {
2001
2164
  import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
2002
2165
  import { homedir as homedir2 } from "os";
2003
2166
  import { dirname as dirname2, join as join2 } from "path";
2004
- import chalk5 from "chalk";
2167
+ import chalk6 from "chalk";
2005
2168
  var CACHE_PATH = join2(homedir2(), ".freeticket", "update-check.json");
2006
2169
  var REGISTRY = "https://registry.npmjs.org/@freeticket/cli/latest";
2007
2170
  var ONE_DAY = 24 * 60 * 60 * 1e3;
@@ -2015,8 +2178,8 @@ async function notifyUpdate(current) {
2015
2178
  if (latest && isNewer(latest, current)) {
2016
2179
  process.stderr.write(
2017
2180
  `
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")}
2181
+ ${chalk6.yellow(`\u26A0 Update available: @freeticket/cli ${current} \u2192 ${latest}`)}
2182
+ ${chalk6.dim(" npm i -g @freeticket/cli@latest \xB7 or use npx @freeticket/cli@latest")}
2020
2183
 
2021
2184
  `
2022
2185
  );
@@ -2235,6 +2398,7 @@ registerResource(program, {
2235
2398
  });
2236
2399
  registerTickets(program);
2237
2400
  registerReports(program);
2401
+ registerApiKeys(program);
2238
2402
  registerAdmin(program);
2239
2403
  if (process.argv.length <= 2) {
2240
2404
  console.log(banner());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freeticket/cli",
3
- "version": "0.7.0",
3
+ "version": "0.8.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",
@@ -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",