@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.mjs
CHANGED
|
@@ -455,14 +455,25 @@ var ToolSchema = z3.object({
|
|
|
455
455
|
params: z3.record(z3.string()),
|
|
456
456
|
fn: z3.function().args(z3.any()).returns(z3.any())
|
|
457
457
|
});
|
|
458
|
+
var UserQueryFiltersSchema = z3.object({
|
|
459
|
+
username: z3.string().optional(),
|
|
460
|
+
email: z3.string().optional(),
|
|
461
|
+
role: z3.string().optional(),
|
|
462
|
+
fullname: z3.string().optional()
|
|
463
|
+
});
|
|
458
464
|
var UsersRequestPayloadSchema = z3.object({
|
|
459
|
-
operation: z3.enum(["create", "update", "delete", "getAll", "getOne"]),
|
|
465
|
+
operation: z3.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
|
|
460
466
|
data: z3.object({
|
|
467
|
+
id: z3.number().optional(),
|
|
461
468
|
username: z3.string().optional(),
|
|
462
469
|
email: z3.string().email("Invalid email format").optional(),
|
|
463
470
|
password: z3.string().optional(),
|
|
464
471
|
fullname: z3.string().optional(),
|
|
465
|
-
role: z3.string().optional()
|
|
472
|
+
role: z3.string().optional(),
|
|
473
|
+
// Query operation fields
|
|
474
|
+
filters: UserQueryFiltersSchema.optional(),
|
|
475
|
+
limit: z3.number().optional(),
|
|
476
|
+
sort: z3.enum(["ASC", "DESC"]).optional()
|
|
466
477
|
}).optional()
|
|
467
478
|
});
|
|
468
479
|
var UsersRequestMessageSchema = z3.object({
|
|
@@ -625,15 +636,24 @@ var BookmarkDataSchema = z3.object({
|
|
|
625
636
|
created_at: z3.string().optional(),
|
|
626
637
|
updated_at: z3.string().optional()
|
|
627
638
|
});
|
|
639
|
+
var BookmarkQueryFiltersSchema = z3.object({
|
|
640
|
+
userId: z3.number().optional(),
|
|
641
|
+
threadId: z3.string().optional(),
|
|
642
|
+
name: z3.string().optional()
|
|
643
|
+
});
|
|
628
644
|
var BookmarksRequestPayloadSchema = z3.object({
|
|
629
|
-
operation: z3.enum(["create", "update", "delete", "getAll", "getOne", "getByUser", "getByThread"]),
|
|
645
|
+
operation: z3.enum(["create", "update", "delete", "getAll", "getOne", "getByUser", "getByThread", "query"]),
|
|
630
646
|
data: z3.object({
|
|
631
647
|
id: z3.number().optional(),
|
|
632
648
|
userId: z3.number().optional(),
|
|
633
649
|
threadId: z3.string().optional(),
|
|
634
650
|
name: z3.string().optional(),
|
|
635
651
|
description: z3.string().optional(),
|
|
636
|
-
uiblock: DBUIBlockSchema.optional()
|
|
652
|
+
uiblock: DBUIBlockSchema.optional(),
|
|
653
|
+
// Query operation fields
|
|
654
|
+
filters: BookmarkQueryFiltersSchema.optional(),
|
|
655
|
+
limit: z3.number().optional(),
|
|
656
|
+
sort: z3.enum(["ASC", "DESC"]).optional()
|
|
637
657
|
}).optional()
|
|
638
658
|
});
|
|
639
659
|
var BookmarksRequestMessageSchema = z3.object({
|
|
@@ -5663,7 +5683,7 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5663
5683
|
try {
|
|
5664
5684
|
const request = UserPromptSuggestionsMessageSchema.parse(data);
|
|
5665
5685
|
const { id, payload, from } = request;
|
|
5666
|
-
const { prompt, limit = 5
|
|
5686
|
+
const { prompt, limit = 5 } = payload;
|
|
5667
5687
|
const wsId = from.id;
|
|
5668
5688
|
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Processing user prompt suggestions: ${prompt}`);
|
|
5669
5689
|
if (!prompt || prompt.trim().length === 0) {
|
|
@@ -5723,23 +5743,17 @@ async function handleUserPromptSuggestions(data, components, sendMessage, collec
|
|
|
5723
5743
|
await Promise.all(searchPromises);
|
|
5724
5744
|
}
|
|
5725
5745
|
if (useEmbeddingSearch && (componentSuggestions.length > 0 || bookmarkSuggestions.length > 0)) {
|
|
5726
|
-
const
|
|
5727
|
-
|
|
5728
|
-
);
|
|
5729
|
-
const filteredBookmarkSuggestions = bookmarkSuggestions.filter(
|
|
5730
|
-
(s) => (s.similarity || 0) >= similarityThreshold
|
|
5731
|
-
);
|
|
5732
|
-
const allSuggestions = [...filteredComponentSuggestions, ...filteredBookmarkSuggestions].sort((a, b) => (b.similarity || 0) - (a.similarity || 0)).slice(0, limit);
|
|
5733
|
-
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Filtered by threshold ${similarityThreshold}: ${componentSuggestions.length} -> ${filteredComponentSuggestions.length} components, ${bookmarkSuggestions.length} -> ${filteredBookmarkSuggestions.length} bookmarks`);
|
|
5746
|
+
const allSuggestions = [...componentSuggestions, ...bookmarkSuggestions].sort((a, b) => (b.similarity || 0) - (a.similarity || 0)).slice(0, limit);
|
|
5747
|
+
logger.info(`[USER_PROMPT_SUGGESTIONS_REQ ${id}] Returning all suggestions: ${componentSuggestions.length} components, ${bookmarkSuggestions.length} bookmarks`);
|
|
5734
5748
|
sendResponse(id, {
|
|
5735
5749
|
success: true,
|
|
5736
5750
|
data: {
|
|
5737
5751
|
prompt,
|
|
5738
5752
|
suggestions: allSuggestions,
|
|
5739
5753
|
count: allSuggestions.length,
|
|
5740
|
-
componentCount:
|
|
5741
|
-
bookmarkCount:
|
|
5742
|
-
message: `Found ${allSuggestions.length} suggestions (${
|
|
5754
|
+
componentCount: componentSuggestions.length,
|
|
5755
|
+
bookmarkCount: bookmarkSuggestions.length,
|
|
5756
|
+
message: `Found ${allSuggestions.length} suggestions (${componentSuggestions.length} components, ${bookmarkSuggestions.length} bookmarks)`
|
|
5743
5757
|
}
|
|
5744
5758
|
}, sendMessage, wsId);
|
|
5745
5759
|
return;
|
|
@@ -6115,17 +6129,28 @@ async function handleComponentListResponse(data, storeComponents, collections) {
|
|
|
6115
6129
|
}
|
|
6116
6130
|
|
|
6117
6131
|
// src/handlers/users.ts
|
|
6118
|
-
async function handleUsersRequest(data, sendMessage) {
|
|
6132
|
+
async function handleUsersRequest(data, collections, sendMessage) {
|
|
6133
|
+
const executeCollection = async (collection, op, params) => {
|
|
6134
|
+
const handler = collections[collection]?.[op];
|
|
6135
|
+
if (!handler) {
|
|
6136
|
+
return null;
|
|
6137
|
+
}
|
|
6138
|
+
return await handler(params);
|
|
6139
|
+
};
|
|
6119
6140
|
try {
|
|
6120
6141
|
const request = UsersRequestMessageSchema.parse(data);
|
|
6121
6142
|
const { id, payload, from } = request;
|
|
6122
6143
|
const { operation, data: requestData } = payload;
|
|
6144
|
+
const numericId = requestData?.id;
|
|
6123
6145
|
const username = requestData?.username;
|
|
6124
6146
|
const email = requestData?.email;
|
|
6125
6147
|
const password = requestData?.password;
|
|
6126
6148
|
const fullname = requestData?.fullname;
|
|
6127
6149
|
const role = requestData?.role;
|
|
6128
|
-
|
|
6150
|
+
const filters = requestData?.filters;
|
|
6151
|
+
const limit = requestData?.limit;
|
|
6152
|
+
const sort = requestData?.sort;
|
|
6153
|
+
if (from.type !== "admin" && operation !== "getOne" && operation !== "getAll" && operation !== "query") {
|
|
6129
6154
|
sendResponse3(id, {
|
|
6130
6155
|
success: false,
|
|
6131
6156
|
error: "Unauthorized: Only admin can manage users"
|
|
@@ -6136,19 +6161,22 @@ async function handleUsersRequest(data, sendMessage) {
|
|
|
6136
6161
|
const userManager = getUserManager();
|
|
6137
6162
|
switch (operation) {
|
|
6138
6163
|
case "create":
|
|
6139
|
-
await handleCreate(id, { username, email, password, fullname, role }, userManager, sendMessage, from.id);
|
|
6164
|
+
await handleCreate(id, { username, email, password, fullname, role }, executeCollection, userManager, sendMessage, from.id);
|
|
6140
6165
|
break;
|
|
6141
6166
|
case "update":
|
|
6142
|
-
await handleUpdate(id, { username, email, password, fullname, role }, userManager, sendMessage, from.id);
|
|
6167
|
+
await handleUpdate(id, numericId, { username, email, password, fullname, role }, executeCollection, userManager, sendMessage, from.id);
|
|
6143
6168
|
break;
|
|
6144
6169
|
case "delete":
|
|
6145
|
-
await handleDelete(id, username, userManager, sendMessage, from.id);
|
|
6170
|
+
await handleDelete(id, numericId, username, executeCollection, userManager, sendMessage, from.id);
|
|
6146
6171
|
break;
|
|
6147
6172
|
case "getAll":
|
|
6148
|
-
await handleGetAll(id, userManager, sendMessage, from.id);
|
|
6173
|
+
await handleGetAll(id, executeCollection, userManager, sendMessage, from.id);
|
|
6149
6174
|
break;
|
|
6150
6175
|
case "getOne":
|
|
6151
|
-
await handleGetOne(id, username, userManager, sendMessage, from.id);
|
|
6176
|
+
await handleGetOne(id, numericId, username, executeCollection, userManager, sendMessage, from.id);
|
|
6177
|
+
break;
|
|
6178
|
+
case "query":
|
|
6179
|
+
await handleQuery(id, filters, limit, sort, executeCollection, userManager, sendMessage, from.id);
|
|
6152
6180
|
break;
|
|
6153
6181
|
default:
|
|
6154
6182
|
sendResponse3(id, {
|
|
@@ -6164,7 +6192,7 @@ async function handleUsersRequest(data, sendMessage) {
|
|
|
6164
6192
|
}, sendMessage);
|
|
6165
6193
|
}
|
|
6166
6194
|
}
|
|
6167
|
-
async function handleCreate(id, userData, userManager, sendMessage, clientId) {
|
|
6195
|
+
async function handleCreate(id, userData, executeCollection, userManager, sendMessage, clientId) {
|
|
6168
6196
|
const { username, email, password, fullname, role } = userData;
|
|
6169
6197
|
if (!username || username.trim().length === 0) {
|
|
6170
6198
|
sendResponse3(id, {
|
|
@@ -6190,52 +6218,121 @@ async function handleCreate(id, userData, userManager, sendMessage, clientId) {
|
|
|
6190
6218
|
return;
|
|
6191
6219
|
}
|
|
6192
6220
|
}
|
|
6193
|
-
|
|
6221
|
+
try {
|
|
6222
|
+
const result = await executeCollection("users", "create", {
|
|
6223
|
+
username,
|
|
6224
|
+
email: email || void 0,
|
|
6225
|
+
password,
|
|
6226
|
+
fullname: fullname || void 0,
|
|
6227
|
+
role: role || void 0
|
|
6228
|
+
});
|
|
6229
|
+
if (result && result.success) {
|
|
6230
|
+
logger.info(`[DB] User created successfully: ${username}`);
|
|
6231
|
+
sendResponse3(id, {
|
|
6232
|
+
success: true,
|
|
6233
|
+
data: {
|
|
6234
|
+
id: result.data?.id,
|
|
6235
|
+
username: result.data?.username,
|
|
6236
|
+
email: result.data?.email,
|
|
6237
|
+
fullname: result.data?.fullname,
|
|
6238
|
+
role: result.data?.role,
|
|
6239
|
+
message: `User '${username}' created successfully (DB)`
|
|
6240
|
+
}
|
|
6241
|
+
}, sendMessage, clientId);
|
|
6242
|
+
return;
|
|
6243
|
+
}
|
|
6244
|
+
} catch (dbError) {
|
|
6245
|
+
logger.warn(`[DB] Failed to create user, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6246
|
+
}
|
|
6247
|
+
try {
|
|
6248
|
+
if (userManager.userExists(username)) {
|
|
6249
|
+
sendResponse3(id, {
|
|
6250
|
+
success: false,
|
|
6251
|
+
error: `User '${username}' already exists`
|
|
6252
|
+
}, sendMessage, clientId);
|
|
6253
|
+
return;
|
|
6254
|
+
}
|
|
6255
|
+
if (email && userManager.getUserByEmail(email)) {
|
|
6256
|
+
sendResponse3(id, {
|
|
6257
|
+
success: false,
|
|
6258
|
+
error: `User with email '${email}' already exists`
|
|
6259
|
+
}, sendMessage, clientId);
|
|
6260
|
+
return;
|
|
6261
|
+
}
|
|
6262
|
+
const newUserData = {
|
|
6263
|
+
username,
|
|
6264
|
+
password
|
|
6265
|
+
};
|
|
6266
|
+
if (email && email.trim().length > 0) {
|
|
6267
|
+
newUserData.email = email.trim();
|
|
6268
|
+
}
|
|
6269
|
+
if (fullname && fullname.trim().length > 0) {
|
|
6270
|
+
newUserData.fullname = fullname.trim();
|
|
6271
|
+
}
|
|
6272
|
+
if (role && role.trim().length > 0) {
|
|
6273
|
+
newUserData.role = role.trim();
|
|
6274
|
+
}
|
|
6275
|
+
const newUser = userManager.createUser(newUserData);
|
|
6276
|
+
logger.info(`[FILE] User '${username}' created successfully`);
|
|
6277
|
+
sendResponse3(id, {
|
|
6278
|
+
success: true,
|
|
6279
|
+
data: {
|
|
6280
|
+
username: newUser.username,
|
|
6281
|
+
email: newUser.email,
|
|
6282
|
+
fullname: newUser.fullname,
|
|
6283
|
+
role: newUser.role,
|
|
6284
|
+
message: `User '${username}' created successfully (File)`
|
|
6285
|
+
}
|
|
6286
|
+
}, sendMessage, clientId);
|
|
6287
|
+
} catch (error) {
|
|
6194
6288
|
sendResponse3(id, {
|
|
6195
6289
|
success: false,
|
|
6196
|
-
error:
|
|
6290
|
+
error: error instanceof Error ? error.message : "Failed to create user"
|
|
6197
6291
|
}, sendMessage, clientId);
|
|
6198
|
-
return;
|
|
6199
6292
|
}
|
|
6200
|
-
|
|
6293
|
+
}
|
|
6294
|
+
async function handleUpdate(id, numericId, userData, executeCollection, userManager, sendMessage, clientId) {
|
|
6295
|
+
const { username, email, password, fullname, role } = userData;
|
|
6296
|
+
if (!numericId && !username) {
|
|
6201
6297
|
sendResponse3(id, {
|
|
6202
6298
|
success: false,
|
|
6203
|
-
error:
|
|
6299
|
+
error: "User ID or username is required"
|
|
6204
6300
|
}, sendMessage, clientId);
|
|
6205
6301
|
return;
|
|
6206
6302
|
}
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
|
|
6224
|
-
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6303
|
+
if (numericId) {
|
|
6304
|
+
try {
|
|
6305
|
+
const result = await executeCollection("users", "update", {
|
|
6306
|
+
id: numericId,
|
|
6307
|
+
username,
|
|
6308
|
+
email,
|
|
6309
|
+
password,
|
|
6310
|
+
fullname,
|
|
6311
|
+
role
|
|
6312
|
+
});
|
|
6313
|
+
if (result && result.success) {
|
|
6314
|
+
logger.info(`[DB] User updated successfully, ID: ${numericId}`);
|
|
6315
|
+
sendResponse3(id, {
|
|
6316
|
+
success: true,
|
|
6317
|
+
data: {
|
|
6318
|
+
id: result.data?.id,
|
|
6319
|
+
username: result.data?.username,
|
|
6320
|
+
email: result.data?.email,
|
|
6321
|
+
fullname: result.data?.fullname,
|
|
6322
|
+
role: result.data?.role,
|
|
6323
|
+
message: `User updated successfully (DB)`
|
|
6324
|
+
}
|
|
6325
|
+
}, sendMessage, clientId);
|
|
6326
|
+
return;
|
|
6327
|
+
}
|
|
6328
|
+
} catch (dbError) {
|
|
6329
|
+
logger.warn(`[DB] Failed to update user, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6230
6330
|
}
|
|
6231
|
-
}
|
|
6232
|
-
}
|
|
6233
|
-
async function handleUpdate(id, userData, userManager, sendMessage, clientId) {
|
|
6234
|
-
const { username, email, password, fullname, role } = userData;
|
|
6331
|
+
}
|
|
6235
6332
|
if (!username || username.trim().length === 0) {
|
|
6236
6333
|
sendResponse3(id, {
|
|
6237
6334
|
success: false,
|
|
6238
|
-
error: "Username is required
|
|
6335
|
+
error: "Username is required for file-based storage update"
|
|
6239
6336
|
}, sendMessage, clientId);
|
|
6240
6337
|
return;
|
|
6241
6338
|
}
|
|
@@ -6286,24 +6383,57 @@ async function handleUpdate(id, userData, userManager, sendMessage, clientId) {
|
|
|
6286
6383
|
}, sendMessage, clientId);
|
|
6287
6384
|
return;
|
|
6288
6385
|
}
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
|
|
6296
|
-
|
|
6297
|
-
|
|
6298
|
-
|
|
6299
|
-
|
|
6300
|
-
|
|
6386
|
+
try {
|
|
6387
|
+
const updatedUser = userManager.updateUser(username, updates);
|
|
6388
|
+
logger.info(`[FILE] User '${username}' updated successfully`);
|
|
6389
|
+
sendResponse3(id, {
|
|
6390
|
+
success: true,
|
|
6391
|
+
data: {
|
|
6392
|
+
username: updatedUser.username,
|
|
6393
|
+
email: updatedUser.email,
|
|
6394
|
+
fullname: updatedUser.fullname,
|
|
6395
|
+
role: updatedUser.role,
|
|
6396
|
+
message: `User '${username}' updated successfully (File)`
|
|
6397
|
+
}
|
|
6398
|
+
}, sendMessage, clientId);
|
|
6399
|
+
} catch (error) {
|
|
6400
|
+
sendResponse3(id, {
|
|
6401
|
+
success: false,
|
|
6402
|
+
error: error instanceof Error ? error.message : "Failed to update user"
|
|
6403
|
+
}, sendMessage, clientId);
|
|
6404
|
+
}
|
|
6301
6405
|
}
|
|
6302
|
-
async function handleDelete(id, username, userManager, sendMessage, clientId) {
|
|
6406
|
+
async function handleDelete(id, numericId, username, executeCollection, userManager, sendMessage, clientId) {
|
|
6407
|
+
if (!numericId && !username) {
|
|
6408
|
+
sendResponse3(id, {
|
|
6409
|
+
success: false,
|
|
6410
|
+
error: "User ID or username is required"
|
|
6411
|
+
}, sendMessage, clientId);
|
|
6412
|
+
return;
|
|
6413
|
+
}
|
|
6414
|
+
if (numericId) {
|
|
6415
|
+
try {
|
|
6416
|
+
const result = await executeCollection("users", "delete", { id: numericId });
|
|
6417
|
+
if (result && result.success) {
|
|
6418
|
+
logger.info(`[DB] User deleted successfully, ID: ${numericId}`);
|
|
6419
|
+
sendResponse3(id, {
|
|
6420
|
+
success: true,
|
|
6421
|
+
data: {
|
|
6422
|
+
id: numericId,
|
|
6423
|
+
username: result.data?.username,
|
|
6424
|
+
message: `User deleted successfully (DB)`
|
|
6425
|
+
}
|
|
6426
|
+
}, sendMessage, clientId);
|
|
6427
|
+
return;
|
|
6428
|
+
}
|
|
6429
|
+
} catch (dbError) {
|
|
6430
|
+
logger.warn(`[DB] Failed to delete user, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6431
|
+
}
|
|
6432
|
+
}
|
|
6303
6433
|
if (!username || username.trim().length === 0) {
|
|
6304
6434
|
sendResponse3(id, {
|
|
6305
6435
|
success: false,
|
|
6306
|
-
error: "Username is required
|
|
6436
|
+
error: "Username is required for file-based storage delete"
|
|
6307
6437
|
}, sendMessage, clientId);
|
|
6308
6438
|
return;
|
|
6309
6439
|
}
|
|
@@ -6322,16 +6452,42 @@ async function handleDelete(id, username, userManager, sendMessage, clientId) {
|
|
|
6322
6452
|
}, sendMessage, clientId);
|
|
6323
6453
|
return;
|
|
6324
6454
|
}
|
|
6325
|
-
logger.info(`User
|
|
6455
|
+
logger.info(`[FILE] User '${username}' deleted successfully`);
|
|
6326
6456
|
sendResponse3(id, {
|
|
6327
6457
|
success: true,
|
|
6328
6458
|
data: {
|
|
6329
6459
|
username,
|
|
6330
|
-
message: `User '${username}' deleted successfully`
|
|
6460
|
+
message: `User '${username}' deleted successfully (File)`
|
|
6331
6461
|
}
|
|
6332
6462
|
}, sendMessage, clientId);
|
|
6333
6463
|
}
|
|
6334
|
-
async function handleGetAll(id, userManager, sendMessage, clientId) {
|
|
6464
|
+
async function handleGetAll(id, executeCollection, userManager, sendMessage, clientId) {
|
|
6465
|
+
try {
|
|
6466
|
+
const result = await executeCollection("users", "getAll", {});
|
|
6467
|
+
if (result && result.success) {
|
|
6468
|
+
const sanitizedUsers2 = result.data.map((user) => ({
|
|
6469
|
+
id: user.id,
|
|
6470
|
+
username: user.username,
|
|
6471
|
+
email: user.email,
|
|
6472
|
+
fullname: user.fullname,
|
|
6473
|
+
role: user.role,
|
|
6474
|
+
createdAt: user.createdAt,
|
|
6475
|
+
updatedAt: user.updatedAt
|
|
6476
|
+
}));
|
|
6477
|
+
logger.info(`[DB] Retrieved ${result.count} users`);
|
|
6478
|
+
sendResponse3(id, {
|
|
6479
|
+
success: true,
|
|
6480
|
+
data: {
|
|
6481
|
+
users: sanitizedUsers2,
|
|
6482
|
+
count: result.count,
|
|
6483
|
+
message: `Retrieved ${result.count} users (DB)`
|
|
6484
|
+
}
|
|
6485
|
+
}, sendMessage, clientId);
|
|
6486
|
+
return;
|
|
6487
|
+
}
|
|
6488
|
+
} catch (dbError) {
|
|
6489
|
+
logger.warn(`[DB] Failed to get all users, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6490
|
+
}
|
|
6335
6491
|
const users = userManager.getAllUsers();
|
|
6336
6492
|
const sanitizedUsers = users.map((user) => ({
|
|
6337
6493
|
username: user.username,
|
|
@@ -6340,21 +6496,55 @@ async function handleGetAll(id, userManager, sendMessage, clientId) {
|
|
|
6340
6496
|
role: user.role,
|
|
6341
6497
|
wsIds: user.wsIds || []
|
|
6342
6498
|
}));
|
|
6343
|
-
logger.info(`
|
|
6499
|
+
logger.info(`[FILE] Retrieved ${sanitizedUsers.length} users`);
|
|
6344
6500
|
sendResponse3(id, {
|
|
6345
6501
|
success: true,
|
|
6346
6502
|
data: {
|
|
6347
6503
|
users: sanitizedUsers,
|
|
6348
6504
|
count: sanitizedUsers.length,
|
|
6349
|
-
message: `Retrieved ${sanitizedUsers.length} users`
|
|
6505
|
+
message: `Retrieved ${sanitizedUsers.length} users (File)`
|
|
6350
6506
|
}
|
|
6351
6507
|
}, sendMessage, clientId);
|
|
6352
6508
|
}
|
|
6353
|
-
async function handleGetOne(id, username, userManager, sendMessage, clientId) {
|
|
6509
|
+
async function handleGetOne(id, numericId, username, executeCollection, userManager, sendMessage, clientId) {
|
|
6510
|
+
if (!numericId && !username) {
|
|
6511
|
+
sendResponse3(id, {
|
|
6512
|
+
success: false,
|
|
6513
|
+
error: "User ID or username is required"
|
|
6514
|
+
}, sendMessage, clientId);
|
|
6515
|
+
return;
|
|
6516
|
+
}
|
|
6517
|
+
if (numericId) {
|
|
6518
|
+
try {
|
|
6519
|
+
const result = await executeCollection("users", "getOne", { id: numericId });
|
|
6520
|
+
if (result && result.success) {
|
|
6521
|
+
const sanitizedUser2 = {
|
|
6522
|
+
id: result.data?.id,
|
|
6523
|
+
username: result.data?.username,
|
|
6524
|
+
email: result.data?.email,
|
|
6525
|
+
fullname: result.data?.fullname,
|
|
6526
|
+
role: result.data?.role,
|
|
6527
|
+
createdAt: result.data?.createdAt,
|
|
6528
|
+
updatedAt: result.data?.updatedAt
|
|
6529
|
+
};
|
|
6530
|
+
logger.info(`[DB] Retrieved user ID: ${numericId}`);
|
|
6531
|
+
sendResponse3(id, {
|
|
6532
|
+
success: true,
|
|
6533
|
+
data: {
|
|
6534
|
+
user: sanitizedUser2,
|
|
6535
|
+
message: `Retrieved user (DB)`
|
|
6536
|
+
}
|
|
6537
|
+
}, sendMessage, clientId);
|
|
6538
|
+
return;
|
|
6539
|
+
}
|
|
6540
|
+
} catch (dbError) {
|
|
6541
|
+
logger.warn(`[DB] Failed to get user, falling back to file storage: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6542
|
+
}
|
|
6543
|
+
}
|
|
6354
6544
|
if (!username || username.trim().length === 0) {
|
|
6355
6545
|
sendResponse3(id, {
|
|
6356
6546
|
success: false,
|
|
6357
|
-
error: "Username is required
|
|
6547
|
+
error: "Username is required for file-based storage lookup"
|
|
6358
6548
|
}, sendMessage, clientId);
|
|
6359
6549
|
return;
|
|
6360
6550
|
}
|
|
@@ -6373,12 +6563,61 @@ async function handleGetOne(id, username, userManager, sendMessage, clientId) {
|
|
|
6373
6563
|
role: user.role,
|
|
6374
6564
|
wsIds: user.wsIds || []
|
|
6375
6565
|
};
|
|
6376
|
-
logger.info(`
|
|
6566
|
+
logger.info(`[FILE] Retrieved user: ${username}`);
|
|
6377
6567
|
sendResponse3(id, {
|
|
6378
6568
|
success: true,
|
|
6379
6569
|
data: {
|
|
6380
6570
|
user: sanitizedUser,
|
|
6381
|
-
message: `Retrieved user '${username}'`
|
|
6571
|
+
message: `Retrieved user '${username}' (File)`
|
|
6572
|
+
}
|
|
6573
|
+
}, sendMessage, clientId);
|
|
6574
|
+
}
|
|
6575
|
+
async function handleQuery(id, filters, limit, sort, executeCollection, userManager, sendMessage, clientId) {
|
|
6576
|
+
try {
|
|
6577
|
+
const result = await executeCollection("users", "query", {
|
|
6578
|
+
filters: filters || {},
|
|
6579
|
+
limit,
|
|
6580
|
+
sort
|
|
6581
|
+
});
|
|
6582
|
+
if (result && result.success) {
|
|
6583
|
+
const sanitizedUsers2 = result.data.map((user) => ({
|
|
6584
|
+
id: user.id,
|
|
6585
|
+
username: user.username,
|
|
6586
|
+
email: user.email,
|
|
6587
|
+
fullname: user.fullname,
|
|
6588
|
+
role: user.role,
|
|
6589
|
+
createdAt: user.createdAt,
|
|
6590
|
+
updatedAt: user.updatedAt
|
|
6591
|
+
}));
|
|
6592
|
+
logger.info(`[DB] Query returned ${result.count} users`);
|
|
6593
|
+
sendResponse3(id, {
|
|
6594
|
+
success: true,
|
|
6595
|
+
data: {
|
|
6596
|
+
users: sanitizedUsers2,
|
|
6597
|
+
count: result.count,
|
|
6598
|
+
message: `Query returned ${result.count} users (DB)`
|
|
6599
|
+
}
|
|
6600
|
+
}, sendMessage, clientId);
|
|
6601
|
+
return;
|
|
6602
|
+
}
|
|
6603
|
+
} catch (dbError) {
|
|
6604
|
+
logger.warn(`[DB] Failed to query users: ${dbError instanceof Error ? dbError.message : "Unknown error"}`);
|
|
6605
|
+
}
|
|
6606
|
+
const users = userManager.getAllUsers();
|
|
6607
|
+
const sanitizedUsers = users.map((user) => ({
|
|
6608
|
+
username: user.username,
|
|
6609
|
+
email: user.email,
|
|
6610
|
+
fullname: user.fullname,
|
|
6611
|
+
role: user.role,
|
|
6612
|
+
wsIds: user.wsIds || []
|
|
6613
|
+
}));
|
|
6614
|
+
logger.info(`[FILE] Retrieved ${sanitizedUsers.length} users (all - no query filter)`);
|
|
6615
|
+
sendResponse3(id, {
|
|
6616
|
+
success: true,
|
|
6617
|
+
data: {
|
|
6618
|
+
users: sanitizedUsers,
|
|
6619
|
+
count: sanitizedUsers.length,
|
|
6620
|
+
message: `Retrieved ${sanitizedUsers.length} users (File - no query filter)`
|
|
6382
6621
|
}
|
|
6383
6622
|
}, sendMessage, clientId);
|
|
6384
6623
|
}
|
|
@@ -6461,7 +6700,7 @@ async function handleDashboardsRequest(data, collections, sendMessage) {
|
|
|
6461
6700
|
await handleGetOne2(id, numericId, dashboardId, executeCollection, dashboardManager2, sendMessage, from.id);
|
|
6462
6701
|
break;
|
|
6463
6702
|
case "query":
|
|
6464
|
-
await
|
|
6703
|
+
await handleQuery2(id, filters, limit, sort, executeCollection, dashboardManager2, sendMessage, from.id);
|
|
6465
6704
|
break;
|
|
6466
6705
|
default:
|
|
6467
6706
|
sendResponse4(id, {
|
|
@@ -6715,7 +6954,7 @@ async function handleGetOne2(id, numericId, dashboardId, executeCollection, dash
|
|
|
6715
6954
|
}
|
|
6716
6955
|
}, sendMessage, clientId);
|
|
6717
6956
|
}
|
|
6718
|
-
async function
|
|
6957
|
+
async function handleQuery2(id, filters, limit, sort, executeCollection, dashboardManager2, sendMessage, clientId) {
|
|
6719
6958
|
try {
|
|
6720
6959
|
const result = await executeCollection("dashboards", "query", {
|
|
6721
6960
|
filters: filters || {},
|
|
@@ -6826,7 +7065,7 @@ async function handleReportsRequest(data, collections, sendMessage) {
|
|
|
6826
7065
|
await handleGetOne3(id, numericId, reportId, executeCollection, reportManager2, sendMessage, from.id);
|
|
6827
7066
|
break;
|
|
6828
7067
|
case "query":
|
|
6829
|
-
await
|
|
7068
|
+
await handleQuery3(id, filters, limit, sort, executeCollection, reportManager2, sendMessage, from.id);
|
|
6830
7069
|
break;
|
|
6831
7070
|
default:
|
|
6832
7071
|
sendResponse5(id, {
|
|
@@ -7080,7 +7319,7 @@ async function handleGetOne3(id, numericId, reportId, executeCollection, reportM
|
|
|
7080
7319
|
}
|
|
7081
7320
|
}, sendMessage, clientId);
|
|
7082
7321
|
}
|
|
7083
|
-
async function
|
|
7322
|
+
async function handleQuery3(id, filters, limit, sort, executeCollection, reportManager2, sendMessage, clientId) {
|
|
7084
7323
|
try {
|
|
7085
7324
|
const result = await executeCollection("reports", "query", {
|
|
7086
7325
|
filters: filters || {},
|
|
@@ -7178,7 +7417,7 @@ async function handleUIsRequest(data, collections, sendMessage) {
|
|
|
7178
7417
|
await handleGetOne4(id, numericId, executeCollection, sendMessage, from.id);
|
|
7179
7418
|
break;
|
|
7180
7419
|
case "query":
|
|
7181
|
-
await
|
|
7420
|
+
await handleQuery4(id, filters, limit, sort, executeCollection, sendMessage, from.id);
|
|
7182
7421
|
break;
|
|
7183
7422
|
default:
|
|
7184
7423
|
sendResponse6(id, {
|
|
@@ -7374,7 +7613,7 @@ async function handleGetOne4(id, numericId, executeCollection, sendMessage, clie
|
|
|
7374
7613
|
}, sendMessage, clientId);
|
|
7375
7614
|
}
|
|
7376
7615
|
}
|
|
7377
|
-
async function
|
|
7616
|
+
async function handleQuery4(id, filters, limit, sort, executeCollection, sendMessage, clientId) {
|
|
7378
7617
|
try {
|
|
7379
7618
|
const result = await executeCollection("uis", "query", {
|
|
7380
7619
|
filters: filters || {},
|
|
@@ -7439,6 +7678,9 @@ async function handleBookmarksRequest(data, collections, sendMessage) {
|
|
|
7439
7678
|
const name = requestData?.name;
|
|
7440
7679
|
const description = requestData?.description;
|
|
7441
7680
|
const uiblock = requestData?.uiblock;
|
|
7681
|
+
const filters = requestData?.filters;
|
|
7682
|
+
const limit = requestData?.limit;
|
|
7683
|
+
const sort = requestData?.sort;
|
|
7442
7684
|
switch (operation) {
|
|
7443
7685
|
case "create":
|
|
7444
7686
|
await handleCreate5(id, userId, threadId, name, description, uiblock, executeCollection, sendMessage, from.id);
|
|
@@ -7461,6 +7703,9 @@ async function handleBookmarksRequest(data, collections, sendMessage) {
|
|
|
7461
7703
|
case "getByThread":
|
|
7462
7704
|
await handleGetByThread(id, threadId, executeCollection, sendMessage, from.id);
|
|
7463
7705
|
break;
|
|
7706
|
+
case "query":
|
|
7707
|
+
await handleQuery5(id, filters, limit, sort, executeCollection, sendMessage, from.id);
|
|
7708
|
+
break;
|
|
7464
7709
|
default:
|
|
7465
7710
|
sendResponse7(id, {
|
|
7466
7711
|
success: false,
|
|
@@ -7639,6 +7884,27 @@ async function handleGetByThread(id, threadId, executeCollection, sendMessage, c
|
|
|
7639
7884
|
}, sendMessage, clientId);
|
|
7640
7885
|
}
|
|
7641
7886
|
}
|
|
7887
|
+
async function handleQuery5(id, filters, limit, sort, executeCollection, sendMessage, clientId) {
|
|
7888
|
+
try {
|
|
7889
|
+
const result = await executeCollection("bookmarks", "query", {
|
|
7890
|
+
filters: filters || {},
|
|
7891
|
+
limit,
|
|
7892
|
+
sort
|
|
7893
|
+
});
|
|
7894
|
+
sendResponse7(id, {
|
|
7895
|
+
success: true,
|
|
7896
|
+
data: result.data,
|
|
7897
|
+
count: result.count,
|
|
7898
|
+
message: `Query returned ${result.count} bookmarks`
|
|
7899
|
+
}, sendMessage, clientId);
|
|
7900
|
+
logger.info(`Query returned ${result.count} bookmarks`);
|
|
7901
|
+
} catch (error) {
|
|
7902
|
+
sendResponse7(id, {
|
|
7903
|
+
success: false,
|
|
7904
|
+
error: error instanceof Error ? error.message : "Failed to query bookmarks"
|
|
7905
|
+
}, sendMessage, clientId);
|
|
7906
|
+
}
|
|
7907
|
+
}
|
|
7642
7908
|
function sendResponse7(id, res, sendMessage, clientId) {
|
|
7643
7909
|
const response = {
|
|
7644
7910
|
id: id || "unknown",
|
|
@@ -8660,7 +8926,7 @@ var SuperatomSDK = class {
|
|
|
8660
8926
|
});
|
|
8661
8927
|
break;
|
|
8662
8928
|
case "USERS":
|
|
8663
|
-
handleUsersRequest(parsed, (msg) => this.send(msg)).catch((error) => {
|
|
8929
|
+
handleUsersRequest(parsed, this.collections, (msg) => this.send(msg)).catch((error) => {
|
|
8664
8930
|
logger.error("Failed to handle users request:", error);
|
|
8665
8931
|
});
|
|
8666
8932
|
break;
|