@freeticket/cli 0.7.1 → 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 (2) hide show
  1. package/dist/index.js +180 -18
  2. package/package.json +1 -1
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.1",
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",
@@ -205,7 +205,11 @@ var postEventsIdDates = (options) => {
205
205
  }
206
206
  ],
207
207
  url: "/events/{id}/dates",
208
- ...options
208
+ ...options,
209
+ headers: {
210
+ "Content-Type": "application/json",
211
+ ...options?.headers
212
+ }
209
213
  });
210
214
  };
211
215
  var deleteEventsIdDatesDateId = (options) => {
@@ -229,7 +233,11 @@ var patchEventsIdDatesDateId = (options) => {
229
233
  }
230
234
  ],
231
235
  url: "/events/{id}/dates/{dateId}",
232
- ...options
236
+ ...options,
237
+ headers: {
238
+ "Content-Type": "application/json",
239
+ ...options?.headers
240
+ }
233
241
  });
234
242
  };
235
243
  var getTicketTypes = (options) => {
@@ -293,7 +301,11 @@ var patchTicketTypesId = (options) => {
293
301
  }
294
302
  ],
295
303
  url: "/ticket-types/{id}",
296
- ...options
304
+ ...options,
305
+ headers: {
306
+ "Content-Type": "application/json",
307
+ ...options?.headers
308
+ }
297
309
  });
298
310
  };
299
311
  var getSales = (options) => {
@@ -421,7 +433,11 @@ var patchMembershipPlansId = (options) => {
421
433
  }
422
434
  ],
423
435
  url: "/membership-plans/{id}",
424
- ...options
436
+ ...options,
437
+ headers: {
438
+ "Content-Type": "application/json",
439
+ ...options?.headers
440
+ }
425
441
  });
426
442
  };
427
443
  var getVenues = (options) => {
@@ -485,7 +501,11 @@ var patchVenuesId = (options) => {
485
501
  }
486
502
  ],
487
503
  url: "/venues/{id}",
488
- ...options
504
+ ...options,
505
+ headers: {
506
+ "Content-Type": "application/json",
507
+ ...options?.headers
508
+ }
489
509
  });
490
510
  };
491
511
  var getStaff = (options) => {
@@ -796,6 +816,46 @@ var getTicketsTicketCodeAccess = (options) => {
796
816
  ...options
797
817
  });
798
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
+ };
799
859
  var postTicketsTicketCodeResend = (options) => {
800
860
  return (options.client ?? client).post({
801
861
  security: [
@@ -1517,9 +1577,110 @@ function camel(s) {
1517
1577
  return s.replace(/-([a-z])/g, (_, c2) => c2.toUpperCase());
1518
1578
  }
1519
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
+
1520
1681
  // src/commands/auth.ts
1521
1682
  import { spawn } from "child_process";
1522
- import chalk3 from "chalk";
1683
+ import chalk4 from "chalk";
1523
1684
  function registerAuth(program2) {
1524
1685
  program2.command("login").description(
1525
1686
  "Log in via the browser (device flow) and store the session in ~/.freeticket/config.json"
@@ -1540,7 +1701,7 @@ function registerAuth(program2) {
1540
1701
  configureClient(workspaceId);
1541
1702
  const me = unwrap(await getMe({})).data;
1542
1703
  console.log(
1543
- `${chalk3.green("\u2713")} Session saved in ${chalk3.dim(CONFIG_PATH)}`
1704
+ `${chalk4.green("\u2713")} Session saved in ${chalk4.dim(CONFIG_PATH)}`
1544
1705
  );
1545
1706
  print(me, {});
1546
1707
  });
@@ -1552,7 +1713,7 @@ function registerAuth(program2) {
1552
1713
  program2.command("logout").description("Log out and remove the stored session").action(() => {
1553
1714
  saveConfig({ apiKey: void 0 });
1554
1715
  console.log(
1555
- `${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)}`
1556
1717
  );
1557
1718
  });
1558
1719
  program2.command("config").description("Show active configuration (the credential is masked)").action(() => {
@@ -1582,11 +1743,11 @@ async function deviceLogin() {
1582
1743
  const start = unwrap(await postAuthDeviceCode({}));
1583
1744
  console.log(
1584
1745
  `
1585
- Open ${chalk3.cyan(start.verification_uri)} and enter the code:
1746
+ Open ${chalk4.cyan(start.verification_uri)} and enter the code:
1586
1747
 
1587
- ${chalk3.bold(start.user_code)}
1748
+ ${chalk4.bold(start.user_code)}
1588
1749
 
1589
- ${chalk3.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1750
+ ${chalk4.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1590
1751
  `
1591
1752
  );
1592
1753
  openBrowser(start.verification_uri_complete);
@@ -1606,7 +1767,7 @@ ${chalk3.dim("Opening your browser\u2026 (Ctrl+C to cancel)")}
1606
1767
  if (workspaces.length > 1 && active) {
1607
1768
  console.log(
1608
1769
  `
1609
- ${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)`)}`
1610
1771
  );
1611
1772
  }
1612
1773
  return { apiKey: access_token, workspaceId: active?.id };
@@ -1928,7 +2089,7 @@ function registerTickets(program2) {
1928
2089
  }
1929
2090
 
1930
2091
  // src/commands/workspace.ts
1931
- import chalk4 from "chalk";
2092
+ import chalk5 from "chalk";
1932
2093
  function registerWorkspace(program2) {
1933
2094
  const root = program2.command("workspace").description("List, switch, and show the active workspace");
1934
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) => {
@@ -1962,7 +2123,7 @@ function registerWorkspace(program2) {
1962
2123
  }
1963
2124
  saveConfig({ workspaceId: match.id });
1964
2125
  console.log(
1965
- `${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})`)}`
1966
2127
  );
1967
2128
  });
1968
2129
  root.command("show").description("Show the active workspace").option("--json", "raw JSON output").action(async (opts) => {
@@ -2003,7 +2164,7 @@ function banner() {
2003
2164
  import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
2004
2165
  import { homedir as homedir2 } from "os";
2005
2166
  import { dirname as dirname2, join as join2 } from "path";
2006
- import chalk5 from "chalk";
2167
+ import chalk6 from "chalk";
2007
2168
  var CACHE_PATH = join2(homedir2(), ".freeticket", "update-check.json");
2008
2169
  var REGISTRY = "https://registry.npmjs.org/@freeticket/cli/latest";
2009
2170
  var ONE_DAY = 24 * 60 * 60 * 1e3;
@@ -2017,8 +2178,8 @@ async function notifyUpdate(current) {
2017
2178
  if (latest && isNewer(latest, current)) {
2018
2179
  process.stderr.write(
2019
2180
  `
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")}
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")}
2022
2183
 
2023
2184
  `
2024
2185
  );
@@ -2237,6 +2398,7 @@ registerResource(program, {
2237
2398
  });
2238
2399
  registerTickets(program);
2239
2400
  registerReports(program);
2401
+ registerApiKeys(program);
2240
2402
  registerAdmin(program);
2241
2403
  if (process.argv.length <= 2) {
2242
2404
  console.log(banner());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freeticket/cli",
3
- "version": "0.7.1",
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",