@todoforai/cli 0.1.1 → 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 +11 -8
  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:
@@ -44899,13 +44899,13 @@ Cancelled by user (Ctrl+C)
44899
44899
  while (Date.now() < deadline) {
44900
44900
  await new Promise((r) => setTimeout(r, 3000));
44901
44901
  try {
44902
- const poll = await api2.pollDeviceLogin(code);
44902
+ const poll = await loginApi.pollDeviceLogin(code);
44903
44903
  failures = 0;
44904
44904
  if (poll.status === "complete" && poll.apiKey) {
44905
44905
  cfg.setDefaultApiKey(poll.apiKey);
44906
44906
  process.stderr.write(`${GREEN}\u2705 Login successful! API key saved.${RESET}
44907
44907
  `);
44908
- return;
44908
+ return poll.apiKey;
44909
44909
  }
44910
44910
  if (poll.status === "expired")
44911
44911
  break;
@@ -44921,10 +44921,13 @@ Cancelled by user (Ctrl+C)
44921
44921
  `);
44922
44922
  process.exit(1);
44923
44923
  }
44924
- 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") || "";
44925
44929
  if (!apiKey) {
44926
- process.stderr.write("Error: No API key. Set via --api-key, TODOFORAI_API_KEY env, or `todoai login`\n");
44927
- process.exit(1);
44930
+ apiKey = await deviceLogin();
44928
44931
  }
44929
44932
  const api = new ApiClient(apiUrl, apiKey);
44930
44933
  if (args.inspect) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@todoforai/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "todoai": "dist/todoai.js"