@withone/cli 2.1.0 → 2.2.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 +19 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1476,6 +1476,7 @@ var PORT_RANGE_START = 49152;
1476
1476
  var PORT_RANGE_END = 65535;
1477
1477
  var MAX_PORT_ATTEMPTS = 5;
1478
1478
  var MAX_KEY_NAME_LENGTH = 120;
1479
+ var MAX_GRANT_LENGTH = 4e3;
1479
1480
  var MAX_ERROR_LENGTH = 200;
1480
1481
  var CHECK_MARK = `<div style="width:48px;height:48px;border-radius:50%;background:rgba(34,197,94,0.1);display:flex;align-items:center;justify-content:center;margin:0 auto 16px">
1481
1482
  <svg width="24" height="24" fill="none" stroke="#22c55e" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/></svg>
@@ -1539,9 +1540,10 @@ function startCallbackServer(expectedState) {
1539
1540
  return;
1540
1541
  }
1541
1542
  const keyName = cleanParam(url.searchParams.get("name"), MAX_KEY_NAME_LENGTH);
1543
+ const grant = cleanParam(url.searchParams.get("grant"), MAX_GRANT_LENGTH);
1542
1544
  res.writeHead(200, { "Content-Type": "text/html" });
1543
1545
  res.end(SUCCESS_HTML);
1544
- resolveResult({ kind: "key", apiKey, keyName });
1546
+ resolveResult({ kind: "key", apiKey, keyName, grant });
1545
1547
  return;
1546
1548
  }
1547
1549
  const error2 = cleanParam(url.searchParams.get("error"), MAX_ERROR_LENGTH);
@@ -1593,6 +1595,9 @@ function noteWidth() {
1593
1595
  const usable = (typeof columns === "number" && columns > 0 ? columns : 80) - 8;
1594
1596
  return Math.max(usable, 40);
1595
1597
  }
1598
+ function grantNoteLines(grant, label) {
1599
+ return grant ? wrapForNote(`${label} ${grant}`).split("\n") : [];
1600
+ }
1596
1601
  async function browserLogin(opts) {
1597
1602
  const state = crypto.randomUUID();
1598
1603
  const spin = createSpinner();
@@ -1650,7 +1655,7 @@ ${describeInstallContext(context)}`
1650
1655
  const apiBase = getApiBase();
1651
1656
  const api = new OneApi(outcome.apiKey, apiBase);
1652
1657
  const whoami = await api.whoami();
