stigmergy 1.0.97 → 1.0.99
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/package.json +1 -1
- package/src/auth.js +11 -11
- package/src/auth_command.js +19 -19
- package/src/calculator.js +11 -11
- package/src/core/cli_help_analyzer.js +108 -108
- package/src/core/cli_parameter_handler.js +22 -22
- package/src/core/cli_tools.js +45 -45
- package/src/core/error_handler.js +67 -67
- package/src/core/memory_manager.js +8 -8
- package/src/core/rest_client.js +13 -13
- package/src/core/smart_router.js +29 -29
- package/src/data_encryption.js +17 -17
- package/src/data_structures.js +17 -17
- package/src/deploy.js +12 -13
- package/src/index.js +1 -1
- package/src/main.js +275 -275
- package/src/main_english.js +583 -671
- package/src/utils.js +78 -79
- package/src/weatherProcessor.js +38 -38
- package/src/main_fixed.js +0 -1172
package/package.json
CHANGED
package/src/auth.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Provides user authentication functionality including password hashing and token management.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const crypto = require(
|
|
6
|
+
const crypto = require('crypto');
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Custom exception for authentication failures.
|
|
@@ -11,7 +11,7 @@ const crypto = require("crypto");
|
|
|
11
11
|
class AuthenticationError extends Error {
|
|
12
12
|
constructor(message) {
|
|
13
13
|
super(message);
|
|
14
|
-
this.name =
|
|
14
|
+
this.name = 'AuthenticationError';
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -38,15 +38,15 @@ class UserAuthenticator {
|
|
|
38
38
|
*/
|
|
39
39
|
registerUser(username, password) {
|
|
40
40
|
if (!username || !password) {
|
|
41
|
-
throw new Error(
|
|
41
|
+
throw new Error('Username and password cannot be empty');
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
if (username.length < 3) {
|
|
45
|
-
throw new Error(
|
|
45
|
+
throw new Error('Username must be at least 3 characters long');
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
if (password.length < 8) {
|
|
49
|
-
throw new Error(
|
|
49
|
+
throw new Error('Password must be at least 8 characters long');
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
if (this._users.has(username)) {
|
|
@@ -54,7 +54,7 @@ class UserAuthenticator {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
// Hash the password with a salt
|
|
57
|
-
const salt = crypto.randomBytes(16).toString(
|
|
57
|
+
const salt = crypto.randomBytes(16).toString('hex');
|
|
58
58
|
const passwordHash = this._hashPassword(password, salt);
|
|
59
59
|
|
|
60
60
|
this._users.set(username, {
|
|
@@ -75,18 +75,18 @@ class UserAuthenticator {
|
|
|
75
75
|
*/
|
|
76
76
|
authenticateUser(username, password) {
|
|
77
77
|
if (!this._users.has(username)) {
|
|
78
|
-
throw new AuthenticationError(
|
|
78
|
+
throw new AuthenticationError('Invalid username or password');
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
const userData = this._users.get(username);
|
|
82
82
|
const passwordHash = this._hashPassword(password, userData.salt);
|
|
83
83
|
|
|
84
84
|
if (passwordHash !== userData.passwordHash) {
|
|
85
|
-
throw new AuthenticationError(
|
|
85
|
+
throw new AuthenticationError('Invalid username or password');
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
// Generate session token
|
|
89
|
-
const sessionToken = crypto.randomBytes(32).toString(
|
|
89
|
+
const sessionToken = crypto.randomBytes(32).toString('base64url');
|
|
90
90
|
this._sessions.set(sessionToken, {
|
|
91
91
|
username: username,
|
|
92
92
|
createdAt: Date.now(),
|
|
@@ -139,9 +139,9 @@ class UserAuthenticator {
|
|
|
139
139
|
salt,
|
|
140
140
|
100000, // iterations
|
|
141
141
|
32, // key length
|
|
142
|
-
|
|
142
|
+
'sha256', // digest
|
|
143
143
|
)
|
|
144
|
-
.toString(
|
|
144
|
+
.toString('hex');
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
|
package/src/auth_command.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Provides CLI commands for user registration, login, and session management.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const fs = require(
|
|
7
|
-
const path = require(
|
|
8
|
-
const { UserAuthenticator, authenticateAndGetToken } = require(
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { UserAuthenticator, authenticateAndGetToken } = require('./auth');
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Get the path to the authentication data file.
|
|
@@ -13,14 +13,14 @@ const { UserAuthenticator, authenticateAndGetToken } = require("./auth");
|
|
|
13
13
|
*/
|
|
14
14
|
function getAuthDataPath() {
|
|
15
15
|
const homeDir = process.env.HOME || process.env.USERPROFILE;
|
|
16
|
-
const configDir = path.join(homeDir,
|
|
16
|
+
const configDir = path.join(homeDir, '.stigmergy');
|
|
17
17
|
|
|
18
18
|
// Create config directory if it doesn't exist
|
|
19
19
|
if (!fs.existsSync(configDir)) {
|
|
20
20
|
fs.mkdirSync(configDir, { recursive: true });
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
return path.join(configDir,
|
|
23
|
+
return path.join(configDir, 'auth.json');
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -31,7 +31,7 @@ function loadAuthData(authenticator) {
|
|
|
31
31
|
try {
|
|
32
32
|
const authFile = getAuthDataPath();
|
|
33
33
|
if (fs.existsSync(authFile)) {
|
|
34
|
-
const data = JSON.parse(fs.readFileSync(authFile,
|
|
34
|
+
const data = JSON.parse(fs.readFileSync(authFile, 'utf8'));
|
|
35
35
|
|
|
36
36
|
// Load users
|
|
37
37
|
if (data.users) {
|
|
@@ -48,7 +48,7 @@ function loadAuthData(authenticator) {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
} catch (error) {
|
|
51
|
-
console.warn(
|
|
51
|
+
console.warn('[WARN] Could not load authentication data:', error.message);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -78,7 +78,7 @@ function saveAuthData(authenticator) {
|
|
|
78
78
|
|
|
79
79
|
fs.writeFileSync(authFile, JSON.stringify(data, null, 2));
|
|
80
80
|
} catch (error) {
|
|
81
|
-
console.warn(
|
|
81
|
+
console.warn('[WARN] Could not save authentication data:', error.message);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -128,11 +128,11 @@ function handleLogin(username, password) {
|
|
|
128
128
|
// Also save the token to a session file for easy access
|
|
129
129
|
const sessionFile = path.join(
|
|
130
130
|
path.dirname(getAuthDataPath()),
|
|
131
|
-
|
|
131
|
+
'session.token',
|
|
132
132
|
);
|
|
133
133
|
fs.writeFileSync(sessionFile, token);
|
|
134
134
|
|
|
135
|
-
console.log(
|
|
135
|
+
console.log('[SUCCESS] Login successful');
|
|
136
136
|
console.log(`Session token: ${token}`);
|
|
137
137
|
} else {
|
|
138
138
|
console.log(`[ERROR] Login failed: ${result}`);
|
|
@@ -150,23 +150,23 @@ function handleLogout() {
|
|
|
150
150
|
// Read the current session token
|
|
151
151
|
const sessionFile = path.join(
|
|
152
152
|
path.dirname(getAuthDataPath()),
|
|
153
|
-
|
|
153
|
+
'session.token',
|
|
154
154
|
);
|
|
155
155
|
|
|
156
156
|
if (!fs.existsSync(sessionFile)) {
|
|
157
|
-
console.log(
|
|
157
|
+
console.log('[ERROR] No active session found');
|
|
158
158
|
process.exit(1);
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
const token = fs.readFileSync(sessionFile,
|
|
161
|
+
const token = fs.readFileSync(sessionFile, 'utf8').trim();
|
|
162
162
|
|
|
163
163
|
const success = authenticator.logout(token);
|
|
164
164
|
if (success) {
|
|
165
165
|
saveAuthData(authenticator);
|
|
166
166
|
fs.unlinkSync(sessionFile); // Remove the session file
|
|
167
|
-
console.log(
|
|
167
|
+
console.log('[SUCCESS] Logged out successfully');
|
|
168
168
|
} else {
|
|
169
|
-
console.log(
|
|
169
|
+
console.log('[ERROR] Logout failed: Invalid session');
|
|
170
170
|
process.exit(1);
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -181,21 +181,21 @@ function handleStatus() {
|
|
|
181
181
|
// Read the current session token
|
|
182
182
|
const sessionFile = path.join(
|
|
183
183
|
path.dirname(getAuthDataPath()),
|
|
184
|
-
|
|
184
|
+
'session.token',
|
|
185
185
|
);
|
|
186
186
|
|
|
187
187
|
if (!fs.existsSync(sessionFile)) {
|
|
188
|
-
console.log(
|
|
188
|
+
console.log('[INFO] No active session');
|
|
189
189
|
return;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
-
const token = fs.readFileSync(sessionFile,
|
|
192
|
+
const token = fs.readFileSync(sessionFile, 'utf8').trim();
|
|
193
193
|
const username = authenticator.validateSession(token);
|
|
194
194
|
|
|
195
195
|
if (username) {
|
|
196
196
|
console.log(`[INFO] Authenticated as: ${username}`);
|
|
197
197
|
} else {
|
|
198
|
-
console.log(
|
|
198
|
+
console.log('[INFO] Session expired or invalid');
|
|
199
199
|
fs.unlinkSync(sessionFile); // Remove the invalid session file
|
|
200
200
|
}
|
|
201
201
|
}
|
package/src/calculator.js
CHANGED
|
@@ -48,7 +48,7 @@ class Calculator {
|
|
|
48
48
|
*/
|
|
49
49
|
divide(a, b) {
|
|
50
50
|
if (b === 0) {
|
|
51
|
-
throw new Error(
|
|
51
|
+
throw new Error('Cannot divide by zero');
|
|
52
52
|
}
|
|
53
53
|
return a / b;
|
|
54
54
|
}
|
|
@@ -71,7 +71,7 @@ class Calculator {
|
|
|
71
71
|
*/
|
|
72
72
|
sqrt(a) {
|
|
73
73
|
if (a < 0) {
|
|
74
|
-
throw new Error(
|
|
74
|
+
throw new Error('Cannot calculate square root of negative number');
|
|
75
75
|
}
|
|
76
76
|
return Math.sqrt(a);
|
|
77
77
|
}
|
|
@@ -84,7 +84,7 @@ class Calculator {
|
|
|
84
84
|
*/
|
|
85
85
|
factorial(n) {
|
|
86
86
|
if (n < 0) {
|
|
87
|
-
throw new Error(
|
|
87
|
+
throw new Error('Cannot calculate factorial of negative number');
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
if (n === 0 || n === 1) {
|
|
@@ -106,7 +106,7 @@ class Calculator {
|
|
|
106
106
|
*/
|
|
107
107
|
percentage(part, whole) {
|
|
108
108
|
if (whole === 0) {
|
|
109
|
-
throw new Error(
|
|
109
|
+
throw new Error('Cannot calculate percentage with zero as whole');
|
|
110
110
|
}
|
|
111
111
|
return (part / whole) * 100;
|
|
112
112
|
}
|
|
@@ -139,11 +139,11 @@ class Calculator {
|
|
|
139
139
|
*/
|
|
140
140
|
fibonacci(n) {
|
|
141
141
|
if (n < 0) {
|
|
142
|
-
throw new Error(
|
|
142
|
+
throw new Error('Cannot calculate Fibonacci of negative number');
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
if (!Number.isInteger(n)) {
|
|
146
|
-
throw new Error(
|
|
146
|
+
throw new Error('Fibonacci input must be an integer');
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
if (n === 0) return 0;
|
|
@@ -170,12 +170,12 @@ class Calculator {
|
|
|
170
170
|
fibonacciSequence(n) {
|
|
171
171
|
if (n < 0) {
|
|
172
172
|
throw new Error(
|
|
173
|
-
|
|
173
|
+
'Cannot generate Fibonacci sequence with negative length',
|
|
174
174
|
);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
if (!Number.isInteger(n)) {
|
|
178
|
-
throw new Error(
|
|
178
|
+
throw new Error('Fibonacci sequence length must be an integer');
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
if (n === 0) return [];
|
|
@@ -199,7 +199,7 @@ class Calculator {
|
|
|
199
199
|
*/
|
|
200
200
|
circleCircumference(radius) {
|
|
201
201
|
if (radius < 0) {
|
|
202
|
-
throw new Error(
|
|
202
|
+
throw new Error('Radius cannot be negative');
|
|
203
203
|
}
|
|
204
204
|
return 2 * Math.PI * radius;
|
|
205
205
|
}
|
|
@@ -264,7 +264,7 @@ class CalculationChain {
|
|
|
264
264
|
*/
|
|
265
265
|
divide(value) {
|
|
266
266
|
if (value === 0) {
|
|
267
|
-
throw new Error(
|
|
267
|
+
throw new Error('Cannot divide by zero');
|
|
268
268
|
}
|
|
269
269
|
this.result /= value;
|
|
270
270
|
return this;
|
|
@@ -287,7 +287,7 @@ class CalculationChain {
|
|
|
287
287
|
*/
|
|
288
288
|
sqrt() {
|
|
289
289
|
if (this.result < 0) {
|
|
290
|
-
throw new Error(
|
|
290
|
+
throw new Error('Cannot calculate square root of negative number');
|
|
291
291
|
}
|
|
292
292
|
this.result = Math.sqrt(this.result);
|
|
293
293
|
return this;
|