team-toon-tack 3.6.3 → 3.7.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.
@@ -2,8 +2,9 @@
2
2
  * Trello initialization flow
3
3
  */
4
4
  import fs from "node:fs/promises";
5
- import { checkbox, select } from "@inquirer/prompts";
5
+ import { checkbox, confirm, select } from "@inquirer/prompts";
6
6
  import { encode } from "@toon-format/toon";
7
+ import { writeDotEnv } from "../env.js";
7
8
  import { formatTodoStatus } from "../status-helpers.js";
8
9
  import { TrelloClient } from "../trello.js";
9
10
  import { updateGitignore } from "./file-ops.js";
@@ -16,6 +17,27 @@ export async function initTrello(options, paths) {
16
17
  console.error("Get your API key from: https://trello.com/power-ups/admin");
17
18
  process.exit(1);
18
19
  }
20
+ // Mirror into process.env so downstream code sees a consistent view
21
+ process.env.TRELLO_API_KEY = credentials.apiKey;
22
+ process.env.TRELLO_TOKEN = credentials.token;
23
+ // Offer to persist to .ttt/.env
24
+ console.log("\nšŸ” Local .env file:");
25
+ console.log(` Path: ${paths.envPath}${credentials.fromSystemEnv ? " (pins a project-local copy of your shell env)" : ""}`);
26
+ let saveToEnvFile = false;
27
+ if (options.interactive) {
28
+ saveToEnvFile = await confirm({
29
+ message: `Write TRELLO_API_KEY / TRELLO_TOKEN to ${paths.envPath}?`,
30
+ default: true,
31
+ });
32
+ }
33
+ if (saveToEnvFile) {
34
+ await fs.mkdir(paths.baseDir, { recursive: true });
35
+ await writeDotEnv(paths.envPath, {
36
+ TRELLO_API_KEY: credentials.apiKey,
37
+ TRELLO_TOKEN: credentials.token,
38
+ });
39
+ console.log(` āœ“ Wrote TRELLO_API_KEY / TRELLO_TOKEN to ${paths.envPath}`);
40
+ }
19
41
  const client = new TrelloClient(credentials.apiKey, credentials.token);
20
42
  console.log("\nšŸ“” Fetching data from Trello...");
21
43
  // Fetch boards (equivalent to teams)
