@todoforai/cli 0.1.0 → 0.1.2

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/todoai.js +17 -10
  2. package/package.json +1 -1
package/dist/todoai.js CHANGED
@@ -44871,9 +44871,9 @@ Cancelled by user (Ctrl+C)
44871
44871
  return;
44872
44872
  }
44873
44873
  const apiUrl = normalizeApiUrl(args["api-url"] || cfg.data.default_api_url || getEnv("API_URL") || DEFAULT_API_URL);
44874
- if (positionals[0] === "login" && positionals.length === 1) {
44875
- const api2 = new ApiClient(apiUrl, "");
44876
- const { code, url, expiresIn } = await api2.initDeviceLogin("cli");
44874
+ async function deviceLogin() {
44875
+ const loginApi = new ApiClient(apiUrl, "");
44876
+ const { code, url, expiresIn } = await loginApi.initDeviceLogin("cli");
44877
44877
  const userCode = new URL(url).searchParams.get("user_code") || code.slice(-8).toUpperCase();
44878
44878
  process.stderr.write(`
44879
44879
  \uD83D\uDD11 Open this URL to authorize:
@@ -44885,8 +44885,12 @@ Cancelled by user (Ctrl+C)
44885
44885
  `);
44886
44886
  try {
44887
44887
  const { spawn } = await import("child_process");
44888
- const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
44889
- spawn(cmd, [url], { stdio: "ignore", detached: true }).unref();
44888
+ if (process.platform === "win32") {
44889
+ spawn("cmd", ["/c", "start", "", url], { stdio: "ignore", detached: true }).unref();
44890
+ } else {
44891
+ const cmd = process.platform === "darwin" ? "open" : "xdg-open";
44892
+ spawn(cmd, [url], { stdio: "ignore", detached: true }).unref();
44893
+ }
44890
44894
  } catch {}
44891
44895
  process.stderr.write(`Waiting for approval (expires in ${Math.round(expiresIn / 60)}min)...
44892
44896
  `);
@@ -44895,13 +44899,13 @@ Cancelled by user (Ctrl+C)
44895
44899
  while (Date.now() < deadline) {
44896
44900
  await new Promise((r) => setTimeout(r, 3000));
44897
44901
  try {
44898
- const poll = await api2.pollDeviceLogin(code);
44902
+ const poll = await loginApi.pollDeviceLogin(code);
44899
44903
  failures = 0;
44900
44904
  if (poll.status === "complete" && poll.apiKey) {
44901
44905
  cfg.setDefaultApiKey(poll.apiKey);
44902
44906
  process.stderr.write(`${GREEN}\u2705 Login successful! API key saved.${RESET}
44903
44907
  `);
44904
- return;
44908
+ return poll.apiKey;
44905
44909
  }
44906
44910
  if (poll.status === "expired")
44907
44911
  break;
@@ -44917,10 +44921,13 @@ Cancelled by user (Ctrl+C)
44917
44921
  `);
44918
44922
  process.exit(1);
44919
44923
  }
44920
- const apiKey = args["api-key"] || cfg.data.default_api_key || getEnv("API_KEY") || "";
44924
+ if (positionals[0] === "login" && positionals.length === 1) {
44925
+ await deviceLogin();
44926
+ return;
44927
+ }
44928
+ let apiKey = args["api-key"] || cfg.data.default_api_key || getEnv("API_KEY") || "";
44921
44929
  if (!apiKey) {
44922
- process.stderr.write("Error: No API key. Set via --api-key, TODOFORAI_API_KEY env, or `todoai login`\n");
44923
- process.exit(1);
44930
+ apiKey = await deviceLogin();
44924
44931
  }
44925
44932
  const api = new ApiClient(apiUrl, apiKey);
44926
44933
  if (args.inspect) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@todoforai/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "todoai": "dist/todoai.js"