@superatomai/sdk-web 0.0.7 → 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()
@@ -780,7 +792,7 @@ async function sendComponents(client, components) {
780
792
  }
781
793
 
782
794
  // src/services/users.ts
783
- async function createUser(client, username, password, timeout) {
795
+ async function createUser(client, username, password, email, fullname, role, timeout) {
784
796
  const messageId = `users_create_${Date.now()}`;
785
797
  const message = UsersRequestMessageSchema.parse({
786
798
  id: messageId,
@@ -791,7 +803,10 @@ async function createUser(client, username, password, timeout) {
791
803
  operation: "create",
792
804
  data: {
793
805
  username,
794
- password
806
+ password,
807
+ email,
808
+ fullname,
809
+ role
795
810
  }
796
811
  }
797
812
  });
@@ -801,10 +816,13 @@ async function createUser(client, username, password, timeout) {
801
816
  success: payload.success,
802
817
  error: payload.error,
803
818
  message: payload.data?.message,
804
- username: payload.data?.username
819
+ username: payload.data?.username,
820
+ email: payload.data?.email,
821
+ fullname: payload.data?.fullname,
822
+ role: payload.data?.role
805
823
  };
806
824
  }
807
- async function updateUser(client, username, password, timeout) {
825
+ async function updateUser(client, username, updates, timeout) {
808
826
  const messageId = `users_update_${Date.now()}`;
809
827
  const message = UsersRequestMessageSchema.parse({
810
828
  id: messageId,
@@ -815,7 +833,7 @@ async function updateUser(client, username, password, timeout) {
815
833
  operation: "update",
816
834
  data: {
817
835
  username,
818
- password
836
+ ...updates
819
837
  }
820
838
  }
821
839
  });
@@ -825,7 +843,10 @@ async function updateUser(client, username, password, timeout) {
825
843
  success: payload.success,
826
844
  error: payload.error,
827
845
  message: payload.data?.message,
828
- username: payload.data?.username
846
+ username: payload.data?.username,
847
+ email: payload.data?.email,
848
+ fullname: payload.data?.fullname,
849
+ role: payload.data?.role
829
850
  };
830
851
  }
831
852
  async function deleteUser(client, username, timeout) {
@@ -848,7 +869,10 @@ async function deleteUser(client, username, timeout) {
848
869
  success: payload.success,
849
870
  error: payload.error,
850
871
  message: payload.data?.message,
851
- username: payload.data?.username
872
+ username: payload.data?.username,
873
+ email: payload.data?.email,
874
+ fullname: payload.data?.fullname,
875
+ role: payload.data?.role
852
876
  };
853
877
  }
854
878
  async function getAllUsers(client, timeout) {
@@ -1496,17 +1520,17 @@ var SuperatomClient = class {
1496
1520
  * Create a new user
1497
1521
  * Delegates to users service
1498
1522
  */
1499
- async createUser(username, password, timeout) {
1523
+ async createUser(username, password, email, fullname, role, timeout) {
1500
1524
  this.log("info", "Creating user:", username);
1501
- return createUser(this, username, password, timeout);
1525
+ return createUser(this, username, password, email, fullname, role, timeout);
1502
1526
  }
1503
1527
  /**
1504
1528
  * Update an existing user
1505
1529
  * Delegates to users service
1506
1530
  */
1507
- async updateUser(username, password, timeout) {
1531
+ async updateUser(username, updates, timeout) {
1508
1532
  this.log("info", "Updating user:", username);
1509
- return updateUser(this, username, password, timeout);
1533
+ return updateUser(this, username, updates, timeout);
1510
1534
  }
1511
1535
  /**
1512
1536
  * Delete a user