@@ -223,9 +245,11 @@ export async function initTrello(options, paths) {
223
245
  console.log(` In Progress: ${statusTransitions.in_progress}`);
224
246
  console.log(` Done: ${statusTransitions.done}`);
225
247
  console.log("\nNext steps:");
226
- if (!process.env.TRELLO_API_KEY || !process.env.TRELLO_TOKEN) {
227
- console.log(" 1. Set environment variables:");
228
- console.log(` export TRELLO_API_KEY="${credentials.apiKey}"`);
248
+ const needsShellExport = !saveToEnvFile && !credentials.fromSystemEnv;
249
+ if (needsShellExport) {
250
+ const maskedKey = `${credentials.apiKey.slice(0, 8)}...${"*".repeat(8)}`;
251
+ console.log(" 1. Set environment variables in your shell profile:");
252
+ console.log(` export TRELLO_API_KEY="${maskedKey}"`);
229
253
  console.log(` export TRELLO_TOKEN="<your-token>"`);
230
254
  console.log(" 2. Run sync: ttt sync");
231
255
  console.log(" 3. Start working: ttt work-on");
@@ -5,5 +5,7 @@ import type { InitOptions } from "./types.js";
5
5
  export interface TrelloCredentials {
6
6
  apiKey: string;
7
7
  token: string;
8
+ /** true when BOTH apiKey and token came from pre-existing env vars */
9
+ fromSystemEnv: boolean;
8
10
  }
9
11
  export declare function promptForTrelloCredentials(options: InitOptions): Promise<TrelloCredentials | null>;
@@ -1,33 +1,72 @@
1
1
  /**
2
2
  * Trello-specific prompt functions for init
3
3
  */
4
- import { input, password } from "@inquirer/prompts";
4
+ import { confirm, input, password } from "@inquirer/prompts";
5
5
  import { TrelloClient } from "../trello.js";
6
+ async function promptNewCredentials() {
7
+ console.log("\nšŸ”‘ Trello API Credentials:");
8
+ console.log(" Get your API key from: https://trello.com/power-ups/admin");
9
+ const apiKey = await input({
10
+ message: "Enter your Trello API key:",
11
+ validate: (v) => (v.length > 10 ? true : "API key seems too short"),
12
+ });
13
+ if (!apiKey)
14
+ return null;
15
+ const authUrl = TrelloClient.getAuthorizationUrl(apiKey);
16
+ console.log("\n To get your token, visit this URL and authorize:");
17
+ console.log(` ${authUrl}`);
18
+ const token = await password({
19
+ message: "Enter the token from the page:",
20
+ });
21
+ if (!token)
22
+ return null;
23
+ return { apiKey, token };
24
+ }
6
25
  export async function promptForTrelloCredentials(options) {
7
- let apiKey = options.trelloApiKey || process.env.TRELLO_API_KEY;
8
- let token = options.trelloToken || process.env.TRELLO_TOKEN;
9
- if (!apiKey && options.interactive) {
10
- console.log("\nšŸ”‘ Trello API Credentials:");
11
- console.log(" Get your API key from: https://trello.com/power-ups/admin");
12
- apiKey = await input({
13
- message: "Enter your Trello API key:",
14
- validate: (v) => (v.length > 10 ? true : "API key seems too short"),
15
- });
26
+ const flagKey = options.trelloApiKey;
27
+ const flagToken = options.trelloToken;
28
+ const envKey = process.env.TRELLO_API_KEY;
29
+ const envToken = process.env.TRELLO_TOKEN;
30
+ // Non-interactive: take whatever is available, no prompts
31
+ if (!options.interactive) {
32
+ const apiKey = flagKey || envKey;
33
+ const token = flagToken || envToken;
34
+ if (!apiKey || !token)
35
+ return null;
36
+ return {
37
+ apiKey,
38
+ token,
39
+ fromSystemEnv: !flagKey && !flagToken && !!envKey && !!envToken,
40
+ };
16
41
  }
17
- if (!apiKey) {
18
- return null;
42
+ // CLI flags short-circuit the picker
43
+ if (flagKey && flagToken) {
44
+ return { apiKey: flagKey, token: flagToken, fromSystemEnv: false };
19
45
  }
20
- if (!token && options.interactive) {
21
- // Generate authorization URL
22
- const authUrl = TrelloClient.getAuthorizationUrl(apiKey);
23
- console.log("\n To get your token, visit this URL and authorize:");
24
- console.log(` ${authUrl}`);
25
- token = await password({
26
- message: "Enter the token from the page:",
46
+ let apiKey;
47
+ let token;
48
+ let fromSystemEnv = false;
49
+ // Offer the existing system env credentials, if any
50
+ if (envKey && envToken) {
51
+ console.log("\nšŸ”‘ Found Trello credentials in environment.");
52
+ const useExisting = await confirm({
53
+ message: "Use the existing TRELLO_API_KEY / TRELLO_TOKEN? (no = enter new credentials)",
54
+ default: true,
27
55
  });
56
+ if (useExisting) {
57
+ apiKey = envKey;
58
+ token = envToken;
59
+ fromSystemEnv = true;
60
+ }
28
61
  }
29
- if (!token) {
30
- return null;
62
+ // Fall through to manual entry
63
+ if (!apiKey || !token) {
64
+ const entered = await promptNewCredentials();
65
+ if (!entered)
66
+ return null;
67
+ apiKey = entered.apiKey;
68
+ token = entered.token;
69
+ fromSystemEnv = false;
31
70
  }
32
71
  // Validate credentials
33
72
  const client = new TrelloClient(apiKey, token);
@@ -37,5 +76,5 @@ export async function promptForTrelloCredentials(options) {
37
76
  return null;
38
77
  }
39
78
  console.log(" āœ“ Trello credentials validated");
40
- return { apiKey, token };
79
+ return { apiKey, token, fromSystemEnv };
41
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "team-toon-tack",
3
- "version": "3.6.3",
3
+ "version": "3.7.0",
4
4
  "description": "Linear & Trello task sync & management CLI with TOON format",
5
5
  "type": "module",
6
6
  "bin": {