@superatomai/sdk-web 0.0.6 → 0.0.8

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 CHANGED
@@ -127,21 +127,42 @@ const verifyResponse = await client.sendAuthVerifyRequest(
127
127
 
128
128
  ```typescript
129
129
  // Create a new user
130
- const result = await client.createUser(username, password, timeout);
130
+ const result = await client.createUser(
131
+ username,
132
+ password,
133
+ email?, // Optional: User email
134
+ fullname?, // Optional: User full name
135
+ role?, // Optional: User role
136
+ timeout?
137
+ );
138
+ // Returns: { success, username?, email?, fullname?, role?, message?, error? }
131
139
 
132
140
  // Update an existing user
133
- const result = await client.updateUser(username, password, timeout);
141
+ const result = await client.updateUser(
142
+ username,
143
+ {
144
+ password?: string, // Optional: New password
145
+ email?: string, // Optional: New email
146
+ fullname?: string, // Optional: New full name
147
+ role?: string, // Optional: New role
148
+ },
149
+ timeout?
150
+ );
151
+ // Returns: { success, username?, email?, fullname?, role?, message?, error? }
134
152
 
135
153
  // Delete a user
136
154
  const result = await client.deleteUser(username, timeout);
155
+ // Returns: { success, username?, email?, fullname?, role?, message?, error? }
137
156
 
138
157
  // Get all users
139
158
  const result = await client.getAllUsers(timeout);
140
159
  // Returns: { success, users, count, error?, message? }
160
+ // User object: { username, email?, fullname?, role?, wsIds }
141
161
 
142
162
  // Get a specific user
143
163
  const result = await client.getUser(username, timeout);
144
164
  // Returns: { success, user, error?, message? }
165
+ // User object: { username, email?, fullname?, role?, wsIds }
145
166
  ```
146
167
 
147
168
  #### Dashboard Management
@@ -292,6 +313,67 @@ The SDK supports the following message types (all validated with Zod schemas):
292
313
 
293
314
  All message types are fully typed and validated using Zod v4 schemas.
294
315
 
316
+ ### USERS Schema
317
+
318
+ The USERS message type supports comprehensive user management with the following structure:
319
+
320
+ **Request Payload** (`USERS`):
321
+ ```typescript
322
+ {
323
+ operation: 'create' | 'update' | 'delete' | 'getAll' | 'getOne',
324
+ data?: {
325
+ username?: string, // Required for all operations except getAll
326
+ email?: string, // Optional: User email (validated)
327
+ password?: string, // Required for create, optional for update
328
+ fullname?: string, // Optional: User's full name
329
+ role?: string, // Optional: User's role
330
+ }
331
+ }
332
+ ```
333
+
334
+ **Response Payload** (`USERS_RES`):
335
+ ```typescript
336
+ {
337
+ success: boolean,
338
+ error?: string,
339
+ data?: {
340
+ username?: string,
341
+ email?: string,
342
+ fullname?: string,
343
+ role?: string,
344
+ message?: string,
345
+ // For getAll operation
346
+ users?: Array<{
347
+ username: string,
348
+ email?: string,
349
+ fullname?: string,
350
+ role?: string,
351
+ wsIds: string[]
352
+ }>,
353
+ count?: number,
354
+ // For getOne operation
355
+ user?: {
356
+ username: string,
357
+ email?: string,
358
+ fullname?: string,
359
+ role?: string,
360
+ wsIds: string[]
361
+ }
362
+ }
363
+ }
364
+ ```
365
+
366
+ **User Object Structure**:
367
+ ```typescript
368
+ interface User {
369
+ username: string; // Required: Unique username
370
+ email?: string; // Optional: Validated email address
371
+ fullname?: string; // Optional: User's full name
372
+ role?: string; // Optional: User role (e.g., 'admin', 'editor', 'viewer')
373
+ wsIds: string[]; // WebSocket connection IDs (in-memory only)
374
+ }
375
+ ```
376
+
295
377
  ## Type Safety
296
378
 
297
379
  All messages are validated using Zod v4 schemas. The SDK exports comprehensive type definitions and schemas:
@@ -380,10 +462,19 @@ const client = new SuperatomClient({
380
462
 
381
463
  await client.connect();
382
464
 
383
- // Create a new user
384
- const createResult = await client.createUser('newuser', 'password123');
465
+ // Create a new user with all fields
466
+ const createResult = await client.createUser(
467
+ 'newuser',
468
+ 'password123',
469
+ 'user@example.com', // email
470
+ 'John Doe', // fullname
471
+ 'editor' // role
472
+ );
385
473
  if (createResult.success) {
386
474
  console.log('User created:', createResult.username);
475
+ console.log('Email:', createResult.email);
476
+ console.log('Full name:', createResult.fullname);
477
+ console.log('Role:', createResult.role);
387
478
  }
388
479
 
389
480
  // Get all users
@@ -391,12 +482,25 @@ const usersResult = await client.getAllUsers();
391
482
  if (usersResult.success && usersResult.users) {
392
483
  console.log(`Found ${usersResult.count} users`);
393
484
  usersResult.users.forEach(user => {
394
- console.log(`- ${user.username} (${user.wsIds.length} connections)`);
485
+ console.log(`- ${user.username} (${user.email || 'no email'})`);
486
+ console.log(` Full name: ${user.fullname || 'N/A'}`);
487
+ console.log(` Role: ${user.role || 'N/A'}`);
488
+ console.log(` Connections: ${user.wsIds.length}`);
395
489
  });
396
490
  }
397
491
 
398
- // Update a user
399
- await client.updateUser('newuser', 'newpassword456');
492
+ // Update a user - change multiple fields
493
+ await client.updateUser('newuser', {
494
+ password: 'newpassword456',
495
+ email: 'newemail@example.com',
496
+ fullname: 'Jane Doe',
497
+ role: 'admin'
498
+ });
499
+
500
+ // Update a user - change only specific fields
501
+ await client.updateUser('newuser', {
502
+ role: 'viewer' // Only update role
503
+ });
400
504
 
401
505
  // Delete a user
402
506
  await client.deleteUser('newuser');
package/dist/index.cjs CHANGED
@@ -434,7 +434,10 @@ var UsersRequestPayloadSchema = zod.z.object({
434
434
  operation: zod.z.enum(["create", "update", "delete", "getAll", "getOne"]),
435
435
  data: zod.z.object({
436
436
  username: zod.z.string().optional(),
437
- password: zod.z.string().optional()
437
+ email: zod.z.string().email("Invalid email format").optional(),
438
+ password: zod.z.string().optional(),
439
+ fullname: zod.z.string().optional(),
440
+ role: zod.z.string().optional()
438
441
  }).optional()
439
442
  });
440
443
  var UsersRequestMessageSchema = zod.z.object({
@@ -449,13 +452,22 @@ var UsersResponsePayloadSchema = zod.z.object({
449
452
  error: zod.z.string().optional(),
450
453
  data: zod.z.object({
451
454
  username: zod.z.string().optional(),
455
+ email: zod.z.string().optional(),
456
+ fullname: zod.z.string().optional(),
457
+ role: zod.z.string().optional(),
452
458
  message: zod.z.string().optional(),
453
459
  users: zod.z.array(zod.z.object({
454
460
  username: zod.z.string(),
461
+ email: zod.z.string().optional(),
462
+ fullname: zod.z.string().optional(),
463
+ role: zod.z.string().optional(),
455
464
  wsIds: zod.z.array(zod.z.string())
456
465
  })).optional(),
457
466
  user: zod.z.object({
458
467
  username: zod.z.string(),
468
+ email: zod.z.string().optional(),
469
+ fullname: zod.z.string().optional(),
470
+ role: zod.z.string().optional(),
459
471
  wsIds: zod.z.array(zod.z.string())
460
472
  }).optional(),
461
473
  count: zod.z.number().optional()
@@ -593,7 +605,7 @@ async function sendAuthLoginRequest(client, loginDataBase64, timeout) {
593
605
  id: messageId,
594
606
  type: "AUTH_LOGIN_REQ",
595
607
  from: {
596
- type: "runtime"
608
+ type: client.type
597
609
  },
598
610
  to: {
599
611
  type: "data-agent"
@@ -603,6 +615,7 @@ async function sendAuthLoginRequest(client, loginDataBase64, timeout) {
603
615
  }
604
616
  });
605
617
  const response = await client.sendWithResponse(message, timeout);
618
+ console.log("sdk auth login response", response);
606
619
  return response;
607
620
  }
608
621
  async function sendAuthVerifyRequest(client, token, timeout) {
@@ -611,7 +624,7 @@ async function sendAuthVerifyRequest(client, token, timeout) {
611
624
  id: messageId,
612
625
  type: "AUTH_VERIFY_REQ",
613
626
  from: {
614
- type: "runtime"
627
+ type: client.type
615
628
  },
616
629
  to: {
617
630
  type: "data-agent"
@@ -631,7 +644,7 @@ async function sendUserPromptRequest(client, prompt, threadId, uiBlockId, timeou
631
644
  id: messageId,
632
645
  type: "USER_PROMPT_REQ",
633
646
  from: {
634
- type: "runtime"
647
+ type: client.type
635
648
  },
636
649
  to: {
637
650
  type: "data-agent"
@@ -656,7 +669,7 @@ async function sendUserPromptSuggestionsRequest(client, prompt, limit = 5, timeo
656
669
  id: messageId,
657
670
  type: "USER_PROMPT_SUGGESTIONS_REQ",
658
671
  from: {
659
- type: "runtime"
672
+ type: client.type
660
673
  },
661
674
  to: {
662
675
  type: "data-agent"
@@ -676,7 +689,7 @@ async function requestBundle(client, options) {
676
689
  const message = BundleRequestMessageSchema.parse({
677
690
  id: messageId,
678
691
  type: "BUNDLE_REQ",
679
- from: { type: "runtime" },
692
+ from: { type: client.type },
680
693
  to: { type: "data-agent" },
681
694
  payload: {}
682
695
  });
@@ -724,7 +737,7 @@ async function requestData(client, options) {
724
737
  const message = DataRequestMessageSchema.parse({
725
738
  id: messageId,
726
739
  type: "DATA_REQ",
727
- from: { type: "runtime" },
740
+ from: { type: client.type },
728
741
  to: { type: "data-agent" },
729
742
  payload: {
730
743
  collection: options.collection,
@@ -766,7 +779,7 @@ async function sendComponents(client, components) {
766
779
  id: messageId,
767
780
  type: "COMPONENT_LIST_RES",
768
781
  from: {
769
- type: "runtime"
782
+ type: client.type
770
783
  },
771
784
  to: {
772
785
  type: "data-agent"
@@ -779,18 +792,21 @@ async function sendComponents(client, components) {
779
792
  }
780
793
 
781
794
  // src/services/users.ts
782
- async function createUser(client, username, password, timeout) {
795
+ async function createUser(client, username, password, email, fullname, role, timeout) {
783
796
  const messageId = `users_create_${Date.now()}`;
784
797
  const message = UsersRequestMessageSchema.parse({
785
798
  id: messageId,
786
799
  type: "USERS",
787
- from: { type: "admin" },
800
+ from: { type: client.type },
788
801
  to: { type: "data-agent" },
789
802
  payload: {
790
803
  operation: "create",
791
804
  data: {
792
805
  username,
793
- password
806
+ password,
807
+ email,
808
+ fullname,
809
+ role
794
810
  }
795
811
  }
796
812
  });
@@ -800,21 +816,24 @@ async function createUser(client, username, password, timeout) {
800
816
  success: payload.success,
801
817
  error: payload.error,
802
818
  message: payload.data?.message,
803
- username: payload.data?.username
819
+ username: payload.data?.username,
820
+ email: payload.data?.email,
821
+ fullname: payload.data?.fullname,
822
+ role: payload.data?.role
804
823
  };
805
824
  }
806
- async function updateUser(client, username, password, timeout) {
825
+ async function updateUser(client, username, updates, timeout) {
807
826
  const messageId = `users_update_${Date.now()}`;
808
827
  const message = UsersRequestMessageSchema.parse({
809
828
  id: messageId,
810
829
  type: "USERS",
811
- from: { type: "admin" },
830
+ from: { type: client.type },
812
831
  to: { type: "data-agent" },
813
832
  payload: {
814
833
  operation: "update",
815
834
  data: {
816
835
  username,
817
- password
836
+ ...updates
818
837
  }
819
838
  }
820
839
  });
@@ -824,7 +843,10 @@ async function updateUser(client, username, password, timeout) {
824
843
  success: payload.success,
825
844
  error: payload.error,
826
845
  message: payload.data?.message,
827
- username: payload.data?.username
846
+ username: payload.data?.username,
847
+ email: payload.data?.email,
848
+ fullname: payload.data?.fullname,
849
+ role: payload.data?.role
828
850
  };
829
851
  }
830
852
  async function deleteUser(client, username, timeout) {
@@ -832,7 +854,7 @@ async function deleteUser(client, username, timeout) {
832
854
  const message = UsersRequestMessageSchema.parse({
833
855
  id: messageId,
834
856
  type: "USERS",
835
- from: { type: "admin" },
857
+ from: { type: client.type },
836
858
  to: { type: "data-agent" },
837
859
  payload: {
838
860
  operation: "delete",
@@ -847,7 +869,10 @@ async function deleteUser(client, username, timeout) {
847
869
  success: payload.success,
848
870
  error: payload.error,
849
871
  message: payload.data?.message,
850
- username: payload.data?.username
872
+ username: payload.data?.username,
873
+ email: payload.data?.email,
874
+ fullname: payload.data?.fullname,
875
+ role: payload.data?.role
851
876
  };
852
877
  }
853
878
  async function getAllUsers(client, timeout) {
@@ -855,7 +880,7 @@ async function getAllUsers(client, timeout) {
855
880
  const message = UsersRequestMessageSchema.parse({
856
881
  id: messageId,
857
882
  type: "USERS",
858
- from: { type: "admin" },
883
+ from: { type: client.type },
859
884
  to: { type: "data-agent" },
860
885
  payload: {
861
886
  operation: "getAll"
@@ -876,7 +901,7 @@ async function getUser(client, username, timeout) {
876
901
  const message = UsersRequestMessageSchema.parse({
877
902
  id: messageId,
878
903
  type: "USERS",
879
- from: { type: "admin" },
904
+ from: { type: client.type },
880
905
  to: { type: "data-agent" },
881
906
  payload: {
882
907
  operation: "getOne",
@@ -901,7 +926,7 @@ async function createDashboard(client, dashboardId, dashboard, timeout) {
901
926
  const message = DashboardsRequestMessageSchema.parse({
902
927
  id: messageId,
903
928
  type: "DASHBOARDS",
904
- from: { type: "admin" },
929
+ from: { type: client.type },
905
930
  to: { type: "data-agent" },
906
931
  payload: {
907
932
  operation: "create",
@@ -926,7 +951,7 @@ async function updateDashboard(client, dashboardId, dashboard, timeout) {
926
951
  const message = DashboardsRequestMessageSchema.parse({
927
952
  id: messageId,
928
953
  type: "DASHBOARDS",
929
- from: { type: "admin" },
954
+ from: { type: client.type },
930
955
  to: { type: "data-agent" },
931
956
  payload: {
932
957
  operation: "update",
@@ -951,7 +976,7 @@ async function deleteDashboard(client, dashboardId, timeout) {
951
976
  const message = DashboardsRequestMessageSchema.parse({
952
977
  id: messageId,
953
978
  type: "DASHBOARDS",
954
- from: { type: "admin" },
979
+ from: { type: client.type },
955
980
  to: { type: "data-agent" },
956
981
  payload: {
957
982
  operation: "delete",
@@ -974,7 +999,7 @@ async function getAllDashboards(client, timeout) {
974
999
  const message = DashboardsRequestMessageSchema.parse({
975
1000
  id: messageId,
976
1001
  type: "DASHBOARDS",
977
- from: { type: "admin" },
1002
+ from: { type: client.type },
978
1003
  to: { type: "data-agent" },
979
1004
  payload: {
980
1005
  operation: "getAll"
@@ -995,7 +1020,7 @@ async function getDashboard(client, dashboardId, timeout) {
995
1020
  const message = DashboardsRequestMessageSchema.parse({
996
1021
  id: messageId,
997
1022
  type: "DASHBOARDS",
998
- from: { type: "admin" },
1023
+ from: { type: client.type },
999
1024
  to: { type: "data-agent" },
1000
1025
  payload: {
1001
1026
  operation: "getOne",
@@ -1021,7 +1046,7 @@ async function createReport(client, reportId, report, timeout) {
1021
1046
  const message = ReportsRequestMessageSchema.parse({
1022
1047
  id: messageId,
1023
1048
  type: "REPORTS",
1024
- from: { type: "admin" },
1049
+ from: { type: client.type },
1025
1050
  to: { type: "data-agent" },
1026
1051
  payload: {
1027
1052
  operation: "create",
@@ -1046,7 +1071,7 @@ async function updateReport(client, reportId, report, timeout) {
1046
1071
  const message = ReportsRequestMessageSchema.parse({
1047
1072
  id: messageId,
1048
1073
  type: "REPORTS",
1049
- from: { type: "admin" },
1074
+ from: { type: client.type },
1050
1075
  to: { type: "data-agent" },
1051
1076
  payload: {
1052
1077
  operation: "update",
@@ -1071,7 +1096,7 @@ async function deleteReport(client, reportId, timeout) {
1071
1096
  const message = ReportsRequestMessageSchema.parse({
1072
1097
  id: messageId,
1073
1098
  type: "REPORTS",
1074
- from: { type: "admin" },
1099
+ from: { type: client.type },
1075
1100
  to: { type: "data-agent" },
1076
1101
  payload: {
1077
1102
  operation: "delete",
@@ -1094,7 +1119,7 @@ async function getAllReports(client, timeout) {
1094
1119
  const message = ReportsRequestMessageSchema.parse({
1095
1120
  id: messageId,
1096
1121
  type: "REPORTS",
1097
- from: { type: "admin" },
1122
+ from: { type: client.type },
1098
1123
  to: { type: "data-agent" },
1099
1124
  payload: {
1100
1125
  operation: "getAll"
@@ -1115,7 +1140,7 @@ async function getReport(client, reportId, timeout) {
1115
1140
  const message = ReportsRequestMessageSchema.parse({
1116
1141
  id: messageId,
1117
1142
  type: "REPORTS",
1118
- from: { type: "admin" },
1143
+ from: { type: client.type },
1119
1144
  to: { type: "data-agent" },
1120
1145
  payload: {
1121
1146
  operation: "getOne",
@@ -1141,7 +1166,7 @@ async function getActions(client, options) {
1141
1166
  const message = ActionsRequestMessageSchema.parse({
1142
1167
  id: messageId,
1143
1168
  type: "ACTIONS",
1144
- from: { type: "runtime" },
1169
+ from: { type: client.type },
1145
1170
  to: { type: "data-agent" },
1146
1171
  payload: {
1147
1172
  SA_RUNTIME: options.SA_RUNTIME
@@ -1329,7 +1354,7 @@ var SuperatomClient = class {
1329
1354
  }
1330
1355
  const fullMessage = {
1331
1356
  ...message,
1332
- from: message.from || { type: "runtime" }
1357
+ from: message.from || { type: this.config.type }
1333
1358
  };
1334
1359
  try {
1335
1360
  this.socket.send(JSON.stringify(fullMessage));
@@ -1407,6 +1432,12 @@ var SuperatomClient = class {
1407
1432
  getReconnectAttempts() {
1408
1433
  return this.reconnectAttempts;
1409
1434
  }
1435
+ /**
1436
+ * Get client type
1437
+ */
1438
+ get type() {
1439
+ return this.config.type;
1440
+ }
1410
1441
  /**
1411
1442
  * Send a message and wait for response with timeout (alias for sendWithResponse)
1412
1443
  */
@@ -1489,17 +1520,17 @@ var SuperatomClient = class {
1489
1520
  * Create a new user
1490
1521
  * Delegates to users service
1491
1522
  */
1492
- async createUser(username, password, timeout) {
1523
+ async createUser(username, password, email, fullname, role, timeout) {
1493
1524
  this.log("info", "Creating user:", username);
1494
- return createUser(this, username, password, timeout);
1525
+ return createUser(this, username, password, email, fullname, role, timeout);
1495
1526
  }
1496
1527
  /**
1497
1528
  * Update an existing user
1498
1529
  * Delegates to users service
1499
1530
  */
1500
- async updateUser(username, password, timeout) {
1531
+ async updateUser(username, updates, timeout) {
1501
1532
  this.log("info", "Updating user:", username);
1502
- return updateUser(this, username, password, timeout);
1533
+ return updateUser(this, username, updates, timeout);
1503
1534
  }
1504
1535
  /**
1505
1536
  * Delete a user