thinkncollab-shell 0.0.4 → 0.0.6
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/Readme.md +392 -16
- package/package.json +1 -1
- package/src/commands/auth/login.js +58 -58
- package/src/commands/auth/register.js +52 -0
- package/src/commands/index.js +62 -43
- package/src/commands/room/join.js +119 -45
- package/src/commands/shell/notify.js +88 -0
- package/src/commands/tasks/complete.js +47 -0
- package/src/commands/tasks/create-task.js +101 -0
- package/src/commands/tasks/suggestTask.js +0 -0
- package/src/commands/tasks/task.js +75 -0
- package/src/commands/tasks/tasks.js +74 -0
- package/src/commands/terminal/share.js +252 -0
- package/src/core/api-client.js +104 -50
- package/src/core/notification-window.js +2 -1
- package/src/core/project-config.js +100 -0
- package/src/core/shell.js +222 -210
- package/src/core/websocket.js +166 -101
package/Readme.md
CHANGED
|
@@ -1,26 +1,402 @@
|
|
|
1
|
-
# ThinkNCollab Shell
|
|
1
|
+
# ThinkNCollab Shell (`thinknsh`)
|
|
2
2
|
|
|
3
|
-
A powerful collaborative shell with WebSocket integration for real-time team collaboration.
|
|
3
|
+
A powerful collaborative shell with WebSocket integration for real-time team collaboration — built on top of the ThinkNCollab platform.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Features](#features)
|
|
10
|
+
- [Installation](#installation)
|
|
11
|
+
- [Quick Start](#quick-start)
|
|
12
|
+
- [Configuration](#configuration)
|
|
13
|
+
- [CLI Flags](#cli-flags)
|
|
14
|
+
- [Interactive Shell](#interactive-shell)
|
|
15
|
+
- [Commands Reference](#commands-reference)
|
|
16
|
+
- [Auth Commands](#auth-commands)
|
|
17
|
+
- [Team Commands](#team-commands)
|
|
18
|
+
- [Room Commands](#room-commands)
|
|
19
|
+
- [Message Commands](#message-commands)
|
|
20
|
+
- [Shell Commands](#shell-commands)
|
|
21
|
+
- [Single-Command Mode](#single-command-mode)
|
|
22
|
+
- [Built-in Shell Features](#built-in-shell-features)
|
|
23
|
+
- [Examples](#examples)
|
|
24
|
+
- [Environment Variables](#environment-variables)
|
|
25
|
+
|
|
26
|
+
---
|
|
4
27
|
|
|
5
28
|
## Features
|
|
6
29
|
|
|
7
|
-
- 🚀 **Custom Shell**
|
|
8
|
-
- 🔌 **WebSocket Integration**
|
|
9
|
-
- 👥 **Room Collaboration**
|
|
10
|
-
- 💬 **Messaging**
|
|
11
|
-
- 🔔 **Notifications**
|
|
12
|
-
- 📁 **File System**
|
|
13
|
-
- ⚡ **Command System**
|
|
14
|
-
- 🔧 **Aliases**
|
|
15
|
-
- 📊 **Variables**
|
|
16
|
-
- 📜 **History**
|
|
17
|
-
- 🎨 **Colored Output**
|
|
30
|
+
- 🚀 **Custom Shell** — Full-featured interactive command-line interface
|
|
31
|
+
- 🔌 **WebSocket Integration** — Real-time communication with ThinkNCollab servers
|
|
32
|
+
- 👥 **Room Collaboration** — Join rooms and collaborate with teammates live
|
|
33
|
+
- 💬 **Messaging** — Send and receive messages in real-time
|
|
34
|
+
- 🔔 **Notifications** — Get notified of tasks, uploads, and room events
|
|
35
|
+
- 📁 **File System** — Built-in file system commands (ls, cd, pwd, cat, mkdir)
|
|
36
|
+
- ⚡ **Command System** — Extensible command registration by category
|
|
37
|
+
- 🔧 **Aliases** — Create and manage custom command shortcuts
|
|
38
|
+
- 📊 **Variables** — Shell variable support (`set`, `$VAR`)
|
|
39
|
+
- 📜 **History** — Persistent command history across sessions
|
|
40
|
+
- 🎨 **Colored Output** — Beautiful chalk-powered terminal output
|
|
41
|
+
|
|
42
|
+
---
|
|
18
43
|
|
|
19
44
|
## Installation
|
|
20
45
|
|
|
21
46
|
```bash
|
|
22
|
-
# Install globally
|
|
47
|
+
# Install globally (recommended)
|
|
23
48
|
npm install -g thinkncollab-shell
|
|
24
49
|
|
|
25
|
-
# Or install locally
|
|
26
|
-
npm install thinkncollab-shell
|
|
50
|
+
# Or install locally in a project
|
|
51
|
+
npm install thinkncollab-shell
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
After global install, the `thinknsh` binary is available everywhere on your system.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Quick Start
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# 1. Start the interactive shell
|
|
62
|
+
thinknsh
|
|
63
|
+
|
|
64
|
+
# 2. Log in to your ThinkNCollab account
|
|
65
|
+
thinknsh> login
|
|
66
|
+
|
|
67
|
+
# 3. Join a room
|
|
68
|
+
thinknsh> join my-room
|
|
69
|
+
|
|
70
|
+
# 4. Send a message
|
|
71
|
+
thinknsh> say Hello team!
|
|
72
|
+
|
|
73
|
+
# 5. Check your status
|
|
74
|
+
thinknsh> status
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Configuration
|
|
80
|
+
|
|
81
|
+
By default `thinknsh` connects to `https://thinkncollab.com`. In production, set environment variables before starting the shell:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
export THINKNCOLLAB_SERVER=https://thinkncollab.com
|
|
85
|
+
export THINKNCOLLAB_API_URL=https://thinkncollab.com
|
|
86
|
+
export THINKNCOLLAB_WS_URL=https://thinkncollab.com
|
|
87
|
+
thinknsh
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Or inline for a single session:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
THINKNCOLLAB_SERVER=https://thinkncollab.com thinknsh
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## CLI Flags
|
|
99
|
+
|
|
100
|
+
These flags are used **before** entering the interactive shell (passed directly to the `thinknsh` binary).
|
|
101
|
+
|
|
102
|
+
| Flag | Alias | Description |
|
|
103
|
+
|------|-------|-------------|
|
|
104
|
+
| `--help` | `-h` | Show help message and exit |
|
|
105
|
+
| `--version` | `-v` | Print the installed version and exit |
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
thinknsh --help
|
|
109
|
+
thinknsh --version
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Interactive Shell
|
|
115
|
+
|
|
116
|
+
Running `thinknsh` with no arguments starts the **interactive shell** — a persistent REPL where you stay logged in, maintain a WebSocket connection, and run commands one after another.
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
$ thinknsh
|
|
120
|
+
|
|
121
|
+
████████╗██╗ ██╗██╗███╗ ██╗██╗ ██╗███╗ ██╗
|
|
122
|
+
╚══██╔╝██║ ██║██║████╗ ██║██║ ██╔╝████╗ ██║
|
|
123
|
+
██║ ███████║██║██╔██╗ ██║█████╔╝ ██╔██╗ ██║
|
|
124
|
+
██║ ██╔══██║██║██║╚██╗██║██╔═██╗ ██║╚██╗██║
|
|
125
|
+
██║ ██║ ██║██║██║ ╚████║██║ ██╗██║ ╚████║
|
|
126
|
+
╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝╚═╝ ╚═══╝
|
|
127
|
+
|
|
128
|
+
thinknsh> _
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Type `help` inside the shell to list all available commands at any time.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Commands Reference
|
|
136
|
+
|
|
137
|
+
### Auth Commands
|
|
138
|
+
|
|
139
|
+
#### `login`
|
|
140
|
+
Authenticate with your ThinkNCollab account. Prompts for email and password interactively.
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
thinknsh> login
|
|
144
|
+
# Enter your email: you@example.com
|
|
145
|
+
# Enter your password: ********
|
|
146
|
+
# ✅ Logged in as you@example.com
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### `logout`
|
|
150
|
+
End your current session and clear saved credentials.
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
thinknsh> logout
|
|
154
|
+
# ✅ Logged out successfully
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
#### `whoami`
|
|
158
|
+
Display information about the currently authenticated user.
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
thinknsh> whoami
|
|
162
|
+
# 👤 Logged in as: Ramanh (raman@thinkncollab.com)
|
|
163
|
+
# 🏢 Team: ThinkNCollab Core
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
### Team Commands
|
|
169
|
+
|
|
170
|
+
#### `myteam`
|
|
171
|
+
Show details about your current team — name, plan, member count.
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
thinknsh> myteam
|
|
175
|
+
# 🏢 Team: ThinkNCollab Core
|
|
176
|
+
# 📋 Plan: Pro
|
|
177
|
+
# 👥 Members: 8
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### `teammates`
|
|
181
|
+
List all members in your team with their online status.
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
thinknsh> teammates
|
|
185
|
+
# 👥 Team Members:
|
|
186
|
+
# 🟢 Raman Singh (you)
|
|
187
|
+
# 🟢 Omkar Yadav
|
|
188
|
+
# 🔴 Radhika Chauhan (offline)
|
|
189
|
+
# 🟡 -------------- (away)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
#### `invite <email>`
|
|
193
|
+
Send a team invitation to an email address.
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
thinknsh> invite newmember@example.com
|
|
197
|
+
# ✅ Invitation sent to newmember@example.com
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
### Room Commands
|
|
203
|
+
|
|
204
|
+
#### `join <room-id>`
|
|
205
|
+
Join a collaboration room. Establishes a WebSocket connection and streams live activity.
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
thinknsh> join room-abc123
|
|
209
|
+
# 🚪 Joined room: room-abc123
|
|
210
|
+
# 👥 Members online: 3
|
|
211
|
+
# 📜 Recent activity loaded
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
You will automatically receive real-time notifications for messages, task updates, and file uploads while inside a room.
|
|
215
|
+
|
|
216
|
+
#### `leave`
|
|
217
|
+
Leave the currently active room and disconnect from its WebSocket stream.
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
thinknsh> leave
|
|
221
|
+
# 👋 Left room: room-abc123
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### `rooms`
|
|
225
|
+
List all rooms available to you — showing name, ID, and member count.
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
thinknsh> rooms
|
|
229
|
+
# 📁 Your Rooms:
|
|
230
|
+
# [1] frontend-team (ID: room-abc123) 👥 4 members
|
|
231
|
+
# [2] backend-infra (ID: room-def456) 👥 2 members
|
|
232
|
+
# [3] design-review (ID: room-ghi789) 👥 6 members
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
### Message Commands
|
|
238
|
+
|
|
239
|
+
#### `say <message>`
|
|
240
|
+
Send a message to the room you are currently in. Requires you to be in a room (use `join` first).
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
thinknsh> say Hey team, PR is ready for review!
|
|
244
|
+
# 💬 [You → frontend-team]: Hey team, PR is ready for review!
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Supports multi-word messages — no quotes needed.
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
thinknsh> say Pushing the hotfix now, give me 5 minutes
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
### Shell Commands
|
|
256
|
+
|
|
257
|
+
#### `status`
|
|
258
|
+
Show a full overview of your current shell session: auth status, active room, WebSocket connection, server URL, and version.
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
thinknsh> status
|
|
262
|
+
# ──────────────────────────────────────
|
|
263
|
+
# ThinkNCollab Shell — Session Status
|
|
264
|
+
# ──────────────────────────────────────
|
|
265
|
+
# User : Raman Singh
|
|
266
|
+
# Email : raman@example.com
|
|
267
|
+
# Server : https://app.thinkncollab.com
|
|
268
|
+
# WebSocket : ✅ Connected
|
|
269
|
+
# Active Room: frontend-team (room-abc123)
|
|
270
|
+
# Version : 1.2.0
|
|
271
|
+
# ──────────────────────────────────────
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
#### `help`
|
|
275
|
+
List all registered commands grouped by category, with descriptions.
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
thinknsh> help
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
#### `clear`
|
|
282
|
+
Clear the terminal screen.
|
|
283
|
+
|
|
284
|
+
```bash
|
|
285
|
+
thinknsh> clear
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
#### `exit` / `quit`
|
|
289
|
+
Exit the interactive shell gracefully.
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
thinknsh> exit
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## Single-Command Mode
|
|
298
|
+
|
|
299
|
+
You can run **any command as a one-liner** without entering the interactive shell. The shell executes the command and exits immediately — great for scripting or CI pipelines.
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
thinknsh status
|
|
303
|
+
thinknsh whoami
|
|
304
|
+
thinknsh join room-abc123
|
|
305
|
+
thinknsh say "Deployment complete ✅"
|
|
306
|
+
thinknsh rooms
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Multi-word commands work naturally:
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
thinknsh say Build passed. Deploying to staging now.
|
|
313
|
+
thinknsh invite contractor@example.com
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## Built-in Shell Features
|
|
319
|
+
|
|
320
|
+
### Command History
|
|
321
|
+
The interactive shell remembers your previously run commands across sessions. Use the **Up/Down arrow keys** to navigate history.
|
|
322
|
+
|
|
323
|
+
### Aliases
|
|
324
|
+
Create shortcuts for frequently used commands:
|
|
325
|
+
|
|
326
|
+
```bash
|
|
327
|
+
thinknsh> alias fe="join room-abc123"
|
|
328
|
+
thinknsh> fe # runs: join room-abc123
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Shell Variables
|
|
332
|
+
Set and use variables within the shell:
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
thinknsh> set ROOM=room-abc123
|
|
336
|
+
thinknsh> join $ROOM
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### Tab Completion
|
|
340
|
+
Press `Tab` to autocomplete commands and room names.
|
|
341
|
+
|
|
342
|
+
### Piping & Chaining (Single-command mode)
|
|
343
|
+
Chain commands using `&&` in your terminal:
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
thinknsh login && thinknsh join room-abc123 && thinknsh status
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## Examples
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
# Check who you are
|
|
355
|
+
thinknsh whoami
|
|
356
|
+
|
|
357
|
+
# See all your rooms, then join one
|
|
358
|
+
thinknsh rooms
|
|
359
|
+
thinknsh join room-abc123
|
|
360
|
+
|
|
361
|
+
# Send a quick message without opening the shell
|
|
362
|
+
thinknsh say "Hotfix deployed to production"
|
|
363
|
+
|
|
364
|
+
# Invite a new member
|
|
365
|
+
thinknsh invite dev@company.com
|
|
366
|
+
|
|
367
|
+
# Full interactive session
|
|
368
|
+
thinknsh
|
|
369
|
+
thinknsh> login
|
|
370
|
+
thinknsh> rooms
|
|
371
|
+
thinknsh> join frontend-team
|
|
372
|
+
thinknsh> say Good morning everyone 🚀
|
|
373
|
+
thinknsh> teammates
|
|
374
|
+
thinknsh> status
|
|
375
|
+
thinknsh> exit
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## Environment Variables
|
|
381
|
+
|
|
382
|
+
| Variable | Default | Description |
|
|
383
|
+
|----------|---------|-------------|
|
|
384
|
+
| `THINKNCOLLAB_SERVER` | `https://thinkncollab.com` | Main server URL (REST + WebSocket base) |
|
|
385
|
+
| `THINKNCOLLAB_API_URL` | `https://thinkncollab.com` | REST API base URL (overrides SERVER for API calls) |
|
|
386
|
+
| `THINKNCOLLAB_WS_URL` | `https://thinkncollab.com` | WebSocket server URL |
|
|
387
|
+
| `THINKNCOLLAB_AUTO_CONNECT` | `false` | Set to `true` to auto-connect WebSocket on shell start |
|
|
388
|
+
|
|
389
|
+
In production, all three URL variables typically point to the same host:
|
|
390
|
+
|
|
391
|
+
```bash
|
|
392
|
+
export THINKNCOLLAB_SERVER=https://app.thinkncollab.com
|
|
393
|
+
export THINKNCOLLAB_API_URL=https://app.thinkncollab.com
|
|
394
|
+
export THINKNCOLLAB_WS_URL=https://app.thinkncollab.com
|
|
395
|
+
export THINKNCOLLAB_AUTO_CONNECT=true
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## License
|
|
401
|
+
|
|
402
|
+
MIT © ThinkNCollab
|
package/package.json
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* commands/auth/login.js
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const chalk = require('chalk');
|
|
6
|
+
const inquirer = require('inquirer');
|
|
4
7
|
|
|
5
8
|
module.exports = {
|
|
6
|
-
name:
|
|
7
|
-
description:
|
|
8
|
-
aliases:
|
|
9
|
+
name: 'login',
|
|
10
|
+
description: 'Login to ThinkNCollab',
|
|
11
|
+
aliases: ['signin'],
|
|
9
12
|
requiresAuth: false,
|
|
10
13
|
|
|
11
14
|
async execute(args, shell) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} else if (args.length >= 2) {
|
|
21
|
-
email = args[0];
|
|
22
|
-
password = args[1];
|
|
23
|
-
} else {
|
|
24
|
-
console.log(chalk.red('❌ Usage: login <email> <password>'));
|
|
25
|
-
console.log(chalk.dim(' or: login (interactive)'));
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (!email || !password) {
|
|
30
|
-
console.log(chalk.red('❌ Email and password required'));
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
15
|
+
// Already logged in?
|
|
16
|
+
if (shell.api.isAuthenticated()) {
|
|
17
|
+
const u = shell.api.getUser();
|
|
18
|
+
console.log(chalk.green(`✅ Already logged in as ${u.name} (${u.email})`));
|
|
19
|
+
console.log(chalk.dim(' Run "logout" first to switch accounts.'));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
33
22
|
|
|
34
|
-
|
|
23
|
+
// Collect credentials
|
|
24
|
+
let email = args[0];
|
|
25
|
+
let password = args[1];
|
|
26
|
+
|
|
27
|
+
if (!email || !password) {
|
|
28
|
+
const answers = await inquirer.prompt([
|
|
29
|
+
!email && { type: 'input', name: 'email', message: 'Email:', validate: v => v.includes('@') || 'Enter a valid email' },
|
|
30
|
+
!password && { type: 'password', name: 'password', message: 'Password:', mask: '*', validate: v => v.length >= 1 || 'Password required' },
|
|
31
|
+
].filter(Boolean));
|
|
32
|
+
email = email || answers.email;
|
|
33
|
+
password = password || answers.password;
|
|
34
|
+
}
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
console.log(chalk.blue('🔐 Logging in...'));
|
|
37
37
|
|
|
38
|
+
try {
|
|
38
39
|
const result = await shell.api.login(email, password);
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// Join personal notification room (for task assignments etc.)
|
|
62
|
-
shell.ws.joinUserRoom(userId);
|
|
63
|
-
|
|
64
|
-
console.log(chalk.green('🔌 Connected to ThinkNCollab server'));
|
|
65
|
-
} catch (wsErr) {
|
|
66
|
-
console.log(chalk.yellow(`⚠️ Could not connect to server: ${wsErr.message}`));
|
|
41
|
+
// result.user is already normalised by api-client.getUser()
|
|
42
|
+
// shape: { _id, userId, email, name, userType }
|
|
43
|
+
const user = result.user;
|
|
44
|
+
|
|
45
|
+
// ★ Tell the WebSocket manager who the user is + pass the token
|
|
46
|
+
// This must happen BEFORE any join attempt
|
|
47
|
+
shell.ws.setUser(user, result.token);
|
|
48
|
+
|
|
49
|
+
// Connect WebSocket if not already connected
|
|
50
|
+
if (!shell.ws.isConnected()) {
|
|
51
|
+
try {
|
|
52
|
+
await shell.ws.connect(result.token);
|
|
53
|
+
console.log(chalk.dim(' 🔌 Connected to ThinkNCollab server'));
|
|
54
|
+
} catch (wsErr) {
|
|
55
|
+
// Non-fatal — user can still use REST commands
|
|
56
|
+
console.log(chalk.yellow(` ⚠️ WebSocket unavailable: ${wsErr.message}`));
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
// Already connected — re-announce with new user identity
|
|
60
|
+
shell.ws._announceUser?.();
|
|
67
61
|
}
|
|
68
62
|
|
|
63
|
+
console.log(chalk.green(`✅ Welcome, ${user.name}!`));
|
|
64
|
+
console.log(chalk.dim(` Logged in as ${user.email}`));
|
|
65
|
+
|
|
69
66
|
} catch (err) {
|
|
70
|
-
if (err.
|
|
71
|
-
|
|
67
|
+
if (err.message.includes('401') || err.message.toLowerCase().includes('invalid') ||
|
|
68
|
+
err.message.toLowerCase().includes('unauthorized')) {
|
|
69
|
+
console.log(chalk.red('❌ Invalid email or password'));
|
|
70
|
+
} else if (err.message.includes('connect') || err.message.includes('ECONNREFUSED')) {
|
|
71
|
+
console.log(chalk.red(`❌ Cannot reach server — is it running?`));
|
|
72
72
|
} else {
|
|
73
73
|
console.log(chalk.red(`❌ Login failed: ${err.message}`));
|
|
74
74
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/commands/auth/register.js
|
|
3
|
+
* Register new account — opens browser with pre-auth session
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const chalk = require('chalk');
|
|
7
|
+
const { exec } = require('child_process');
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
name: 'register',
|
|
11
|
+
description: 'Create a new ThinkNCollab account',
|
|
12
|
+
aliases: ['signup', 'reg'],
|
|
13
|
+
requiresAuth: false,
|
|
14
|
+
|
|
15
|
+
async execute(args, shell) {
|
|
16
|
+
try {
|
|
17
|
+
console.log(chalk.cyan('🌐 Opening registration in browser...'));
|
|
18
|
+
|
|
19
|
+
const baseUrl = shell.api.apiUrl || 'http://localhost:3001';
|
|
20
|
+
|
|
21
|
+
// Generate a CLI source token so backend knows it came from terminal
|
|
22
|
+
const crypto = require('crypto');
|
|
23
|
+
const cliRef = crypto.randomBytes(8).toString('hex');
|
|
24
|
+
|
|
25
|
+
const url = `${baseUrl}/register?ref=cli&cliRef=${cliRef}`;
|
|
26
|
+
|
|
27
|
+
// Open browser cross-platform
|
|
28
|
+
const openCmd = process.platform === 'win32'
|
|
29
|
+
? `start "" "${url}"`
|
|
30
|
+
: process.platform === 'darwin'
|
|
31
|
+
? `open "${url}"`
|
|
32
|
+
: `xdg-open "${url}"`;
|
|
33
|
+
|
|
34
|
+
exec(openCmd, (err) => {
|
|
35
|
+
if (err) {
|
|
36
|
+
console.log(chalk.yellow('⚠️ Could not open browser automatically.'));
|
|
37
|
+
console.log(chalk.dim(' Open this URL manually:'));
|
|
38
|
+
console.log(chalk.cyan(` ${url}`));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
console.log(chalk.green(`✅ Registration page opened!`));
|
|
43
|
+
console.log(chalk.dim(` URL: ${url}`));
|
|
44
|
+
console.log('');
|
|
45
|
+
console.log(chalk.dim(' After registering, come back and run:'));
|
|
46
|
+
console.log(chalk.cyan(' login'));
|
|
47
|
+
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.log(chalk.red(`❌ Error: ${err.message}`));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|