thinkncollab-cli 0.0.84 → 0.0.85

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/bin/index.js CHANGED
@@ -18,6 +18,8 @@ import machine from "node-machine-id";
18
18
  import push from "../commands/push.js";
19
19
  import taskCompletion from "../commands/taskCompletion.js";
20
20
  import task from "../commands/task.js";
21
+ import createTask from "../commands/createTask.js";
22
+ import myTeam from "../commands/myTeam.js";
21
23
 
22
24
 
23
25
 
@@ -188,6 +190,17 @@ case "my-tasks": {
188
190
  await myTask();
189
191
  break;
190
192
  }
193
+ case "create-task": {
194
+ const roomIdx = args.indexOf("create-task");
195
+
196
+
197
+ await createTask();
198
+ break;
199
+ }
200
+ case "send": {
201
+ await send();
202
+ break;
203
+ }
191
204
  case "invite": {
192
205
  const roomIdx = args.indexOf("invite");
193
206
  if (roomIdx === -1 || !args[roomIdx + 1]) {
@@ -204,6 +217,11 @@ case "task": {
204
217
  break;
205
218
  }
206
219
 
220
+ case "myteam": {
221
+ myTeam();
222
+ break;
223
+ }
224
+
207
225
  case "signout": {
208
226
  await DAPP();
209
227
  break;
@@ -0,0 +1,260 @@
1
+ import axios from "axios";
2
+ import fs from "fs";
3
+ import os from "os";
4
+ import path from "path";
5
+ import machine from "node-machine-id";
6
+ import chalk from "chalk";
7
+ import { fileURLToPath } from 'url';
8
+ import open from 'open';
9
+ import http from 'http';
10
+
11
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
12
+ const getVerifyModule = await import("../lib/getVerify.js");
13
+ const getVerify = getVerifyModule.default;
14
+ const { token } = await getVerify();
15
+
16
+ const CWD = process.cwd();
17
+ const tncmetaPath = path.join(CWD, ".tnc", ".tncmeta.json");
18
+ const fileData = fs.existsSync(tncmetaPath) ? JSON.parse(fs.readFileSync(tncmetaPath, "utf-8")) : null;
19
+ const roomId = fileData?.roomId || null;
20
+
21
+ function createSpinner(message) {
22
+ const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
23
+ let i = 0;
24
+
25
+ const spinner = setInterval(() => {
26
+ process.stdout.write(`\r${chalk.cyan(frames[i])} ${message}`);
27
+ i = (i + 1) % frames.length;
28
+ }, 80);
29
+
30
+ return {
31
+ stop: (clearMessage = true) => {
32
+ clearInterval(spinner);
33
+ if (clearMessage) {
34
+ process.stdout.write('\r' + ' '.repeat(process.stdout.columns || 50) + '\r');
35
+ }
36
+ },
37
+ update: (newMessage) => {
38
+ message = newMessage;
39
+ }
40
+ };
41
+ }
42
+
43
+ async function createTask() {
44
+ try {
45
+ console.log(chalk.blue('\n🚀 Task Creation CLI\n'));
46
+
47
+ // Validate roomId and token
48
+ if (!roomId) {
49
+ console.error(chalk.red('❌ No roomId found in .tnc/.tncmeta.json'));
50
+ console.log(chalk.yellow('Please ensure you are in a ThinkNCollab project directory'));
51
+ return;
52
+ }
53
+
54
+ if (!token) {
55
+ console.error(chalk.red('❌ No token found'));
56
+ console.log(chalk.yellow('Please login first using: tnc login'));
57
+ return;
58
+ }
59
+
60
+ // console.log(chalk.green(`✅ Room ID: ${roomId}`));
61
+ // console.log(chalk.green(`✅ Token: ${token.substring(0, 10)}...${token.substring(token.length - 10)}\n`));
62
+
63
+ // Construct the URL with CLI flag
64
+ const redirectUrl = `https://thinkncollab.in/cli/tasks/${roomId}/${token}/create?cli=true`;
65
+
66
+ const spinner = createSpinner('Preparing task creation interface...');
67
+
68
+ console.log(chalk.blue('🔗 Opening task creation interface in your browser...'));
69
+ console.log(chalk.gray(`URL: ${redirectUrl}`));
70
+
71
+ // Find available port
72
+ const PORT = await findAvailablePort(3002);
73
+ spinner.stop();
74
+
75
+ // Create callback server
76
+ // Create callback server with better CORS and request handling
77
+ const server = http.createServer((req, res) => {
78
+ console.log(chalk.yellow(`\n📨 Callback received: ${req.url}`));
79
+
80
+ // CORS headers for all responses
81
+ res.setHeader('Access-Control-Allow-Origin', '*');
82
+ res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
83
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type, X-CLI-Callback-URL');
84
+ res.setHeader('Access-Control-Max-Age', '86400'); // 24 hours
85
+
86
+ // Handle preflight
87
+ if (req.method === 'OPTIONS') {
88
+ res.writeHead(200);
89
+ res.end();
90
+ return;
91
+ }
92
+
93
+ // Parse URL
94
+ const url = new URL(req.url, `http://localhost:${PORT}`);
95
+
96
+ // Check for callback (handle both /callback and direct query params)
97
+ if (req.url.includes('/callback') || url.searchParams.has('taskId')) {
98
+ const taskId = url.searchParams.get('taskId');
99
+ const attachments = url.searchParams.get('attachments');
100
+ const status = url.searchParams.get('status');
101
+
102
+ // Log success
103
+ if (status === 'error') {
104
+ console.log(chalk.red('\n❌ Task creation failed!'));
105
+ } else {
106
+ console.log(chalk.green('\n✅ Task created successfully!'));
107
+ if (taskId) {
108
+ console.log(chalk.blue(`📋 Task ID: ${taskId}`));
109
+
110
+ // Save task ID to file
111
+ const taskMetaPath = path.join(CWD, ".tnc", "last-task.json");
112
+ fs.writeFileSync(taskMetaPath, JSON.stringify({
113
+ taskId,
114
+ attachments: attachments ? attachments.length : 0,
115
+ timestamp: new Date().toISOString(),
116
+ roomId
117
+ }, null, 2));
118
+ console.log(chalk.gray(`📝 Task ID saved to .tnc/last-task.json`));
119
+ }
120
+ if (attachments) {
121
+ // console.log(chalk.blue(`📎 Attachments: ${attachments}`));
122
+ }
123
+ }
124
+
125
+ // Send response to close browser (HTML with auto-close)
126
+ res.writeHead(200, {
127
+ 'Content-Type': 'text/html',
128
+ 'Access-Control-Allow-Origin': '*'
129
+ });
130
+ res.end(`
131
+ <!DOCTYPE html>
132
+ <html>
133
+ <head>
134
+ <title>${status === 'error' ? 'Failed' : 'Success'}</title>
135
+ <style>
136
+ body {
137
+ font-family: Arial, sans-serif;
138
+ display: flex;
139
+ justify-content: center;
140
+ align-items: center;
141
+ height: 100vh;
142
+ margin: 0;
143
+ background: ${status === 'error' ? '#f44336' : '#4CAF50'};
144
+ color: white;
145
+ }
146
+ .message {
147
+ text-align: center;
148
+ padding: 20px;
149
+ }
150
+ </style>
151
+ </head>
152
+ <body>
153
+ <div class="message">
154
+ <h1>${status === 'error' ? '❌ Task Failed' : '✅ Task Created'}</h1>
155
+ ${taskId ? `<p>Task ID: ${taskId}</p>` : ''}
156
+ <p>Closing in 3 seconds...</p>
157
+ </div>
158
+ <script>
159
+ // Send one more callback to ensure it was received
160
+ fetch(window.location.href, { method: 'GET', mode: 'no-cors' });
161
+
162
+ // Auto close
163
+ setTimeout(() => window.close(), 3000);
164
+
165
+ // Fallback
166
+ setTimeout(() => {
167
+ window.location.href = 'about:blank';
168
+ setTimeout(() => window.close(), 100);
169
+ }, 4000);
170
+ </script>
171
+ </body>
172
+ </html>
173
+ `);
174
+
175
+ // Close server after response
176
+ setTimeout(() => {
177
+ server.close();
178
+ console.log(chalk.gray('\n📡 Callback server closed'));
179
+ process.exit(0);
180
+ }, 2000);
181
+ } else {
182
+ // Handle other requests (like favicon)
183
+ res.writeHead(404);
184
+ res.end('Not found');
185
+ }
186
+ });
187
+
188
+ // Server error handling
189
+ server.on('error', (err) => {
190
+ if (err.code === 'EADDRINUSE') {
191
+ console.log(chalk.yellow(`⚠️ Port ${PORT} is already in use. Callback might not work.`));
192
+ console.log(chalk.yellow('The task will still be created, but you may need to check manually.'));
193
+ } else {
194
+ console.error(chalk.red('Server error:'), err.message);
195
+ }
196
+ });
197
+
198
+ // Start server
199
+ server.listen(PORT, () => {
200
+ // console.log(chalk.gray(`📡 Waiting for callback on http://localhost:${PORT}/callback`));
201
+ // console.log(chalk.gray('The browser will automatically close after task creation\n'));
202
+ });
203
+
204
+ // Open browser
205
+ setTimeout(async () => {
206
+ try {
207
+ await open(redirectUrl);
208
+ // console.log(chalk.green('✅ Browser opened successfully!'));
209
+ } catch (err) {
210
+ if (err.message.includes('No application')) {
211
+ console.error(chalk.red('❌ Could not open browser automatically.'));
212
+ console.log(chalk.yellow('Please manually open this URL in your browser:'));
213
+ console.log(chalk.cyan(redirectUrl));
214
+ } else {
215
+ console.error(chalk.red('Browser error:'), err.message);
216
+ }
217
+ }
218
+ }, 500);
219
+
220
+ // Wait for callback or timeout
221
+ await new Promise((resolve) => {
222
+ const timeout = setTimeout(() => {
223
+ console.log(chalk.yellow('\n⚠️ No callback received within 5 minutes.'));
224
+ console.log(chalk.gray('Your task may have been created successfully.'));
225
+ console.log(chalk.gray('Check your browser to confirm.'));
226
+ server.close();
227
+ resolve();
228
+ }, 300000); // 5 minutes
229
+
230
+ server.on('close', () => {
231
+ clearTimeout(timeout);
232
+ resolve();
233
+ });
234
+ });
235
+
236
+ } catch (err) {
237
+ console.error(chalk.red("❌ An unexpected error occurred:"), err.message);
238
+ }
239
+ }
240
+
241
+ // Helper function to find available port
242
+ async function findAvailablePort(startPort) {
243
+ const net = await import('net');
244
+ return new Promise((resolve, reject) => {
245
+ const server = net.createServer();
246
+ server.listen(startPort, () => {
247
+ const port = server.address().port;
248
+ server.close(() => resolve(port));
249
+ });
250
+ server.on('error', (err) => {
251
+ if (err.code === 'EADDRINUSE') {
252
+ resolve(findAvailablePort(startPort + 1));
253
+ } else {
254
+ reject(err);
255
+ }
256
+ });
257
+ });
258
+ }
259
+
260
+ export default createTask;
@@ -0,0 +1,44 @@
1
+ import axios from "axios";
2
+ import fs from "fs";
3
+ import os from "os";
4
+ import path from "path";
5
+ import machine from "node-machine-id";
6
+ import chalk from "chalk";
7
+ import FormData from "form-data";
8
+ import getVerify from "../lib/getVerify.js";
9
+
10
+ const CWD = process.cwd();
11
+ const TNC_API_URL = "http://localhost:3001/";
12
+ const metaDataFile = path.join(CWD, ".tnc", ".tncmeta.json");
13
+ const metaData = JSON.parse(fs.readFileSync(metaDataFile, "utf-8"));
14
+ const roomId = metaData.roomId;
15
+
16
+ async function myTeam() {
17
+ try {
18
+ const verifyData = await getVerify();
19
+ const { email, token } = verifyData;
20
+ const response = await axios.get(`${TNC_API_URL}cli/myTeam/${roomId}`, {
21
+ headers: {
22
+ email,
23
+ token,
24
+ machineId: machine.machineIdSync(),
25
+ },
26
+ });
27
+ const teamMembers = response.data.RoomMembers || [];
28
+ if (teamMembers.length === 0) {
29
+ console.log(chalk.yellow("⚠️ You are not part of any team yet."));
30
+ return;
31
+ }
32
+ console.log(chalk.green("👥 Your Team Members:"))
33
+ teamMembers.forEach(member => {
34
+ console.log(chalk.blue(`- ${member.name} (${member.email})`));
35
+ });
36
+ } catch (err) {
37
+ if (err.response) {
38
+ console.error(chalk.red("❌ Error:"), chalk.red(err.response.data.error));
39
+ } else {
40
+ console.error(chalk.red("❌ Error:"), chalk.red(err.message));
41
+ }
42
+ }
43
+ }
44
+ export default myTeam;
@@ -0,0 +1,16 @@
1
+ import axios from "axios"
2
+
3
+ let data = {
4
+
5
+ }
6
+
7
+ function sendData() {
8
+ const res = axios.post('http://172.16.44.215:5001/senddata',
9
+ {
10
+ "name": "Raman Singh",
11
+ "email": "admin@thinkncollab.com"
12
+ }
13
+ );
14
+
15
+ }
16
+ sendData();
package/commands/task.js CHANGED
@@ -44,7 +44,7 @@ async function task() {
44
44
 
45
45
  // API call (correct way using headers)
46
46
  const response = await axios.get(
47
- `http://localhost:3001/cli/task/${taskId.trim()}`,
47
+ `https://thinkncollab.com/cli/task/${taskId.trim()}`,
48
48
  {
49
49
  headers: {
50
50
  email,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "thinkncollab-cli",
3
3
  "author": "Raman Singh",
4
- "version": "0.0.84",
4
+ "version": "0.0.85",
5
5
  "description": "CLI tool for ThinkNCollab",
6
6
  "main": "index.js",
7
7
  "bin": {
@@ -15,7 +15,10 @@
15
15
  "axios": "^1.12.2",
16
16
  "chalk": "^5.6.2",
17
17
  "cli-table3": "^0.6.5",
18
- "inquirer": "^9.3.8",
19
- "node-machine-id": "^1.1.12"
18
+ "form-data": "^4.0.5",
19
+ "inquirer": "^8.2.5",
20
+ "inquirer-file-selector": "^1.0.1",
21
+ "node-machine-id": "^1.1.12",
22
+ "open": "^11.0.0"
20
23
  }
21
24
  }