natureco-cli 5.4.21 → 5.5.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.
@@ -4,6 +4,8 @@ const { getConfig, saveConfig } = require('../utils/config');
4
4
  const fs = require('fs');
5
5
  const { execSync } = require('child_process');
6
6
 
7
+ const { checkExistingToken } = require('./channel-helper');
8
+
7
9
  async function imessage(action) {
8
10
  if (!action || action === 'connect') return connectImessage();
9
11
  if (action === 'disconnect') return disconnectImessage();
@@ -11,6 +11,8 @@ const SIGNAL_PID_FILE = path.join(SIGNAL_DIR, 'daemon.pid');
11
11
  const SIGNAL_LOG_FILE = path.join(SIGNAL_DIR, 'daemon.log');
12
12
  const SIGNAL_CLI_VERSION = '0.13.6';
13
13
 
14
+ const { checkExistingToken } = require('./channel-helper');
15
+
14
16
  async function signal(action, subAction) {
15
17
  if (!action || action === 'connect') return connectSignal();
16
18
  if (action === 'disconnect') return disconnectSignal();
@@ -1,119 +1,121 @@
1
- const chalk = require('chalk');
2
- const inquirer = require('../utils/inquirer-wrapper');
3
- const { getApiKey, getConfig, saveConfig } = require('../utils/config');
4
- const { getBots } = require('../utils/api');
5
-
6
- async function slack(action) {
7
- if (!action || action === 'connect') {
8
- return connectSlack();
9
- }
10
-
11
- if (action === 'disconnect') {
12
- return disconnectSlack();
13
- }
14
-
15
- if (action === 'status') {
16
- return statusSlack();
17
- }
18
-
19
- console.log(chalk.red('\n❌ Unknown action\n'));
20
- console.log(chalk.gray('Available actions: connect, disconnect, status\n'));
21
- process.exit(1);
22
- }
23
-
24
- async function connectSlack() {
25
- const config = getConfig();
26
-
27
- if (!config.providerUrl) {
28
- console.log(chalk.red('\n❌ Setup yapılmamış. Önce "natureco setup" çalıştırın.\n'));
29
- process.exit(1);
30
- }
31
-
32
- process.stdin.resume();
33
-
34
- const answers = await inquirer.prompt([
35
- {
36
- type: 'input',
37
- name: 'token',
38
- message: 'Slack bot token (starts with xoxb-):',
39
- validate: (val) => {
40
- const trimmed = val.trim();
41
- if (trimmed === '') return 'Token cannot be empty';
42
- if (!trimmed.startsWith('xoxb-')) return 'Slack bot token must start with xoxb-';
43
- return true;
44
- },
45
- },
46
- ]);
47
-
48
- // Slack için bot ID oluştur (timestamp-based)
49
- const botId = `slack_${Date.now()}`;
50
- const selectedBot = { name: 'Slack Bot', id: botId };
51
-
52
- console.log(chalk.yellow('\n⏳ Slack bağlantısı kaydediliyor...\n'));
53
-
54
- // Save to config (v2.x - no backend call)
55
- config.slackToken = answers.token.trim();
56
- config.slackBotId = botId;
57
- saveConfig(config);
58
-
59
- console.log(chalk.green('✅ Slack token kaydedildi!\n'));
60
- console.log(chalk.cyan('Bot ID:'), chalk.white(botId));
61
- console.log(chalk.cyan('Token:'), chalk.white(answers.token.slice(0, 20) + '...'));
62
- console.log(chalk.gray('\nNot: Slack botunuzu Slack App settings\'ten yapılandırmanız gerekiyor.'));
63
- console.log(chalk.gray('Token config\'e kaydedildi: ~/.natureco/config.json\n'));
64
- }
65
-
66
- async function disconnectSlack() {
67
- const config = getConfig();
68
-
69
- if (!config.slackToken) {
70
- console.log(chalk.gray('\n⚠️ No Slack connection found\n'));
71
- return;
72
- }
73
-
74
- process.stdin.resume();
75
-
76
- const { confirm } = await inquirer.prompt([
77
- {
78
- type: 'confirm',
79
- name: 'confirm',
80
- message: 'Are you sure you want to disconnect Slack?',
81
- default: false,
82
- },
83
- ]);
84
-
85
- if (!confirm) {
86
- console.log(chalk.gray('\nCancelled\n'));
87
- return;
88
- }
89
-
90
- // Remove from config
91
- delete config.slackToken;
92
- delete config.slackBotId;
93
- saveConfig(config);
94
-
95
- console.log(chalk.green('\n✅ Slack disconnected\n'));
96
- console.log(chalk.gray('Note: The bot is still registered on Slack.'));
97
- console.log(chalk.gray('You may need to manually remove it from Slack App settings.\n'));
98
- }
99
-
100
- function statusSlack() {
101
- const config = getConfig();
102
-
103
- if (!config.slackToken) {
104
- console.log(chalk.gray('\n⚠️ Slack not connected\n'));
105
- console.log(chalk.gray('Connect with: natureco slack connect\n'));
106
- return;
107
- }
108
-
109
- console.log(chalk.green('\n✅ Slack connected\n'));
110
- console.log(chalk.cyan('Token:'), chalk.white(config.slackToken.slice(0, 20) + '...'));
111
-
112
- if (config.slackBotId) {
113
- console.log(chalk.cyan('Bot ID:'), chalk.white(config.slackBotId));
114
- }
115
-
116
- console.log(chalk.gray('\nDisconnect with: natureco slack disconnect\n'));
117
- }
118
-
119
- module.exports = slack;
1
+ const chalk = require('chalk');
2
+ const inquirer = require('../utils/inquirer-wrapper');
3
+ const { getApiKey, getConfig, saveConfig } = require('../utils/config');
4
+ const { getBots } = require('../utils/api');
5
+
6
+ const { checkExistingToken } = require('./channel-helper');
7
+
8
+ async function slack(action) {
9
+ if (!action || action === 'connect') {
10
+ return connectSlack();
11
+ }
12
+
13
+ if (action === 'disconnect') {
14
+ return disconnectSlack();
15
+ }
16
+
17
+ if (action === 'status') {
18
+ return statusSlack();
19
+ }
20
+
21
+ console.log(chalk.red('\n❌ Unknown action\n'));
22
+ console.log(chalk.gray('Available actions: connect, disconnect, status\n'));
23
+ process.exit(1);
24
+ }
25
+
26
+ async function connectSlack() {
27
+ const config = getConfig();
28
+
29
+ if (!config.providerUrl) {
30
+ console.log(chalk.red('\n❌ Setup yapılmamış. Önce "natureco setup" çalıştırın.\n'));
31
+ process.exit(1);
32
+ }
33
+
34
+ process.stdin.resume();
35
+
36
+ const answers = await inquirer.prompt([
37
+ {
38
+ type: 'input',
39
+ name: 'token',
40
+ message: 'Slack bot token (starts with xoxb-):',
41
+ validate: (val) => {
42
+ const trimmed = val.trim();
43
+ if (trimmed === '') return 'Token cannot be empty';
44
+ if (!trimmed.startsWith('xoxb-')) return 'Slack bot token must start with xoxb-';
45
+ return true;
46
+ },
47
+ },
48
+ ]);
49
+
50
+ // Slack için bot ID oluştur (timestamp-based)
51
+ const botId = `slack_${Date.now()}`;
52
+ const selectedBot = { name: 'Slack Bot', id: botId };
53
+
54
+ console.log(chalk.yellow('\n⏳ Slack bağlantısı kaydediliyor...\n'));
55
+
56
+ // Save to config (v2.x - no backend call)
57
+ config.slackToken = answers.token.trim();
58
+ config.slackBotId = botId;
59
+ saveConfig(config);
60
+
61
+ console.log(chalk.green(' Slack token kaydedildi!\n'));
62
+ console.log(chalk.cyan('Bot ID:'), chalk.white(botId));
63
+ console.log(chalk.cyan('Token:'), chalk.white(answers.token.slice(0, 20) + '...'));
64
+ console.log(chalk.gray('\nNot: Slack botunuzu Slack App settings\'ten yapılandırmanız gerekiyor.'));
65
+ console.log(chalk.gray('Token config\'e kaydedildi: ~/.natureco/config.json\n'));
66
+ }
67
+
68
+ async function disconnectSlack() {
69
+ const config = getConfig();
70
+
71
+ if (!config.slackToken) {
72
+ console.log(chalk.gray('\n⚠️ No Slack connection found\n'));
73
+ return;
74
+ }
75
+
76
+ process.stdin.resume();
77
+
78
+ const { confirm } = await inquirer.prompt([
79
+ {
80
+ type: 'confirm',
81
+ name: 'confirm',
82
+ message: 'Are you sure you want to disconnect Slack?',
83
+ default: false,
84
+ },
85
+ ]);
86
+
87
+ if (!confirm) {
88
+ console.log(chalk.gray('\nCancelled\n'));
89
+ return;
90
+ }
91
+
92
+ // Remove from config
93
+ delete config.slackToken;
94
+ delete config.slackBotId;
95
+ saveConfig(config);
96
+
97
+ console.log(chalk.green('\n✅ Slack disconnected\n'));
98
+ console.log(chalk.gray('Note: The bot is still registered on Slack.'));
99
+ console.log(chalk.gray('You may need to manually remove it from Slack App settings.\n'));
100
+ }
101
+
102
+ function statusSlack() {
103
+ const config = getConfig();
104
+
105
+ if (!config.slackToken) {
106
+ console.log(chalk.gray('\n⚠️ Slack not connected\n'));
107
+ console.log(chalk.gray('Connect with: natureco slack connect\n'));
108
+ return;
109
+ }
110
+
111
+ console.log(chalk.green('\n✅ Slack connected\n'));
112
+ console.log(chalk.cyan('Token:'), chalk.white(config.slackToken.slice(0, 20) + '...'));
113
+
114
+ if (config.slackBotId) {
115
+ console.log(chalk.cyan('Bot ID:'), chalk.white(config.slackBotId));
116
+ }
117
+
118
+ console.log(chalk.gray('\nDisconnect with: natureco slack disconnect\n'));
119
+ }
120
+
121
+ module.exports = slack;