@superatomai/sdk-node 0.0.20 → 0.0.21
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/dist/index.js +353 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +353 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -495,14 +495,25 @@ var ToolSchema = import_zod3.z.object({
|
|
|
495
495
|
params: import_zod3.z.record(import_zod3.z.string()),
|
|
496
496
|
fn: import_zod3.z.function().args(import_zod3.z.any()).returns(import_zod3.z.any())
|
|
497
497
|
});
|
|
498
|
+
var UserQueryFiltersSchema = import_zod3.z.object({
|
|
499
|
+
username: import_zod3.z.string().optional(),
|
|
500
|
+
email: import_zod3.z.string().optional(),
|
|
501
|
+
role: import_zod3.z.string().optional(),
|
|
502
|
+
fullname: import_zod3.z.string().optional()
|
|
503
|
+
});
|
|
498
504
|
var UsersRequestPayloadSchema = import_zod3.z.object({
|
|
499
|
-
operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne"]),
|
|
505
|
+
operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
|
|
500
506
|
data: import_zod3.z.object({
|
|
507
|
+
id: import_zod3.z.number().optional(),
|
|
501
508
|
username: import_zod3.z.string().optional(),
|
|
502
509
|
email: import_zod3.z.string().email("Invalid email format").optional(),
|
|
503
510
|
password: import_zod3.z.string().optional(),
|
|
504
511
|
fullname: import_zod3.z.string().optional(),
|
|
505
|
-
role: import_zod3.z.string().optional()
|
|
512
|
+
role: import_zod3.z.string().optional(),
|
|
513
|
+
// Query operation fields
|
|
514
|
+
filters: UserQueryFiltersSchema.optional(),
|
|
515
|
+
limit: import_zod3.z.number().optional(),
|
|
516
|
+
sort: import_zod3.z.enum(["ASC", "DESC"]).optional()
|
|
506
517
|
}).optional()
|
|
507
518
|
});
|
|
508
519
|
var UsersRequestMessageSchema = import_zod3.z.object({
|
|
@@ -665,15 +676,24 @@ var BookmarkDataSchema = import_zod3.z.object({
|
|
|
665
676
|
created_at: import_zod3.z.string().optional(),
|
|
666
677
|
updated_at: import_zod3.z.string().optional()
|
|
667
678
|
});
|
|
679
|
+
var BookmarkQueryFiltersSchema = import_zod3.z.object({
|
|
680
|
+
userId: import_zod3.z.number().optional(),
|
|
681
|
+
threadId: import_zod3.z.string().optional(),
|
|
682
|
+
name: import_zod3.z.string().optional()
|
|
683
|
+
});
|
|
668
684
|
var BookmarksRequestPayloadSchema = import_zod3.z.object({
|
|
669
|
-
operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "getByUser", "getByThread"]),
|
|
685
|
+
operation: import_zod3.z.enum(["create", "update", "delete", "getAll", "getOne", "getByUser", "getByThread", "query"]),
|
|
670
686
|
data: import_zod3.z.object({
|
|
671
687
|
id: import_zod3.z.number().optional(),
|
|
672
688
|
userId: import_zod3.z.number().optional(),
|
|
673
689
|
threadId: import_zod3.z.string().optional(),
|
|
674
690
|
name: import_zod3.z.string().optional(),
|
|
675
691
|
description: import_zod3.z.string().optional(),
|
|
676
|
-
uiblock: DBUIBlockSchema.optional()
|
|
692
|
+
uiblock: DBUIBlockSchema.optional(),
|
|
693
|
+
// Query operation fields
|
|
694
|
+
filters: BookmarkQueryFiltersSchema.optional(),
|
|
695
|
+
limit: import_zod3.z.number().optional(),
|
|
696
|
+
sort: import_zod3.z.enum(["ASC", "DESC"]).optional()
|
|
677
697
|
}).optional()
|
|
678
698
|
});
|
|
679
699
|
var BookmarksRequestMessageSchema = import_zod3.z.object({
|
|
@@ -5703,7 +5723,7 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5703
5723
|
try {
|
|
5704
5724
|
const request = UserPromptSuggestionsMessageSchema.parse(data);
|
|
5705
5725
|
const { id, payload, from } = request;
|
|
5706
|
-
const { prompt, limit = 5
|
|
5726
|
+
const { prompt, limit = 5 } = payload;
|
|
5707
5727
|
const wsId = from.id;
|
|
5708
5728
|
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Processing user prompt suggestions: ${prompt}`);
|
|
5709
5729
|
if (!prompt || prompt.trim().length === 0) {
|
|
@@ -5763,23 +5783,17 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5763
5783
|
await Promise.all(searchPromises);
|
|
5764
5784
|
}
|
|
5765
5785
|
if (useEmbeddingSearch && (componentSuggestions.length > 0 || bookmarkSuggestions.length > 0)) {
|
|
5766
|
-
const
|
|
5767
|
-
|
|
5768
|
-
);
|
|
5769
|
-
const filteredBookmarkSuggestions = bookmarkSuggestions.filter(
|
|
5770
|
-
(s) => (s.similarity || 0) >= similarityThreshold
|
|
5771
|
-
);
|
|
5772
|
-
const allSuggestions = [...filteredComponentSuggestions, ...filteredBookmarkSuggestions].sort((a, b) => (b.similarity || 0) - (a.similarity || 0)).slice(0, limit);
|
|
5773
|
-
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Filtered by threshold ${similarityThreshold}: ${componentSuggestions.length} -> ${filteredComponentSuggestions.length} components, ${bookmarkSuggestions.length} -> ${filteredBookmarkSuggestions.length} bookmarks`);
|
|
5786
|
+
const allSuggestions = [...componentSuggestions, ...bookmarkSuggestions].sort((a, b) => (b.similarity || 0) - (a.similarity || 0)).slice(0, limit);
|
|
5787
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Returning all suggestions: ${componentSuggestions.length} components, ${bookmarkSuggestions.length} bookmarks`);
|
|
5774
5788
|
sendResponse(id, {
|
|
5775
5789
|
success: true,
|
|
5776
5790
|
data: {
|
|
5777
5791
|
prompt,
|
|
5778
5792
|
suggestions: allSuggestions,
|
|
5779
5793
|
count: allSuggestions.length,
|
|
5780
|
-
componentCount:
|
|
5781
|
-
bookmarkCount:
|
|
5782
|
-
message: `Found ${allSuggestions.length} suggestions (${
|
|
5794
|
+
componentCount: componentSuggestions.length,
|
|
5795
|
+
bookmarkCount: bookmarkSuggestions.length,
|
|
5796
|
+
message: `Found ${allSuggestions.length} suggestions (${componentSuggestions.length} components, ${bookmarkSuggestions.length} bookmarks)`
|
|
5783
5797
|
}
|
|
5784
5798
|
}, sendMessage, wsId);
|
|
5785
5799
|
return;
|
|
@@ -6155,17 +6169,28 @@ async function handleComponentListResponse(data, storeComponents, collections) {
|
|
|
6155
6169
|
}
|
|
6156
6170
|
|
|
6157
6171
|
// src/handlers/users.ts
|
|
6158
|
-
async function handleUsersRequest(data, sendMessage) {
|
|
6172
|
+
async function handleUsersRequest(data, collections, sendMessage) {
|
|
6173
|
+
const executeCollection = async (collection, op, params) => {
|
|
6174
|
+
const handler = collections[collection]?.[op];
|
|
6175
|
+
if (!handler) {
|
|
6176
|
+
return null;
|
|
6177
|
+
}
|
|
6178
|
+
return await handler(params);
|
|
6179
|
+
};
|
|
6159
6180
|
try {
|
|
6160
6181
|
const request = UsersRequestMessageSchema.parse(data);
|
|
6161
6182
|
const { id, payload, from } = request;
|
|
6162
6183
|
const { operation, data: requestData } = payload;
|
|
6184
|
+
const numericId = requestData?.id;
|
|
6163
6185
|
const username = requestData?.username;
|
|
6164
6186
|
const email = requestData?.email;
|
|
6165
6187
|
const password = requestData?.password;
|
|
6166
6188
|
const fullname = requestData?.fullname;
|
|
6167
6189
|
const role = requestData?.role;
|
|
6168
|
-
|
|
6190
|
+
const filters = requestData?.filters;
|
|
6191
|
+
const limit = requestData?.limit;
|
|
6192
|
+
const sort = requestData?.sort;
|
|
6193
|
+
if (from.type !== "admin" && operation !== "getOne" && operation !== "getAll" && operation !== "query") {
|
|
6169
6194
|
sendResponse3(id, {
|
|
6170
6195
|
success: false,
|
|
6171
6196
|
error: "Unauthorized: Only admin can manage users"
|
|
@@ -6176,19 +6201,22 @@ async function handleUsersRequest(data, sendMessage) {
|
|
|
6176
6201
|
const userManager = getUserManager();
|
|
6177
6202
|
switch (operation) {
|
|
6178
6203
|
case "create":
|
|
6179
|
-
await handleCreate(id, { username, email, password, fullname, role }, userManager, sendMessage, from.id);
|
|
6204
|
+
await handleCreate(id, { username, email, password, fullname, role }, executeCollection, userManager, sendMessage, from.id);
|
|
6180
6205
|
break;
|
|
6181
6206
|
case "update":
|
|
6182
|
-
await handleUpdate(id, { username, email, password, fullname, role }, userManager, sendMessage, from.id);
|
|
6207
|
+
await handleUpdate(id, numericId, { username, email, password, fullname, role }, executeCollection, userManager, sendMessage, from.id);
|
|
6183
6208
|
break;
|
|
6184
6209
|
case "delete":
|
|
6185
|
-
await handleDelete(id, username, userManager, sendMessage, from.id);
|
|
6210
|
+
await handleDelete(id, numericId, username, executeCollection, userManager, sendMessage, from.id);
|
|
6186
6211
|
break;
|
|
6187
6212
|
case "getAll":
|
|
6188
|
-
await handleGetAll(id, userManager, sendMessage, from.id);
|
|
6213
|
+
await handleGetAll(id, executeCollection, userManager, sendMessage, from.id);
|
|
6189
6214
|
break;
|
|
6190
6215
|
case "getOne":
|
|
6191
|
-
await handleGetOne(id, username, userManager, sendMessage, from.id);
|
|
6216
|
+
await handleGetOne(id, numericId, username, executeCollection, userManager, sendMessage, from.id);
|
|
6217
|
+
break;
|
|
6218
|
+
case "query":
|
|
6219
|
+
await handleQuery(id, filters, limit, sort, executeCollection, userManager, sendMessage, from.id);
|
|
6192
6220
|
break;
|
|
6193
6221
|
default:
|
|
6194
6222
|
sendResponse3(id, {
|
|
@@ -6204,7 +6232,7 @@ async function handleUsersRequest(data, sendMessage) {
|
|
|
6204
6232
|
}, sendMessage);
|
|
6205
6233
|
}
|
|
6206
6234
|
}
|
|
6207
|
-
async function handleCreate(id, userData, userManager, sendMessage, clientId) {
|
|
6235
|
+
async function handleCreate(id, userData, executeCollection, userManager, sendMessage, clientId) {
|
|
6208
6236
|
const { username, email, password, fullname, role } = userData;
|
|
6209
6237
|
if (!username || username.trim().length === 0) {
|
|
6210
6238
|
sendResponse3(id, {
|
|
@@ -6230,52 +6258,121 @@ async function handleCreate(id, userData, userManager, sendMessage, clientId) {
|
|
|
6230
6258
|
return;
|
|
6231
6259
|
}
|
|
6232
6260
|
}
|
|
6233
|
-
|
|
6261
|
+
try {
|
|
6262
|
+
const result = await executeCollection("users", "create", {
|
|
6263
|
+
username,
|
|
6264
|
+
email: email || void 0,
|
|
6265
|
+
password,
|
|
6266
|
+
fullname: fullname || void 0,
|
|
6267
|
+
role: role || void 0
|
|
6268
|
+
});
|
|
6269
|
+
if (result && result.success) {
|
|
6270
|
+
logger.info(`[DB] User created successfully: ${username}`);
|
|
6271
|
+
sendResponse3(id, {
|
|
6272
|
+
success: true,
|
|
6273
|
+
data: {
|
|
6274
|
+
id: result.data?.id,
|
|
6275
|
+
username: result.data?.username,
|
|
6276
|
+
email: result.data?.email,
|
|
6277
|
+
fullname: result.data?.fullname,
|
|
6278
|
+
role: result.data?.role,
|
|
6279
|
+
message: `User '${username}' created successfully (DB)`
|
|
6280
|
+
}
|
|
6281
|
+
}, sendMessage, clientId);
|
|
6282
|
+
return;
|
|
6283
|
+
}
|
|
6284
|
+
} catch (dbError) {
|
|
6285
|
+
logger.warn(`[DB] Failed to create user, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6286
|
+
}
|
|
6287
|
+
try {
|
|
6288
|
+
if (userManager.userExists(username)) {
|
|
6289
|
+
sendResponse3(id, {
|
|
6290
|
+
success: false,
|
|
6291
|
+
error: `User '${username}' already exists`
|
|
6292
|
+
}, sendMessage, clientId);
|
|
6293
|
+
return;
|
|
6294
|
+
}
|
|
6295
|
+
if (email && userManager.getUserByEmail(email)) {
|
|
6296
|
+
sendResponse3(id, {
|
|
6297
|
+
success: false,
|
|
6298
|
+
error: `User with email '${email}' already exists`
|
|
6299
|
+
}, sendMessage, clientId);
|
|
6300
|
+
return;
|
|
6301
|
+
}
|
|
6302
|
+
const newUserData = {
|
|
6303
|
+
username,
|
|
6304
|
+
password
|
|
6305
|
+
};
|
|
6306
|
+
if (email && email.trim().length > 0) {
|
|
6307
|
+
newUserData.email = email.trim();
|
|
6308
|
+
}
|
|
6309
|
+
if (fullname && fullname.trim().length > 0) {
|
|
6310
|
+
newUserData.fullname = fullname.trim();
|
|
6311
|
+
}
|
|
6312
|
+
if (role && role.trim().length > 0) {
|
|
6313
|
+
newUserData.role = role.trim();
|
|
6314
|
+
}
|
|
6315
|
+
const newUser = userManager.createUser(newUserData);
|
|
6316
|
+
logger.info(`[FILE] User '${username}' created successfully`);
|
|
6317
|
+
sendResponse3(id, {
|
|
6318
|
+
success: true,
|
|
6319
|
+
data: {
|
|
6320
|
+
username: newUser.username,
|
|
6321
|
+
email: newUser.email,
|
|
6322
|
+
fullname: newUser.fullname,
|
|
6323
|
+
role: newUser.role,
|
|
6324
|
+
message: `User '${username}' created successfully (File)`
|
|
6325
|
+
}
|
|
6326
|
+
}, sendMessage, clientId);
|
|
6327
|
+
} catch (error) {
|
|
6234
6328
|
sendResponse3(id, {
|
|
6235
6329
|
success: false,
|
|
6236
|
-
error:
|
|
6330
|
+
error: error instanceof Error ? error.message : "Failed to create user"
|
|
6237
6331
|
}, sendMessage, clientId);
|
|
6238
|
-
return;
|
|
6239
6332
|
}
|
|
6240
|
-
|
|
6333
|
+
}
|
|
6334
|
+
async function handleUpdate(id, numericId, userData, executeCollection, userManager, sendMessage, clientId) {
|
|
6335
|
+
const { username, email, password, fullname, role } = userData;
|
|
6336
|
+
if (!numericId && !username) {
|
|
6241
6337
|
sendResponse3(id, {
|
|
6242
6338
|
success: false,
|
|
6243
|
-
error:
|
|
6339
|
+
error: "User ID or username is required"
|
|
6244
6340
|
}, sendMessage, clientId);
|
|
6245
6341
|
return;
|
|
6246
6342
|
}
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
|
|
6256
|
-
|
|
6257
|
-
|
|
6258
|
-
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6343
|
+
if (numericId) {
|
|
6344
|
+
try {
|
|
6345
|
+
const result = await executeCollection("users", "update", {
|
|
6346
|
+
id: numericId,
|
|
6347
|
+
username,
|
|
6348
|
+
email,
|
|
6349
|
+
password,
|
|
6350
|
+
fullname,
|
|
6351
|
+
role
|
|
6352
|
+
});
|
|
6353
|
+
if (result && result.success) {
|
|
6354
|
+
logger.info(`[DB] User updated successfully, ID: ${numericId}`);
|
|
6355
|
+
sendResponse3(id, {
|
|
6356
|
+
success: true,
|
|
6357
|
+
data: {
|
|
6358
|
+
id: result.data?.id,
|
|
6359
|
+
username: result.data?.username,
|
|
6360
|
+
email: result.data?.email,
|
|
6361
|
+
fullname: result.data?.fullname,
|
|
6362
|
+
role: result.data?.role,
|
|
6363
|
+
message: `User updated successfully (DB)`
|
|
6364
|
+
}
|
|
6365
|
+
}, sendMessage, clientId);
|
|
6366
|
+
return;
|
|
6367
|
+
}
|
|
6368
|
+
} catch (dbError) {
|
|
6369
|
+
logger.warn(`[DB] Failed to update user, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6270
6370
|
}
|
|
6271
|
-
}
|
|
6272
|
-
}
|
|
6273
|
-
async function handleUpdate(id, userData, userManager, sendMessage, clientId) {
|
|
6274
|
-
const { username, email, password, fullname, role } = userData;
|
|
6371
|
+
}
|
|
6275
6372
|
if (!username || username.trim().length === 0) {
|
|
6276
6373
|
sendResponse3(id, {
|
|
6277
6374
|
success: false,
|
|
6278
|
-
error: "Username is required
|
|
6375
|
+
error: "Username is required for file-based storage update"
|
|
6279
6376
|
}, sendMessage, clientId);
|
|
6280
6377
|
return;
|
|
6281
6378
|
}
|
|
@@ -6326,24 +6423,57 @@ async function handleUpdate(id, userData, userManager, sendMessage, clientId) {
|
|
|
6326
6423
|
}, sendMessage, clientId);
|
|
6327
6424
|
return;
|
|
6328
6425
|
}
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6338
|
-
|
|
6339
|
-
|
|
6340
|
-
|
|
6426
|
+
try {
|
|
6427
|
+
const updatedUser = userManager.updateUser(username, updates);
|
|
6428
|
+
logger.info(`[FILE] User '${username}' updated successfully`);
|
|
6429
|
+
sendResponse3(id, {
|
|
6430
|
+
success: true,
|
|
6431
|
+
data: {
|
|
6432
|
+
username: updatedUser.username,
|
|
6433
|
+
email: updatedUser.email,
|
|
6434
|
+
fullname: updatedUser.fullname,
|
|
6435
|
+
role: updatedUser.role,
|
|
6436
|
+
message: `User '${username}' updated successfully (File)`
|
|
6437
|
+
}
|
|
6438
|
+
}, sendMessage, clientId);
|
|
6439
|
+
} catch (error) {
|
|
6440
|
+
sendResponse3(id, {
|
|
6441
|
+
success: false,
|
|
6442
|
+
error: error instanceof Error ? error.message : "Failed to update user"
|
|
6443
|
+
}, sendMessage, clientId);
|
|
6444
|
+
}
|
|
6341
6445
|
}
|
|
6342
|
-
async function handleDelete(id, username, userManager, sendMessage, clientId) {
|
|
6446
|
+
async function handleDelete(id, numericId, username, executeCollection, userManager, sendMessage, clientId) {
|
|
6447
|
+
if (!numericId && !username) {
|
|
6448
|
+
sendResponse3(id, {
|
|
6449
|
+
success: false,
|
|
6450
|
+
error: "User ID or username is required"
|
|
6451
|
+
}, sendMessage, clientId);
|
|
6452
|
+
return;
|
|
6453
|
+
}
|
|
6454
|
+
if (numericId) {
|
|
6455
|
+
try {
|
|
6456
|
+
const result = await executeCollection("users", "delete", { id: numericId });
|
|
6457
|
+
if (result && result.success) {
|
|
6458
|
+
logger.info(`[DB] User deleted successfully, ID: ${numericId}`);
|
|
6459
|
+
sendResponse3(id, {
|
|
6460
|
+
success: true,
|
|
6461
|
+
data: {
|
|
6462
|
+
id: numericId,
|
|
6463
|
+
username: result.data?.username,
|
|
6464
|
+
message: `User deleted successfully (DB)`
|
|
6465
|
+
}
|
|
6466
|
+
}, sendMessage, clientId);
|
|
6467
|
+
return;
|
|
6468
|
+
}
|
|
6469
|
+
} catch (dbError) {
|
|
6470
|
+
logger.warn(`[DB] Failed to delete user, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6471
|
+
}
|
|
6472
|
+
}
|
|
6343
6473
|
if (!username || username.trim().length === 0) {
|
|
6344
6474
|
sendResponse3(id, {
|
|
6345
6475
|
success: false,
|
|
6346
|
-
error: "Username is required
|
|
6476
|
+
error: "Username is required for file-based storage delete"
|
|
6347
6477
|
}, sendMessage, clientId);
|
|
6348
6478
|
return;
|
|
6349
6479
|
}
|
|
@@ -6362,16 +6492,42 @@ async function handleDelete(id, username, userManager, sendMessage, clientId) {
|
|
|
6362
6492
|
}, sendMessage, clientId);
|
|
6363
6493
|
return;
|
|
6364
6494
|
}
|
|
6365
|
-
logger.info(`User
|
|
6495
|
+
logger.info(`[FILE] User '${username}' deleted successfully`);
|
|
6366
6496
|
sendResponse3(id, {
|
|
6367
6497
|
success: true,
|
|
6368
6498
|
data: {
|
|
6369
6499
|
username,
|
|
6370
|
-
message: `User '${username}' deleted successfully`
|
|
6500
|
+
message: `User '${username}' deleted successfully (File)`
|
|
6371
6501
|
}
|
|
6372
6502
|
}, sendMessage, clientId);
|
|
6373
6503
|
}
|
|
6374
|
-
async function handleGetAll(id, userManager, sendMessage, clientId) {
|
|
6504
|
+
async function handleGetAll(id, executeCollection, userManager, sendMessage, clientId) {
|
|
6505
|
+
try {
|
|
6506
|
+
const result = await executeCollection("users", "getAll", {});
|
|
6507
|
+
if (result && result.success) {
|
|
6508
|
+
const sanitizedUsers2 = result.data.map((user) => ({
|
|
6509
|
+
id: user.id,
|
|
6510
|
+
username: user.username,
|
|
6511
|
+
email: user.email,
|
|
6512
|
+
fullname: user.fullname,
|
|
6513
|
+
role: user.role,
|
|
6514
|
+
createdAt: user.createdAt,
|
|
6515
|
+
updatedAt: user.updatedAt
|
|
6516
|
+
}));
|
|
6517
|
+
logger.info(`[DB] Retrieved ${result.count} users`);
|
|
6518
|
+
sendResponse3(id, {
|
|
6519
|
+
success: true,
|
|
6520
|
+
data: {
|
|
6521
|
+
users: sanitizedUsers2,
|
|
6522
|
+
count: result.count,
|
|
6523
|
+
message: `Retrieved ${result.count} users (DB)`
|
|
6524
|
+
}
|
|
6525
|
+
}, sendMessage, clientId);
|
|
6526
|
+
return;
|
|
6527
|
+
}
|
|
6528
|
+
} catch (dbError) {
|
|
6529
|
+
logger.warn(`[DB] Failed to get all users, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6530
|
+
}
|
|
6375
6531
|
const users = userManager.getAllUsers();
|
|
6376
6532
|
const sanitizedUsers = users.map((user) => ({
|
|
6377
6533
|
username: user.username,
|
|
@@ -6380,21 +6536,55 @@ async function handleGetAll(id, userManager, sendMessage, clientId) {
|
|
|
6380
6536
|
role: user.role,
|
|
6381
6537
|
wsIds: user.wsIds || []
|
|
6382
6538
|
}));
|
|
6383
|
-
logger.info(`
|
|
6539
|
+
logger.info(`[FILE] Retrieved ${sanitizedUsers.length} users`);
|
|
6384
6540
|
sendResponse3(id, {
|
|
6385
6541
|
success: true,
|
|
6386
6542
|
data: {
|
|
6387
6543
|
users: sanitizedUsers,
|
|
6388
6544
|
count: sanitizedUsers.length,
|
|
6389
|
-
message: `Retrieved ${sanitizedUsers.length} users`
|
|
6545
|
+
message: `Retrieved ${sanitizedUsers.length} users (File)`
|
|
6390
6546
|
}
|
|
6391
6547
|
}, sendMessage, clientId);
|
|
6392
6548
|
}
|
|
6393
|
-
async function handleGetOne(id, username, userManager, sendMessage, clientId) {
|
|
6549
|
+
async function handleGetOne(id, numericId, username, executeCollection, userManager, sendMessage, clientId) {
|
|
6550
|
+
if (!numericId && !username) {
|
|
6551
|
+
sendResponse3(id, {
|
|
6552
|
+
success: false,
|
|
6553
|
+
error: "User ID or username is required"
|
|
6554
|
+
}, sendMessage, clientId);
|
|
6555
|
+
return;
|
|
6556
|
+
}
|
|
6557
|
+
if (numericId) {
|
|
6558
|
+
try {
|
|
6559
|
+
const result = await executeCollection("users", "getOne", { id: numericId });
|
|
6560
|
+
if (result && result.success) {
|
|
6561
|
+
const sanitizedUser2 = {
|
|
6562
|
+
id: result.data?.id,
|
|
6563
|
+
username: result.data?.username,
|
|
6564
|
+
email: result.data?.email,
|
|
6565
|
+
fullname: result.data?.fullname,
|
|
6566
|
+
role: result.data?.role,
|
|
6567
|
+
createdAt: result.data?.createdAt,
|
|
6568
|
+
updatedAt: result.data?.updatedAt
|
|
6569
|
+
};
|
|
6570
|
+
logger.info(`[DB] Retrieved user ID: ${numericId}`);
|
|
6571
|
+
sendResponse3(id, {
|
|
6572
|
+
success: true,
|
|
6573
|
+
data: {
|
|
6574
|
+
user: sanitizedUser2,
|
|
6575
|
+
message: `Retrieved user (DB)`
|
|
6576
|
+
}
|
|
6577
|
+
}, sendMessage, clientId);
|
|
6578
|
+
return;
|
|
6579
|
+
}
|
|
6580
|
+
} catch (dbError) {
|
|
6581
|
+
logger.warn(`[DB] Failed to get user, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6582
|
+
}
|
|
6583
|
+
}
|
|
6394
6584
|
if (!username || username.trim().length === 0) {
|
|
6395
6585
|
sendResponse3(id, {
|
|
6396
6586
|
success: false,
|
|
6397
|
-
error: "Username is required
|
|
6587
|
+
error: "Username is required for file-based storage lookup"
|
|
6398
6588
|
}, sendMessage, clientId);
|
|
6399
6589
|
return;
|
|
6400
6590
|
}
|
|
@@ -6413,12 +6603,61 @@ async function handleGetOne(id, username, userManager, sendMessage, clientId) {
|
|
|
6413
6603
|
role: user.role,
|
|
6414
6604
|
wsIds: user.wsIds || []
|
|
6415
6605
|
};
|
|
6416
|
-
logger.info(`
|
|
6606
|
+
logger.info(`[FILE] Retrieved user: ${username}`);
|
|
6417
6607
|
sendResponse3(id, {
|
|
6418
6608
|
success: true,
|
|
6419
6609
|
data: {
|
|
6420
6610
|
user: sanitizedUser,
|
|
6421
|
-
message: `Retrieved user '${username}'`
|
|
6611
|
+
message: `Retrieved user '${username}' (File)`
|
|
6612
|
+
}
|
|
6613
|
+
}, sendMessage, clientId);
|
|
6614
|
+
}
|
|
6615
|
+
async function handleQuery(id, filters, limit, sort, executeCollection, userManager, sendMessage, clientId) {
|
|
6616
|
+
try {
|
|
6617
|
+
const result = await executeCollection("users", "query", {
|
|
6618
|
+
filters: filters || {},
|
|
6619
|
+
limit,
|
|
6620
|
+
sort
|
|
6621
|
+
});
|
|
6622
|
+
if (result && result.success) {
|
|
6623
|
+
const sanitizedUsers2 = result.data.map((user) => ({
|
|
6624
|
+
id: user.id,
|
|
6625
|
+
username: user.username,
|
|
6626
|
+
email: user.email,
|
|
6627
|
+
fullname: user.fullname,
|
|
6628
|
+
role: user.role,
|
|
6629
|
+
createdAt: user.createdAt,
|
|
6630
|
+
updatedAt: user.updatedAt
|
|
6631
|
+
}));
|
|
6632
|
+
logger.info(`[DB] Query returned ${result.count} users`);
|
|
6633
|
+
sendResponse3(id, {
|
|
6634
|
+
success: true,
|
|
6635
|
+
data: {
|
|
6636
|
+
users: sanitizedUsers2,
|
|
6637
|
+
count: result.count,
|
|
6638
|
+
message: `Query returned ${result.count} users (DB)`
|
|
6639
|
+
}
|
|
6640
|
+
}, sendMessage, clientId);
|
|
6641
|
+
return;
|
|
6642
|
+
}
|
|
6643
|
+
} catch (dbError) {
|
|
6644
|
+
logger.warn(`[DB] Failed to query users: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6645
|
+
}
|
|
6646
|
+
const users = userManager.getAllUsers();
|
|
6647
|
+
const sanitizedUsers = users.map((user) => ({
|
|
6648
|
+
username: user.username,
|
|
6649
|
+
email: user.email,
|
|
6650
|
+
fullname: user.fullname,
|
|
6651
|
+
role: user.role,
|
|
6652
|
+
wsIds: user.wsIds || []
|
|
6653
|
+
}));
|
|
6654
|
+
logger.info(`[FILE] Retrieved ${sanitizedUsers.length} users (all - no query filter)`);
|
|
6655
|
+
sendResponse3(id, {
|
|
6656
|
+
success: true,
|
|
6657
|
+
data: {
|
|
6658
|
+
users: sanitizedUsers,
|
|
6659
|
+
count: sanitizedUsers.length,
|
|
6660
|
+
message: `Retrieved ${sanitizedUsers.length} users (File - no query filter)`
|
|
6422
6661
|
}
|
|
6423
6662
|
}, sendMessage, clientId);
|
|
6424
6663
|
}
|
|
@@ -6501,7 +6740,7 @@ async function handleDashboardsRequest(data, collections, sendMessage) {
|
|
|
6501
6740
|
await handleGetOne2(id, numericId, dashboardId, executeCollection, dashboardManager2, sendMessage, from.id);
|
|
6502
6741
|
break;
|
|
6503
6742
|
case "query":
|
|
6504
|
-
await
|
|
6743
|
+
await handleQuery2(id, filters, limit, sort, executeCollection, dashboardManager2, sendMessage, from.id);
|
|
6505
6744
|
break;
|
|
6506
6745
|
default:
|
|
6507
6746
|
sendResponse4(id, {
|
|
@@ -6755,7 +6994,7 @@ async function handleGetOne2(id, numericId, dashboardId, executeCollection, dash
|
|
|
6755
6994
|
}
|
|
6756
6995
|
}, sendMessage, clientId);
|
|
6757
6996
|
}
|
|
6758
|
-
async function
|
|
6997
|
+
async function handleQuery2(id, filters, limit, sort, executeCollection, dashboardManager2, sendMessage, clientId) {
|
|
6759
6998
|
try {
|
|
6760
6999
|
const result = await executeCollection("dashboards", "query", {
|
|
6761
7000
|
filters: filters || {},
|
|
@@ -6866,7 +7105,7 @@ async function handleReportsRequest(data, collections, sendMessage) {
|
|
|
6866
7105
|
await handleGetOne3(id, numericId, reportId, executeCollection, reportManager2, sendMessage, from.id);
|
|
6867
7106
|
break;
|
|
6868
7107
|
case "query":
|
|
6869
|
-
await
|
|
7108
|
+
await handleQuery3(id, filters, limit, sort, executeCollection, reportManager2, sendMessage, from.id);
|
|
6870
7109
|
break;
|
|
6871
7110
|
default:
|
|
6872
7111
|
sendResponse5(id, {
|
|
@@ -7120,7 +7359,7 @@ async function handleGetOne3(id, numericId, reportId, executeCollection, reportM
|
|
|
7120
7359
|
}
|
|
7121
7360
|
}, sendMessage, clientId);
|
|
7122
7361
|
}
|
|
7123
|
-
async function
|
|
7362
|
+
async function handleQuery3(id, filters, limit, sort, executeCollection, reportManager2, sendMessage, clientId) {
|
|
7124
7363
|
try {
|
|
7125
7364
|
const result = await executeCollection("reports", "query", {
|
|
7126
7365
|
filters: filters || {},
|
|
@@ -7218,7 +7457,7 @@ async function handleUIsRequest(data, collections, sendMessage) {
|
|
|
7218
7457
|
await handleGetOne4(id, numericId, executeCollection, sendMessage, from.id);
|
|
7219
7458
|
break;
|
|
7220
7459
|
case "query":
|
|
7221
|
-
await
|
|
7460
|
+
await handleQuery4(id, filters, limit, sort, executeCollection, sendMessage, from.id);
|
|
7222
7461
|
break;
|
|
7223
7462
|
default:
|
|
7224
7463
|
sendResponse6(id, {
|
|
@@ -7414,7 +7653,7 @@ async function handleGetOne4(id, numericId, executeCollection, sendMessage, clie
|
|
|
7414
7653
|
}, sendMessage, clientId);
|
|
7415
7654
|
}
|
|
7416
7655
|
}
|
|
7417
|
-
async function
|
|
7656
|
+
async function handleQuery4(id, filters, limit, sort, executeCollection, sendMessage, clientId) {
|
|
7418
7657
|
try {
|
|
7419
7658
|
const result = await executeCollection("uis", "query", {
|
|
7420
7659
|
filters: filters || {},
|
|
@@ -7479,6 +7718,9 @@ async function handleBookmarksRequest(data, collections, sendMessage) {
|
|
|
7479
7718
|
const name = requestData?.name;
|
|
7480
7719
|
const description = requestData?.description;
|
|
7481
7720
|
const uiblock = requestData?.uiblock;
|
|
7721
|
+
const filters = requestData?.filters;
|
|
7722
|
+
const limit = requestData?.limit;
|
|
7723
|
+
const sort = requestData?.sort;
|
|
7482
7724
|
switch (operation) {
|
|
7483
7725
|
case "create":
|
|
7484
7726
|
await handleCreate5(id, userId, threadId, name, description, uiblock, executeCollection, sendMessage, from.id);
|
|
@@ -7501,6 +7743,9 @@ async function handleBookmarksRequest(data, collections, sendMessage) {
|
|
|
7501
7743
|
case "getByThread":
|
|
7502
7744
|
await handleGetByThread(id, threadId, executeCollection, sendMessage, from.id);
|
|
7503
7745
|
break;
|
|
7746
|
+
case "query":
|
|
7747
|
+
await handleQuery5(id, filters, limit, sort, executeCollection, sendMessage, from.id);
|
|
7748
|
+
break;
|
|
7504
7749
|
default:
|
|
7505
7750
|
sendResponse7(id, {
|
|
7506
7751
|
success: false,
|
|
@@ -7679,6 +7924,27 @@ async function handleGetByThread(id, threadId, executeCollection, sendMessage, c
|
|
|
7679
7924
|
}, sendMessage, clientId);
|
|
7680
7925
|
}
|
|
7681
7926
|
}
|
|
7927
|
+
async function handleQuery5(id, filters, limit, sort, executeCollection, sendMessage, clientId) {
|
|
7928
|
+
try {
|
|
7929
|
+
const result = await executeCollection("bookmarks", "query", {
|
|
7930
|
+
filters: filters || {},
|
|
7931
|
+
limit,
|
|
7932
|
+
sort
|
|
7933
|
+
});
|
|
7934
|
+
sendResponse7(id, {
|
|
7935
|
+
success: true,
|
|
7936
|
+
data: result.data,
|
|
7937
|
+
count: result.count,
|
|
7938
|
+
message: `Query returned ${result.count} bookmarks`
|
|
7939
|
+
}, sendMessage, clientId);
|
|
7940
|
+
logger.info(`Query returned ${result.count} bookmarks`);
|
|
7941
|
+
} catch (error) {
|
|
7942
|
+
sendResponse7(id, {
|
|
7943
|
+
success: false,
|
|
7944
|
+
error: error instanceof Error ? error.message : "Failed to query bookmarks"
|
|
7945
|
+
}, sendMessage, clientId);
|
|
7946
|
+
}
|
|
7947
|
+
}
|
|
7682
7948
|
function sendResponse7(id, res, sendMessage, clientId) {
|
|
7683
7949
|
const response = {
|
|
7684
7950
|
id: id || "unknown",
|
|
@@ -8700,7 +8966,7 @@ var SuperatomSDK = class {
|
|
|
8700
8966
|
});
|
|
8701
8967
|
break;
|
|
8702
8968
|
case "USERS":
|
|
8703
|
-
handleUsersRequest(parsed, (msg) => this.send(msg)).catch((error) => {
|
|
8969
|
+
handleUsersRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
8704
8970
|
logger.error("Failed to handle users request:", error);
|
|
8705
8971
|
});
|
|
8706
8972
|
break;
|