1653
- return { apiKey: outcome.apiKey, whoami, keyName: outcome.keyName };
1658
+ return { apiKey: outcome.apiKey, whoami, keyName: outcome.keyName, grant: outcome.grant };
1654
1659
  } catch (err) {
1655
1660
  spin.stop("Authentication failed.");
1656
1661
  if (err instanceof Error && err.message === "timeout") {
@@ -1709,7 +1714,7 @@ async function loginCommand() {
1709
1714
  }
1710
1715
  const result = await browserLogin({ scope: targetScope });
1711
1716
  if (!result) return;
1712
- const { apiKey, whoami, keyName } = result;
1717
+ const { apiKey, whoami, keyName, grant } = result;
1713
1718
  saveCredentials(apiKey, targetScope, { keyName, whoami });
1714
1719
  const pc16 = (await import("picocolors")).default;
1715
1720
  const env = getEnvFromApiKey(apiKey);
@@ -1724,6 +1729,7 @@ async function loginCommand() {
1724
1729
  `${whoami.user.name} ${pc16.dim(`(${whoami.user.email})`)}`
1725
1730
  ];
1726
1731
  if (keyName) infoLines.push(`${pc16.dim("Key:")} ${keyName}`);
1732
+ infoLines.push(...grantNoteLines(grant, pc16.dim("Access:")));
1727
1733
  if (whoami.organization) infoLines.push(`${pc16.dim("Org:")} ${whoami.organization.name}`);
1728
1734
  if (whoami.project) infoLines.push(`${pc16.dim("Project:")} ${whoami.project.name}`);
1729
1735
  infoLines.push("");
@@ -1780,6 +1786,7 @@ async function nonInteractiveInit(options) {
1780
1786
  const scope = options.global ? "global" : options.project ? "project" : "global";
1781
1787
  let apiKey;
1782
1788
  let keyName;
1789
+ let grant;
1783
1790
  let whoami;
1784
1791
  if (auth === "browser") {
1785
1792
  const result = await browserLogin({ scope });
@@ -1788,6 +1795,7 @@ async function nonInteractiveInit(options) {
1788
1795
  }
1789
1796
  apiKey = result.apiKey;
1790
1797
  keyName = result.keyName;
1798
+ grant = result.grant;
1791
1799
  whoami = result.whoami;
1792
1800
  } else {
1793
1801
  const key = options.apiKey?.trim();
@@ -1834,6 +1842,7 @@ async function nonInteractiveInit(options) {
1834
1842
  env: getEnvFromApiKey(apiKey)
1835
1843
  },
1836
1844
  keyName,
1845
+ grant,
1837
1846
  skillInstalled: installed,
1838
1847
  skillFailed: failed
1839
1848
  });
@@ -1851,6 +1860,7 @@ async function nonInteractiveInit(options) {
1851
1860
  console.log(` ${pc4.dim("Account:")} ${scopeDisplay} ${pc4.dim("\xB7")} ${envLabel}`);
1852
1861
  console.log(` ${pc4.dim("User:")} ${whoami.user.name} ${pc4.dim(`(${whoami.user.email})`)}`);
1853
1862
  if (keyName) console.log(` ${pc4.dim("Key:")} ${keyName}`);
1863
+ if (grant) console.log(` ${pc4.dim("Access:")} ${grant}`);
1854
1864
  console.log(` ${pc4.dim("Config:")} ${tildify(configPath)}`);
1855
1865
  if (installed.length > 0) {
1856
1866
  console.log(` ${pc4.dim("Skill:")} ${pc4.green("installed")} ${pc4.dim("\xB7 " + installed.join(", "))}`);
@@ -2046,6 +2056,7 @@ async function handleUpdateKey(statuses, scope) {
2046
2056
  }
2047
2057
  let newKey;
2048
2058
  let keyName;
2059
+ let grant;
2049
2060
  let whoamiResult;
2050
2061
  if (authMethod === "browser") {
2051
2062
  const result = await browserLogin({ scope });
@@ -2055,6 +2066,7 @@ async function handleUpdateKey(statuses, scope) {
2055
2066
  }
2056
2067
  newKey = result.apiKey;
2057
2068
  keyName = result.keyName;
2069
+ grant = result.grant;
2058
2070
  whoamiResult = result.whoami;
2059
2071
  } else {
2060
2072
  p3.note(`Get your API key at:
@@ -2108,7 +2120,8 @@ ${pc4.cyan(getApiKeyUrl())}`, `API Key ${scopeLabel(scope)}`);
2108
2120
  [
2109
2121
  `${scopeDisplay} ${pc4.dim("\xB7")} ${envLabel}`,
2110
2122
  `${whoamiResult.user.name} ${pc4.dim(`(${whoamiResult.user.email})`)}`,
2111
- ...keyName ? [`${pc4.dim("Key:")} ${keyName}`] : []
2123
+ ...keyName ? [`${pc4.dim("Key:")} ${keyName}`] : [],
2124
+ ...grantNoteLines(grant, pc4.dim("Access:"))
2112
2125
  ].join("\n"),
2113
2126
  "Account"
2114
2127
  );
@@ -2370,7 +2383,8 @@ async function freshSetup(scope, options) {
2370
2383
  [
2371
2384
  `${scopeDisplay} ${pc4.dim("\xB7")} ${envLabel}`,
2372
2385
  `${result.whoami.user.name} ${pc4.dim(`(${result.whoami.user.email})`)}`,
2373
- ...result.keyName ? [`${pc4.dim("Key:")} ${result.keyName}`] : []
2386
+ ...result.keyName ? [`${pc4.dim("Key:")} ${result.keyName}`] : [],
2387
+ ...grantNoteLines(result.grant, pc4.dim("Access:"))
2374
2388
  ].join("\n"),
2375
2389
  "Account"
2376
2390
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withone/cli",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "CLI for managing One",
5
5
  "type": "module",
6
6
  "files": [