@corsair-dev/cli 0.1.12 → 0.1.13

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/dist/auth.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare function runAuth({ cwd, pluginId: pluginIdArg, tenantId: tenantIdArg, code: codeArg, credentials: showCredentials, agent: agentMode, }: {
1
+ export declare function runAuth({ cwd, pluginId: pluginIdArg, tenantId: tenantIdArg, code: codeArg, credentials: showCredentials, listen: listenMode, collect: collectMode, sessionId, }: {
2
2
  cwd: string;
3
3
  pluginId?: string;
4
4
  tenantId?: string;
@@ -6,7 +6,11 @@ export declare function runAuth({ cwd, pluginId: pluginIdArg, tenantId: tenantId
6
6
  code?: string;
7
7
  /** Output current credential status instead of starting OAuth flow. */
8
8
  credentials?: boolean;
9
- /** When true, output instructions for an AI agent to guide the user through auth. */
10
- agent?: boolean;
9
+ /** Internal: run as the background OAuth callback server for a given session. */
10
+ listen?: boolean;
11
+ /** Check whether the background OAuth session completed and tokens are stored. */
12
+ collect?: boolean;
13
+ /** Session ID tying --listen and --collect together. */
14
+ sessionId?: string;
11
15
  }): Promise<void>;
12
16
  //# sourceMappingURL=auth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../auth.ts"],"names":[],"mappings":"AAwmBA,wBAAsB,OAAO,CAAC,EAC7B,GAAG,EACH,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,eAAuB,EACpC,KAAK,EAAE,SAAiB,GACxB,EAAE;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qFAAqF;IACrF,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6EhB"}
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../auth.ts"],"names":[],"mappings":"AAguBA,wBAAsB,OAAO,CAAC,EAC7B,GAAG,EACH,QAAQ,EAAE,WAAW,EACrB,QAAQ,EAAE,WAAW,EACrB,IAAI,EAAE,OAAO,EACb,WAAW,EAAE,eAAuB,EACpC,MAAM,EAAE,UAAkB,EAC1B,OAAO,EAAE,WAAmB,EAC5B,SAAS,GACT,EAAE;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,iFAAiF;IACjF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kFAAkF;IAClF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgJhB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAuLA;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQhE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,kBAAkB,CAAC,EACxC,GAAG,EACH,UAAU,EACV,kBAA0B,GAC1B,EAAE;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B,eAqLA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAyLA;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQhE;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,kBAAkB,CAAC,EACxC,GAAG,EACH,UAAU,EACV,kBAA0B,GAC1B,EAAE;IACF,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B,eAqLA"}
package/dist/index.js CHANGED
@@ -1577,9 +1577,14 @@ var auth_exports = {};
1577
1577
  __export(auth_exports, {
1578
1578
  runAuth: () => runAuth
1579
1579
  });
1580
+ import { spawn } from "child_process";
1581
+ import * as crypto4 from "crypto";
1582
+ import * as fs2 from "fs";
1580
1583
  import * as http from "http";
1581
1584
  import * as https from "https";
1582
1585
  import * as net from "net";
1586
+ import * as os from "os";
1587
+ import * as path2 from "path";
1583
1588
  import * as querystring from "querystring";
1584
1589
  import {
1585
1590
  CORSAIR_INTERNAL as CORSAIR_INTERNAL3,
@@ -1592,6 +1597,30 @@ import { createCorsairOrm } from "corsair/orm";
1592
1597
  function out(data) {
1593
1598
  console.log(JSON.stringify(data));
1594
1599
  }
1600
+ function authStateFile(sessionId) {
1601
+ return path2.join(os.tmpdir(), `corsair-auth-${sessionId}.json`);
1602
+ }
1603
+ function writeAuthState(sessionId, state) {
1604
+ fs2.writeFileSync(authStateFile(sessionId), JSON.stringify(state));
1605
+ }
1606
+ function pollAuthState(sessionId, timeoutMs) {
1607
+ return new Promise((resolve, reject) => {
1608
+ const file = authStateFile(sessionId);
1609
+ const start = Date.now();
1610
+ const interval = setInterval(() => {
1611
+ try {
1612
+ const state = JSON.parse(fs2.readFileSync(file, "utf8"));
1613
+ clearInterval(interval);
1614
+ resolve(state);
1615
+ } catch {
1616
+ if (Date.now() - start > timeoutMs) {
1617
+ clearInterval(interval);
1618
+ reject(new Error("Timed out waiting for OAuth server to start"));
1619
+ }
1620
+ }
1621
+ }, 100);
1622
+ });
1623
+ }
1595
1624
  function getOAuthConfigForPlugin(plugin) {
1596
1625
  return plugin.oauthConfig ?? null;
1597
1626
  }
@@ -1743,100 +1772,6 @@ async function ensureAccount(database, integrationId, tenantId, kek) {
1743
1772
  dek: encryptedDek
1744
1773
  });
1745
1774
  }
1746
- async function oauthGetUrl(database, plugin, kek, tenantId) {
1747
- const oauthCfg = getOAuthConfigForPlugin(plugin);
1748
- if (!oauthCfg) {
1749
- out({ error: `No oauthConfig defined on plugin '${plugin.id}'.` });
1750
- return;
1751
- }
1752
- const extraFields = getCustomIntegrationFields(plugin, "oauth_2");
1753
- const integrationKm = createIntegrationKeyManager3({
1754
- authType: "oauth_2",
1755
- integrationName: plugin.id,
1756
- kek,
1757
- database,
1758
- extraIntegrationFields: extraFields
1759
- });
1760
- const clientId = await integrationKm.get_client_id();
1761
- if (!clientId) {
1762
- out({
1763
- error: `client_id not set for '${plugin.id}'. Run: corsair setup --${plugin.id} client_id=YOUR_CLIENT_ID`
1764
- });
1765
- return;
1766
- }
1767
- const clientSecret = await integrationKm.get_client_secret();
1768
- if (!clientSecret) {
1769
- out({
1770
- error: `client_secret not set for '${plugin.id}'. Run: corsair setup --${plugin.id} client_secret=YOUR_CLIENT_SECRET`
1771
- });
1772
- return;
1773
- }
1774
- let redirectUri;
1775
- if (oauthCfg.requiresRegisteredRedirect) {
1776
- const stored = await integrationKm.get_redirect_url();
1777
- if (!stored) {
1778
- out({
1779
- error: `redirect_url required for '${plugin.id}'. Run: corsair setup --${plugin.id} redirect_url=YOUR_REDIRECT_URI`
1780
- });
1781
- return;
1782
- }
1783
- redirectUri = stored;
1784
- } else {
1785
- const port = await findFreePort();
1786
- redirectUri = `http://localhost:${port}`;
1787
- }
1788
- const authParams = {
1789
- client_id: clientId,
1790
- redirect_uri: redirectUri,
1791
- response_type: "code",
1792
- scope: oauthCfg.scopes.join(" "),
1793
- ...oauthCfg.authParams
1794
- };
1795
- const authUrl = `${oauthCfg.authUrl}?${querystring.stringify(authParams)}`;
1796
- const localhostPortMatch = redirectUri.match(
1797
- /^https?:\/\/(?:localhost|127\.0\.0\.1):(\d+)/
1798
- );
1799
- const localhostPort = localhostPortMatch?.[1] ? parseInt(localhostPortMatch[1], 10) : null;
1800
- if (localhostPort) {
1801
- out({
1802
- status: "pending_oauth",
1803
- authUrl,
1804
- redirectUri,
1805
- plugin: plugin.id,
1806
- tenant: tenantId,
1807
- note: "Open authUrl in a browser. Tokens will be saved automatically once authorized."
1808
- });
1809
- let code;
1810
- try {
1811
- code = await waitForOAuthCode(localhostPort);
1812
- } catch (err) {
1813
- out({
1814
- error: `Authorization failed: ${err instanceof Error ? err.message : String(err)}`
1815
- });
1816
- return;
1817
- }
1818
- await oauthExchangeCode(
1819
- database,
1820
- plugin,
1821
- kek,
1822
- tenantId,
1823
- code,
1824
- redirectUri,
1825
- clientId,
1826
- clientSecret,
1827
- oauthCfg
1828
- );
1829
- return;
1830
- }
1831
- out({
1832
- status: "needs_code",
1833
- authUrl,
1834
- redirectUri,
1835
- plugin: plugin.id,
1836
- tenant: tenantId,
1837
- note: "Open authUrl, complete auth, then run: corsair auth --plugin=<id> --code=CODE"
1838
- });
1839
- }
1840
1775
  async function oauthExchangeCode(database, plugin, kek, tenantId, code, redirectUri, clientId, clientSecret, oauthCfg) {
1841
1776
  let tokens;
1842
1777
  try {
@@ -1851,13 +1786,13 @@ async function oauthExchangeCode(database, plugin, kek, tenantId, code, redirect
1851
1786
  out({
1852
1787
  error: `Token exchange failed: ${err instanceof Error ? err.message : String(err)}`
1853
1788
  });
1854
- return;
1789
+ return false;
1855
1790
  }
1856
1791
  if (!tokens.access_token) {
1857
1792
  out({
1858
1793
  error: `No access_token in response from ${oauthCfg.providerName}.`
1859
1794
  });
1860
- return;
1795
+ return false;
1861
1796
  }
1862
1797
  const extraAccountFields = getCustomAccountFields(plugin, "oauth_2");
1863
1798
  const accountKm = createAccountKeyManager3({
@@ -1876,6 +1811,7 @@ async function oauthExchangeCode(database, plugin, kek, tenantId, code, redirect
1876
1811
  (Math.floor(Date.now() / 1e3) + tokens.expires_in).toString()
1877
1812
  );
1878
1813
  out({ status: "success", plugin: plugin.id, tenant: tenantId });
1814
+ return true;
1879
1815
  }
1880
1816
  async function oauthWithCode(database, plugin, kek, tenantId, code) {
1881
1817
  const oauthCfg = getOAuthConfigForPlugin(plugin);
@@ -1912,6 +1848,153 @@ async function oauthWithCode(database, plugin, kek, tenantId, code) {
1912
1848
  oauthCfg
1913
1849
  );
1914
1850
  }
1851
+ async function oauthListen(database, plugin, kek, tenantId, sessionId) {
1852
+ const oauthCfg = getOAuthConfigForPlugin(plugin);
1853
+ if (!oauthCfg) {
1854
+ writeAuthState(sessionId, {
1855
+ status: "error",
1856
+ error: `No oauthConfig defined on plugin '${plugin.id}'.`
1857
+ });
1858
+ return;
1859
+ }
1860
+ const extraFields = getCustomIntegrationFields(plugin, "oauth_2");
1861
+ const integrationKm = createIntegrationKeyManager3({
1862
+ authType: "oauth_2",
1863
+ integrationName: plugin.id,
1864
+ kek,
1865
+ database,
1866
+ extraIntegrationFields: extraFields
1867
+ });
1868
+ const clientId = await integrationKm.get_client_id();
1869
+ if (!clientId) {
1870
+ writeAuthState(sessionId, {
1871
+ status: "error",
1872
+ error: `client_id not set for '${plugin.id}'.`
1873
+ });
1874
+ return;
1875
+ }
1876
+ const clientSecret = await integrationKm.get_client_secret();
1877
+ if (!clientSecret) {
1878
+ writeAuthState(sessionId, {
1879
+ status: "error",
1880
+ error: `client_secret not set for '${plugin.id}'.`
1881
+ });
1882
+ return;
1883
+ }
1884
+ let redirectUri;
1885
+ let localhostPort;
1886
+ if (oauthCfg.requiresRegisteredRedirect) {
1887
+ const stored = await integrationKm.get_redirect_url();
1888
+ if (!stored) {
1889
+ writeAuthState(sessionId, {
1890
+ status: "error",
1891
+ error: `redirect_url required for '${plugin.id}'.`
1892
+ });
1893
+ return;
1894
+ }
1895
+ const match = stored.match(/^https?:\/\/(?:localhost|127\.0\.0\.1):(\d+)/);
1896
+ if (!match) {
1897
+ const authParams2 = {
1898
+ client_id: clientId,
1899
+ redirect_uri: stored,
1900
+ response_type: "code",
1901
+ scope: oauthCfg.scopes.join(" "),
1902
+ ...oauthCfg.authParams
1903
+ };
1904
+ const authUrl2 = `${oauthCfg.authUrl}?${querystring.stringify(authParams2)}`;
1905
+ writeAuthState(sessionId, {
1906
+ status: "needs_code",
1907
+ url: authUrl2,
1908
+ redirectUri: stored
1909
+ });
1910
+ return;
1911
+ }
1912
+ redirectUri = stored;
1913
+ localhostPort = parseInt(match[1], 10);
1914
+ } else {
1915
+ localhostPort = await findFreePort();
1916
+ redirectUri = `http://localhost:${localhostPort}`;
1917
+ }
1918
+ const authParams = {
1919
+ client_id: clientId,
1920
+ redirect_uri: redirectUri,
1921
+ response_type: "code",
1922
+ scope: oauthCfg.scopes.join(" "),
1923
+ ...oauthCfg.authParams
1924
+ };
1925
+ const authUrl = `${oauthCfg.authUrl}?${querystring.stringify(authParams)}`;
1926
+ writeAuthState(sessionId, { status: "listening", url: authUrl });
1927
+ const timeout = setTimeout(
1928
+ () => {
1929
+ writeAuthState(sessionId, {
1930
+ status: "error",
1931
+ error: "OAuth session timed out after 10 minutes."
1932
+ });
1933
+ process.exit(0);
1934
+ },
1935
+ 10 * 60 * 1e3
1936
+ );
1937
+ timeout.unref();
1938
+ let code;
1939
+ try {
1940
+ code = await waitForOAuthCode(localhostPort);
1941
+ } catch (err) {
1942
+ writeAuthState(sessionId, {
1943
+ status: "error",
1944
+ error: `Authorization failed: ${err instanceof Error ? err.message : String(err)}`
1945
+ });
1946
+ return;
1947
+ }
1948
+ const success = await oauthExchangeCode(
1949
+ database,
1950
+ plugin,
1951
+ kek,
1952
+ tenantId,
1953
+ code,
1954
+ redirectUri,
1955
+ clientId,
1956
+ clientSecret,
1957
+ oauthCfg
1958
+ );
1959
+ writeAuthState(
1960
+ sessionId,
1961
+ success ? { status: "complete" } : { status: "error", error: "Token exchange failed." }
1962
+ );
1963
+ }
1964
+ async function oauthCollect(database, plugin, kek, tenantId, sessionId) {
1965
+ const extraAccountFields = getCustomAccountFields(plugin, "oauth_2");
1966
+ const accountKm = createAccountKeyManager3({
1967
+ authType: "oauth_2",
1968
+ integrationName: plugin.id,
1969
+ tenantId,
1970
+ kek,
1971
+ database,
1972
+ extraAccountFields
1973
+ });
1974
+ const accessToken = await accountKm.get_access_token();
1975
+ if (accessToken) {
1976
+ try {
1977
+ fs2.unlinkSync(authStateFile(sessionId));
1978
+ } catch {
1979
+ }
1980
+ out({ status: "success", plugin: plugin.id, tenant: tenantId });
1981
+ return;
1982
+ }
1983
+ try {
1984
+ const state = JSON.parse(
1985
+ fs2.readFileSync(authStateFile(sessionId), "utf8")
1986
+ );
1987
+ if (state.status === "error") {
1988
+ out({ status: "error", error: state.error });
1989
+ return;
1990
+ }
1991
+ } catch {
1992
+ }
1993
+ out({
1994
+ status: "pending",
1995
+ message: "User has not completed sign-in yet. Try again after the user visits the auth URL."
1996
+ });
1997
+ }
1915
1998
  async function getCredentials(database, plugin, kek, tenantId) {
1916
1999
  const authType = getAuthType(plugin);
1917
2000
  const result = {};
@@ -1991,7 +2074,9 @@ async function runAuth({
1991
2074
  tenantId: tenantIdArg,
1992
2075
  code: codeArg,
1993
2076
  credentials: showCredentials = false,
1994
- agent: agentMode = false
2077
+ listen: listenMode = false,
2078
+ collect: collectMode = false,
2079
+ sessionId
1995
2080
  }) {
1996
2081
  let internal;
1997
2082
  try {
@@ -2037,29 +2122,95 @@ async function runAuth({
2037
2122
  });
2038
2123
  return;
2039
2124
  }
2040
- if (agentMode) {
2041
- const baseCmd = `pnpm corsair auth --plugin=${plugin.id}`;
2042
- const needsQuoting = tenantIdArg && /[^a-zA-Z0-9_\-.]/.test(tenantIdArg);
2043
- const tenantFlag = tenantIdArg && tenantIdArg !== "default" ? ` --tenant=${needsQuoting ? `"${tenantIdArg}"` : tenantIdArg}` : "";
2044
- const cmd = `${baseCmd}${tenantFlag}`;
2045
- out({
2046
- status: "agent_instructions",
2047
- plugin: plugin.id,
2048
- tenant: tenantId,
2049
- command: cmd,
2050
- message: `To authenticate the '${plugin.id}' plugin, run the following command:
2051
-
2052
- ${cmd}
2053
-
2054
- This command opens a browser and waits for an OAuth callback \u2014 it is a long-running interactive task. Either ask the user to run it in a separate terminal, or run it as a background process. Do NOT run it inline in the current session.`
2055
- });
2125
+ if (listenMode) {
2126
+ if (!sessionId) {
2127
+ out({ error: "--listen requires --session=<id>." });
2128
+ process.exit(1);
2129
+ }
2130
+ await oauthListen(database, plugin, kek, tenantId, sessionId);
2131
+ return;
2132
+ }
2133
+ if (collectMode) {
2134
+ if (!sessionId) {
2135
+ out({ error: "--collect requires --session=<id>." });
2136
+ process.exit(1);
2137
+ }
2138
+ await oauthCollect(database, plugin, kek, tenantId, sessionId);
2056
2139
  return;
2057
2140
  }
2058
2141
  if (codeArg) {
2059
2142
  await oauthWithCode(database, plugin, kek, tenantId, codeArg);
2060
- } else {
2061
- await oauthGetUrl(database, plugin, kek, tenantId);
2143
+ return;
2144
+ }
2145
+ const session = crypto4.randomUUID().slice(0, 8);
2146
+ const needsQuoting = tenantIdArg && /[^a-zA-Z0-9_\-.]/.test(tenantIdArg);
2147
+ const tenantFlag = tenantIdArg && tenantIdArg !== "default" ? `--tenant=${needsQuoting ? `"${tenantIdArg}"` : tenantIdArg}` : "";
2148
+ const spawnOpts = {
2149
+ detached: true,
2150
+ stdio: "ignore",
2151
+ cwd: process.cwd(),
2152
+ env: process.env
2153
+ };
2154
+ const child = spawn(
2155
+ process.execPath,
2156
+ [
2157
+ ...process.execArgv,
2158
+ process.argv[1] ?? "",
2159
+ "auth",
2160
+ `--plugin=${plugin.id}`,
2161
+ "--listen",
2162
+ `--session=${session}`,
2163
+ ...tenantFlag ? [tenantFlag] : []
2164
+ ],
2165
+ spawnOpts
2166
+ );
2167
+ child.unref();
2168
+ let state;
2169
+ try {
2170
+ state = await pollAuthState(session, 5e3);
2171
+ } catch (err) {
2172
+ out({
2173
+ error: `Failed to start OAuth server: ${err instanceof Error ? err.message : String(err)}`
2174
+ });
2175
+ return;
2176
+ }
2177
+ if (state.status === "needs_code") {
2178
+ console.log(`
2179
+ Authorize ${plugin.id}
2180
+ `);
2181
+ console.log(` Open this URL in your browser:
2182
+ `);
2183
+ console.log(` ${state.url}
2184
+ `);
2185
+ console.log(
2186
+ ` Once you've signed in, copy the code from the redirect URL and run:
2187
+ `
2188
+ );
2189
+ console.log(` pnpm corsair auth --plugin=${plugin.id} --code=CODE
2190
+ `);
2191
+ return;
2192
+ }
2193
+ if (state.status === "error") {
2194
+ out({ error: state.error });
2195
+ return;
2062
2196
  }
2197
+ const collectCmd = [
2198
+ `pnpm corsair auth --plugin=${plugin.id}`,
2199
+ "--collect",
2200
+ `--session=${session}`,
2201
+ ...tenantFlag ? [tenantFlag] : []
2202
+ ].join(" ");
2203
+ console.log(`
2204
+ Authorize ${plugin.id}
2205
+ `);
2206
+ console.log(` Open this URL in your browser:
2207
+ `);
2208
+ console.log(` ${state.url}
2209
+ `);
2210
+ console.log(` Once you've signed in, run:
2211
+ `);
2212
+ console.log(` ${collectCmd}
2213
+ `);
2063
2214
  }
2064
2215
  var init_auth = __esm({
2065
2216
  "auth.ts"() {
@@ -2069,34 +2220,35 @@ var init_auth = __esm({
2069
2220
  });
2070
2221
 
2071
2222
  // index.ts
2072
- import fs2, { existsSync, realpathSync } from "fs";
2073
- import path2 from "path";
2223
+ import fs3, { existsSync, realpathSync } from "fs";
2224
+ import path3 from "path";
2074
2225
  import { fileURLToPath } from "url";
2075
2226
  import babelPresetReact from "@babel/preset-react";
2076
2227
  import babelPresetTypeScript from "@babel/preset-typescript";
2077
2228
  import { loadConfig } from "c12";
2229
+ import { getSchema, listOperations } from "corsair";
2078
2230
  function resolveReferencePath(configDir, refPath) {
2079
- const resolvedPath = path2.resolve(configDir, refPath);
2231
+ const resolvedPath = path3.resolve(configDir, refPath);
2080
2232
  if (refPath.endsWith(".json")) {
2081
2233
  return resolvedPath;
2082
2234
  }
2083
- if (fs2.existsSync(resolvedPath)) {
2235
+ if (fs3.existsSync(resolvedPath)) {
2084
2236
  try {
2085
- const stats = fs2.statSync(resolvedPath);
2237
+ const stats = fs3.statSync(resolvedPath);
2086
2238
  if (stats.isFile()) {
2087
2239
  return resolvedPath;
2088
2240
  }
2089
2241
  } catch {
2090
2242
  }
2091
2243
  }
2092
- return path2.resolve(configDir, refPath, "tsconfig.json");
2244
+ return path3.resolve(configDir, refPath, "tsconfig.json");
2093
2245
  }
2094
2246
  function getPathAliasesRecursive(tsconfigPath, visited = /* @__PURE__ */ new Set()) {
2095
2247
  if (visited.has(tsconfigPath)) {
2096
2248
  return {};
2097
2249
  }
2098
2250
  visited.add(tsconfigPath);
2099
- if (!fs2.existsSync(tsconfigPath)) {
2251
+ if (!fs3.existsSync(tsconfigPath)) {
2100
2252
  console.warn(`Referenced tsconfig not found: ${tsconfigPath}`);
2101
2253
  return {};
2102
2254
  }
@@ -2104,14 +2256,14 @@ function getPathAliasesRecursive(tsconfigPath, visited = /* @__PURE__ */ new Set
2104
2256
  const tsConfig = getTsconfigInfo(void 0, tsconfigPath);
2105
2257
  const { paths = {}, baseUrl = "." } = tsConfig.compilerOptions || {};
2106
2258
  const result = {};
2107
- const configDir = path2.dirname(tsconfigPath);
2259
+ const configDir = path3.dirname(tsconfigPath);
2108
2260
  const obj = Object.entries(paths);
2109
2261
  for (const [alias, aliasPaths] of obj) {
2110
2262
  for (const aliasedPath of aliasPaths) {
2111
- const resolvedBaseUrl = path2.resolve(configDir, baseUrl);
2263
+ const resolvedBaseUrl = path3.resolve(configDir, baseUrl);
2112
2264
  const finalAlias = alias.slice(-1) === "*" ? alias.slice(0, -1) : alias;
2113
2265
  const finalAliasedPath = aliasedPath.slice(-1) === "*" ? aliasedPath.slice(0, -1) : aliasedPath;
2114
- result[finalAlias || ""] = path2.join(resolvedBaseUrl, finalAliasedPath);
2266
+ result[finalAlias || ""] = path3.join(resolvedBaseUrl, finalAliasedPath);
2115
2267
  }
2116
2268
  }
2117
2269
  if (tsConfig.references) {
@@ -2132,8 +2284,8 @@ function getPathAliasesRecursive(tsconfigPath, visited = /* @__PURE__ */ new Set
2132
2284
  }
2133
2285
  }
2134
2286
  function getPathAliases(cwd) {
2135
- const tsConfigPath = path2.join(cwd, "tsconfig.json");
2136
- if (!fs2.existsSync(tsConfigPath)) {
2287
+ const tsConfigPath = path3.join(cwd, "tsconfig.json");
2288
+ if (!fs3.existsSync(tsConfigPath)) {
2137
2289
  return null;
2138
2290
  }
2139
2291
  try {
@@ -2146,7 +2298,7 @@ function getPathAliases(cwd) {
2146
2298
  }
2147
2299
  function findCorsairConfigPath(cwd) {
2148
2300
  for (const possiblePath of possiblePaths) {
2149
- const fullPath = path2.join(cwd, possiblePath);
2301
+ const fullPath = path3.join(cwd, possiblePath);
2150
2302
  if (existsSync(fullPath)) {
2151
2303
  return fullPath;
2152
2304
  }
@@ -2161,7 +2313,7 @@ async function getCorsairInstance({
2161
2313
  try {
2162
2314
  let corsairInstance = null;
2163
2315
  if (configPath) {
2164
- let resolvedPath = path2.join(cwd, configPath);
2316
+ let resolvedPath = path3.join(cwd, configPath);
2165
2317
  if (existsSync(configPath)) {
2166
2318
  resolvedPath = configPath;
2167
2319
  }
@@ -2312,8 +2464,8 @@ function resolveClient(instance, tenant) {
2312
2464
  }
2313
2465
  return obj;
2314
2466
  }
2315
- function navigateToEndpoint(client, path3) {
2316
- const parts = path3.split(".");
2467
+ function navigateToEndpoint(client, path4) {
2468
+ const parts = path4.split(".");
2317
2469
  let current = client;
2318
2470
  for (const part of parts) {
2319
2471
  if (current === null || typeof current !== "object") return void 0;
@@ -2347,20 +2499,26 @@ function parseAuthArgs(args) {
2347
2499
  let code;
2348
2500
  let credentials = false;
2349
2501
  let webhook = false;
2350
- let agent = false;
2502
+ let listen = false;
2503
+ let collect = false;
2504
+ let sessionId;
2351
2505
  for (const arg of args) {
2352
2506
  if (arg === "--credentials") {
2353
2507
  credentials = true;
2354
2508
  continue;
2355
2509
  }
2356
- if (arg === "--agent") {
2357
- agent = true;
2358
- continue;
2359
- }
2360
2510
  if (arg === "--webhook") {
2361
2511
  webhook = true;
2362
2512
  continue;
2363
2513
  }
2514
+ if (arg === "--listen") {
2515
+ listen = true;
2516
+ continue;
2517
+ }
2518
+ if (arg === "--collect") {
2519
+ collect = true;
2520
+ continue;
2521
+ }
2364
2522
  const eqIdx = arg.indexOf("=");
2365
2523
  if (arg.startsWith("--") && eqIdx !== -1) {
2366
2524
  const key = arg.slice(2, eqIdx);
@@ -2377,9 +2535,22 @@ function parseAuthArgs(args) {
2377
2535
  code = value;
2378
2536
  continue;
2379
2537
  }
2538
+ if (key === "session") {
2539
+ sessionId = value;
2540
+ continue;
2541
+ }
2380
2542
  }
2381
2543
  }
2382
- return { pluginId, tenantId, code, credentials, webhook, agent };
2544
+ return {
2545
+ pluginId,
2546
+ tenantId,
2547
+ code,
2548
+ credentials,
2549
+ webhook,
2550
+ listen,
2551
+ collect,
2552
+ sessionId
2553
+ };
2383
2554
  }
2384
2555
  function parseSetupArgs(args) {
2385
2556
  let backfill = false;
@@ -2482,7 +2653,6 @@ function printHelp() {
2482
2653
  "pnpm corsair setup --plugin=<id> <field>=VALUE Set plugin credentials",
2483
2654
  "pnpm corsair auth --plugin=<id> Start OAuth flow",
2484
2655
  "pnpm corsair auth --plugin=<id> --code=<code> Exchange OAuth code for tokens",
2485
- "pnpm corsair auth --plugin=<id> --agent Run this if you are an agent (specific instructions to handle pending process)",
2486
2656
  "pnpm corsair auth --plugin=<id> --credentials Show credential status",
2487
2657
  "pnpm corsair auth --plugin=<id> --webhook Set up webhook subscription",
2488
2658
  " `pnpm corsair list --type=webhooks` to see webhook plugins",
@@ -2584,29 +2754,17 @@ async function main() {
2584
2754
  if (command === "list") {
2585
2755
  const { plugin, type } = parseListArgs(args.slice(1));
2586
2756
  const instance = await getCorsairInstance({ cwd });
2587
- const corsair = instance;
2588
- if (typeof corsair.list_operations !== "function") {
2589
- console.error(
2590
- "[#corsair]: list_operations not available on this Corsair instance."
2591
- );
2592
- process.exit(1);
2593
- }
2594
- const result = corsair.list_operations({ plugin, type });
2757
+ const result = listOperations(instance, {
2758
+ plugin,
2759
+ type
2760
+ });
2595
2761
  if (type === "db") {
2596
2762
  console.log(
2597
2763
  "[#corsair]: NOTE: Every DB query listed here has both .search() and .list() methods available."
2598
2764
  );
2599
2765
  console.log("");
2600
2766
  }
2601
- if (typeof result === "string") {
2602
- console.log(result);
2603
- } else if (Array.isArray(result)) {
2604
- console.log(result.join("\n"));
2605
- } else if (result && typeof result === "object") {
2606
- const grouped = result;
2607
- const all = Object.values(grouped).flat();
2608
- console.log(all.join("\n"));
2609
- }
2767
+ console.log(result);
2610
2768
  return;
2611
2769
  }
2612
2770
  if (SHOW_RUN && command === "run") {
@@ -2681,7 +2839,7 @@ async function main() {
2681
2839
  try {
2682
2840
  const { createRequire } = await import("module");
2683
2841
  const { pathToFileURL } = await import("url");
2684
- const req = createRequire(path2.join(cwd, "package.json"));
2842
+ const req = createRequire(path3.join(cwd, "package.json"));
2685
2843
  const resolvedPath = req.resolve("@corsair-dev/studio/server");
2686
2844
  const mod = await import(pathToFileURL(resolvedPath).href);
2687
2845
  const candidate = mod.start ?? mod.startStudio;
@@ -2719,14 +2877,7 @@ async function main() {
2719
2877
  process.exit(1);
2720
2878
  }
2721
2879
  const instance = await getCorsairInstance({ cwd });
2722
- const corsair = instance;
2723
- if (typeof corsair.get_schema !== "function") {
2724
- console.error(
2725
- "[#corsair]: get_schema not available on this Corsair instance."
2726
- );
2727
- process.exit(1);
2728
- }
2729
- const result = corsair.get_schema(schemaPath);
2880
+ const result = getSchema(instance, schemaPath);
2730
2881
  console.log(result);
2731
2882
  return;
2732
2883
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corsair-dev/cli",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "@clack/prompts": "^1.0.0",
24
24
  "c12": "^3.3.3",
25
25
  "zod": "^3.25.76",
26
- "corsair": "0.1.59"
26
+ "corsair": "0.1.60"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/jest": "^29.5.14",