@docbrasil/api-systemmanager 1.1.76 → 1.1.78

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.
@@ -215,6 +215,220 @@ class AdminLists {
215
215
  throw ex;
216
216
  }
217
217
  }
218
+
219
+ /**
220
+ * @author Myndware <augusto.pissarra@myndware.com>
221
+ * @description Filter organization lists by name
222
+ * @param {object} params Parameters
223
+ * @param {string} params.orgId Organization ID (required)
224
+ * @param {array} [params.names=[]] Array of list names to filter (empty = all)
225
+ * @param {string} session JWT session token
226
+ * @return {Promise<array>} Array of matching org lists sorted by name
227
+ * @public
228
+ * @async
229
+ * @example
230
+ *
231
+ * const API = require('@docbrasil/api-systemmanager');
232
+ * const api = new API();
233
+ * const params = { orgId: '5edd11c46b6ce9729c2c297c', names: ['Tags', 'Categorias'] };
234
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
235
+ * const lists = await api.admin.list.filterByName(params, session);
236
+ */
237
+ async filterByName(params = {}, session) {
238
+ const self = this;
239
+
240
+ try {
241
+ Joi.assert(params, Joi.object().required());
242
+ Joi.assert(params.orgId, Joi.string().required());
243
+ Joi.assert(session, Joi.string().required());
244
+
245
+ const { orgId, names = [] } = params;
246
+ const payload = { names };
247
+
248
+ const apiCall = self._client.post(
249
+ `/admin/organizations/${orgId}/orgtags/filter`,
250
+ payload,
251
+ self._setHeader(session)
252
+ );
253
+
254
+ return self._returnData(await apiCall);
255
+ } catch (ex) {
256
+ throw ex;
257
+ }
258
+ }
259
+
260
+ /**
261
+ * @author Myndware <augusto.pissarra@myndware.com>
262
+ * @description Create a new organization list
263
+ * @param {object} params Parameters
264
+ * @param {string} params.orgId Organization ID (required)
265
+ * @param {string} params.name List name (required)
266
+ * @param {array} [params.list=[]] Initial list items
267
+ * @param {string} session JWT session token
268
+ * @return {Promise<object>} Created list document
269
+ * @public
270
+ * @async
271
+ * @example
272
+ *
273
+ * const API = require('@docbrasil/api-systemmanager');
274
+ * const api = new API();
275
+ * const params = { orgId: '5edd11c46b6ce9729c2c297c', name: 'My List', list: [] };
276
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
277
+ * const list = await api.admin.list.create(params, session);
278
+ */
279
+ async create(params = {}, session) {
280
+ const self = this;
281
+
282
+ try {
283
+ Joi.assert(params, Joi.object().required());
284
+ Joi.assert(params.orgId, Joi.string().required());
285
+ Joi.assert(params.name, Joi.string().required());
286
+ Joi.assert(session, Joi.string().required());
287
+
288
+ const { orgId, name, list = [] } = params;
289
+ const payload = { orgId, name, list };
290
+
291
+ const apiCall = self._client.put(
292
+ `/admin/organizations/${orgId}/orgtags`,
293
+ payload,
294
+ self._setHeader(session)
295
+ );
296
+
297
+ return self._returnData(await apiCall);
298
+ } catch (ex) {
299
+ throw ex;
300
+ }
301
+ }
302
+
303
+ /**
304
+ * @author Myndware <augusto.pissarra@myndware.com>
305
+ * @description Update an organization list
306
+ * @param {object} params Parameters
307
+ * @param {string} params.orgId Organization ID (required)
308
+ * @param {string} params.id List ID (required)
309
+ * @param {object} params.data Fields to update (name, list, etc.)
310
+ * @param {string} session JWT session token
311
+ * @return {Promise<object>} Updated list document
312
+ * @public
313
+ * @async
314
+ * @example
315
+ *
316
+ * const API = require('@docbrasil/api-systemmanager');
317
+ * const api = new API();
318
+ * const params = { orgId: '5edd11c46b6ce9729c2c297c', id: '55e4a3bd6be6b45210833fae', data: { name: 'Renamed' } };
319
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
320
+ * const list = await api.admin.list.update(params, session);
321
+ */
322
+ async update(params = {}, session) {
323
+ const self = this;
324
+
325
+ try {
326
+ Joi.assert(params, Joi.object().required());
327
+ Joi.assert(params.orgId, Joi.string().required());
328
+ Joi.assert(params.id, Joi.string().required());
329
+ Joi.assert(params.data, Joi.object().required());
330
+ Joi.assert(session, Joi.string().required());
331
+
332
+ const { orgId, id, data } = params;
333
+
334
+ const apiCall = self._client.put(
335
+ `/admin/organizations/${orgId}/orgtags/${id}`,
336
+ data,
337
+ self._setHeader(session)
338
+ );
339
+
340
+ return self._returnData(await apiCall);
341
+ } catch (ex) {
342
+ throw ex;
343
+ }
344
+ }
345
+
346
+ /**
347
+ * @author Myndware <augusto.pissarra@myndware.com>
348
+ * @description Remove an organization list
349
+ * @param {object} params Parameters
350
+ * @param {string} params.orgId Organization ID (required)
351
+ * @param {string} params.id List ID to remove (required)
352
+ * @param {string} session JWT session token
353
+ * @return {Promise<object>} Removal confirmation
354
+ * @public
355
+ * @async
356
+ * @example
357
+ *
358
+ * const API = require('@docbrasil/api-systemmanager');
359
+ * const api = new API();
360
+ * const params = { orgId: '5edd11c46b6ce9729c2c297c', id: '55e4a3bd6be6b45210833fae' };
361
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
362
+ * await api.admin.list.remove(params, session);
363
+ */
364
+ async remove(params = {}, session) {
365
+ const self = this;
366
+
367
+ try {
368
+ Joi.assert(params, Joi.object().required());
369
+ Joi.assert(params.orgId, Joi.string().required());
370
+ Joi.assert(params.id, Joi.string().required());
371
+ Joi.assert(session, Joi.string().required());
372
+
373
+ const { orgId, id } = params;
374
+
375
+ const apiCall = self._client.delete(
376
+ `/admin/organizations/${orgId}/orgtags/${id}`,
377
+ self._setHeader(session)
378
+ );
379
+
380
+ return self._returnData(await apiCall);
381
+ } catch (ex) {
382
+ throw ex;
383
+ }
384
+ }
385
+
386
+ /**
387
+ * @author Myndware <augusto.pissarra@myndware.com>
388
+ * @description Update list items of an organization list
389
+ * @param {object} params Parameters
390
+ * @param {string} params.orgId Organization ID (required)
391
+ * @param {string} params.id List ID (required)
392
+ * @param {array} params.list Updated list items array (required)
393
+ * @param {string} session JWT session token
394
+ * @return {Promise<object>} Updated list document
395
+ * @public
396
+ * @async
397
+ * @example
398
+ *
399
+ * const API = require('@docbrasil/api-systemmanager');
400
+ * const api = new API();
401
+ * const params = {
402
+ * orgId: '5edd11c46b6ce9729c2c297c',
403
+ * id: '55e4a3bd6be6b45210833fae',
404
+ * list: [{ _id: '1', value: 'Item 1', filter: '', order: 0 }]
405
+ * };
406
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
407
+ * const list = await api.admin.list.updateListItems(params, session);
408
+ */
409
+ async updateListItems(params = {}, session) {
410
+ const self = this;
411
+
412
+ try {
413
+ Joi.assert(params, Joi.object().required());
414
+ Joi.assert(params.orgId, Joi.string().required());
415
+ Joi.assert(params.id, Joi.string().required());
416
+ Joi.assert(params.list, Joi.array().required());
417
+ Joi.assert(session, Joi.string().required());
418
+
419
+ const { orgId, id, list } = params;
420
+
421
+ const apiCall = self._client.put(
422
+ `/admin/organizations/${orgId}/orgtags/${id}`,
423
+ { list },
424
+ self._setHeader(session)
425
+ );
426
+
427
+ return self._returnData(await apiCall);
428
+ } catch (ex) {
429
+ throw ex;
430
+ }
431
+ }
218
432
  }
219
433
 
220
434
  export default AdminLists;
@@ -298,6 +298,83 @@ class AdminUser {
298
298
  }
299
299
  }
300
300
 
301
+ /**
302
+ * @author Myndware <augusto.pissarra@myndware.com>
303
+ * @description Create a new user
304
+ * @param {object} payload User data to create
305
+ * @param {string} payload.name Full name (required)
306
+ * @param {string} payload.username Username (required)
307
+ * @param {string} payload.email Email (required)
308
+ * @param {string} payload.orgId Primary organization ID (required)
309
+ * @param {array} [payload.orgIds] Organization IDs
310
+ * @param {array} [payload.role=[2]] Security roles
311
+ * @param {string} [payload.password] Initial password
312
+ * @param {string} session JWT session token
313
+ * @return {Promise<object>} Created user document
314
+ * @public
315
+ * @async
316
+ * @example
317
+ *
318
+ * const API = require('@docbrasil/api-systemmanager');
319
+ * const api = new API();
320
+ * const payload = {
321
+ * name: 'Maria Silva',
322
+ * username: 'maria.silva',
323
+ * email: 'maria@example.com',
324
+ * orgId: '5edd11c46b6ce9729c2c297c',
325
+ * role: [2]
326
+ * };
327
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
328
+ * await api.admin.user.create(payload, session);
329
+ */
330
+ async create(payload, session) {
331
+ const self = this;
332
+
333
+ try {
334
+ Joi.assert(payload, Joi.object().required(), 'User data to create');
335
+ Joi.assert(payload.name, Joi.string().required(), 'Full name');
336
+ Joi.assert(payload.username, Joi.string().required(), 'Username');
337
+ Joi.assert(payload.email, Joi.string().email().required(), 'Email');
338
+ Joi.assert(payload.orgId, Joi.string().required(), 'Primary organization ID');
339
+ Joi.assert(session, Joi.string().required(), 'Session token');
340
+
341
+ const apiCall = self.client.post('/admin/users', payload, self._setHeader(session));
342
+ return self._returnData(await apiCall);
343
+ } catch (ex) {
344
+ throw ex;
345
+ }
346
+ }
347
+
348
+ /**
349
+ * @author Myndware <augusto.pissarra@myndware.com>
350
+ * @description Remove a user
351
+ * @param {string} userId User ID to remove (required)
352
+ * @param {string} session JWT session token
353
+ * @return {Promise<object>} Removal confirmation
354
+ * @public
355
+ * @async
356
+ * @example
357
+ *
358
+ * const API = require('@docbrasil/api-systemmanager');
359
+ * const api = new API();
360
+ * const userId = '55e4a3bd6be6b45210833fae';
361
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
362
+ * await api.admin.user.remove(userId, session);
363
+ */
364
+ async remove(userId, session) {
365
+ const self = this;
366
+
367
+ try {
368
+ Joi.assert(userId, Joi.string().required(), 'User ID');
369
+ Joi.assert(session, Joi.string().required(), 'Session token');
370
+
371
+ const apiCall = self.client.delete(`/admin/users/${userId}`, self._setHeader(session));
372
+ return self._returnData(await apiCall);
373
+ } catch (ex) {
374
+ throw ex;
375
+ }
376
+ }
377
+
301
378
  /**
302
379
  * @description Request GUID to change the password
303
380
  * @param {string} email - User email
@@ -405,7 +482,7 @@ class AdminUser {
405
482
 
406
483
  const payloadToSend = {$project: project, sort};
407
484
 
408
- const apiCall = self._client
485
+ const apiCall = self.client
409
486
  .post(`/admin/users?page=${page}&perPage=${perPage}`, payloadToSend, self._setHeader(session));
410
487
 
411
488
  return self._returnData(await apiCall);
@@ -414,6 +491,291 @@ class AdminUser {
414
491
  throw ex;
415
492
  }
416
493
  }
494
+
495
+ /**
496
+ * @author Myndware <augusto.pissarra@myndware.com>
497
+ * @description Block a user (prevent login)
498
+ * @param {string} userId User ID to block (required)
499
+ * @param {string} session JWT session token
500
+ * @return {Promise<object>} Updated user
501
+ * @public
502
+ * @async
503
+ * @example
504
+ *
505
+ * const API = require('@docbrasil/api-systemmanager');
506
+ * const api = new API();
507
+ * const userId = '55e4a3bd6be6b45210833fae';
508
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
509
+ * await api.admin.user.block(userId, session);
510
+ */
511
+ async block(userId, session) {
512
+ const self = this;
513
+
514
+ try {
515
+ Joi.assert(userId, Joi.string().required(), 'User ID');
516
+ Joi.assert(session, Joi.string().required(), 'Session token');
517
+
518
+ const apiCall = self.client.put(`/admin/users/${userId}/block`, {}, self._setHeader(session));
519
+ return self._returnData(await apiCall);
520
+ } catch (ex) {
521
+ throw ex;
522
+ }
523
+ }
524
+
525
+ /**
526
+ * @author Myndware <augusto.pissarra@myndware.com>
527
+ * @description Unblock a user (allow login)
528
+ * @param {string} userId User ID to unblock (required)
529
+ * @param {string} session JWT session token
530
+ * @return {Promise<object>} Updated user
531
+ * @public
532
+ * @async
533
+ * @example
534
+ *
535
+ * const API = require('@docbrasil/api-systemmanager');
536
+ * const api = new API();
537
+ * const userId = '55e4a3bd6be6b45210833fae';
538
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
539
+ * await api.admin.user.unblock(userId, session);
540
+ */
541
+ async unblock(userId, session) {
542
+ const self = this;
543
+
544
+ try {
545
+ Joi.assert(userId, Joi.string().required(), 'User ID');
546
+ Joi.assert(session, Joi.string().required(), 'Session token');
547
+
548
+ const apiCall = self.client.put(`/admin/users/${userId}/unblock`, {}, self._setHeader(session));
549
+ return self._returnData(await apiCall);
550
+ } catch (ex) {
551
+ throw ex;
552
+ }
553
+ }
554
+
555
+ /**
556
+ * @author Myndware <augusto.pissarra@myndware.com>
557
+ * @description Block email notifications for a user
558
+ * @param {string} userId User ID (required)
559
+ * @param {string} session JWT session token
560
+ * @return {Promise<object>} Updated user
561
+ * @public
562
+ * @async
563
+ */
564
+ async blockEmail(userId, session) {
565
+ const self = this;
566
+
567
+ try {
568
+ Joi.assert(userId, Joi.string().required(), 'User ID');
569
+ Joi.assert(session, Joi.string().required(), 'Session token');
570
+
571
+ const apiCall = self.client.put(`/admin/users/${userId}/blockemail`, {}, self._setHeader(session));
572
+ return self._returnData(await apiCall);
573
+ } catch (ex) {
574
+ throw ex;
575
+ }
576
+ }
577
+
578
+ /**
579
+ * @author Myndware <augusto.pissarra@myndware.com>
580
+ * @description Unblock email notifications for a user
581
+ * @param {string} userId User ID (required)
582
+ * @param {string} session JWT session token
583
+ * @return {Promise<object>} Updated user
584
+ * @public
585
+ * @async
586
+ */
587
+ async unblockEmail(userId, session) {
588
+ const self = this;
589
+
590
+ try {
591
+ Joi.assert(userId, Joi.string().required(), 'User ID');
592
+ Joi.assert(session, Joi.string().required(), 'Session token');
593
+
594
+ const apiCall = self.client.put(`/admin/users/${userId}/unblockemail`, {}, self._setHeader(session));
595
+ return self._returnData(await apiCall);
596
+ } catch (ex) {
597
+ throw ex;
598
+ }
599
+ }
600
+
601
+ /**
602
+ * @author Myndware <augusto.pissarra@myndware.com>
603
+ * @description Update user type classification
604
+ * @param {object} params Parameters
605
+ * @param {string} params.userId User ID (required)
606
+ * @param {string} params.userType New user type (required)
607
+ * @param {string} session JWT session token
608
+ * @return {Promise<object>} Updated user
609
+ * @public
610
+ * @async
611
+ * @example
612
+ *
613
+ * const API = require('@docbrasil/api-systemmanager');
614
+ * const api = new API();
615
+ * const params = { userId: '55e4a3bd6be6b45210833fae', userType: 'USER' };
616
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
617
+ * await api.admin.user.updateUserType(params, session);
618
+ */
619
+ async updateUserType(params, session) {
620
+ const self = this;
621
+
622
+ try {
623
+ Joi.assert(params, Joi.object().required(), 'Parameters');
624
+ Joi.assert(params.userId, Joi.string().required(), 'User ID');
625
+ Joi.assert(params.userType, Joi.string().required(), 'User type');
626
+ Joi.assert(session, Joi.string().required(), 'Session token');
627
+
628
+ const { userId, userType } = params;
629
+ const apiCall = self.client.put(`/admin/users/${userId}/type/${userType}`, {}, self._setHeader(session));
630
+ return self._returnData(await apiCall);
631
+ } catch (ex) {
632
+ throw ex;
633
+ }
634
+ }
635
+
636
+ /**
637
+ * @author Myndware <augusto.pissarra@myndware.com>
638
+ * @description Get organization groups with their permissions
639
+ * @param {string} orgId Organization ID (required)
640
+ * @param {string} session JWT session token
641
+ * @return {Promise<array>} Array of groups with permissions
642
+ * @public
643
+ * @async
644
+ * @example
645
+ *
646
+ * const API = require('@docbrasil/api-systemmanager');
647
+ * const api = new API();
648
+ * const orgId = '5edd11c46b6ce9729c2c297c';
649
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
650
+ * const groups = await api.admin.user.getGroupsPermissions(orgId, session);
651
+ */
652
+ async getGroupsPermissions(orgId, session) {
653
+ const self = this;
654
+
655
+ try {
656
+ Joi.assert(orgId, Joi.string().required(), 'Organization ID');
657
+ Joi.assert(session, Joi.string().required(), 'Session token');
658
+
659
+ const apiCall = self.client.get(
660
+ `/admin/organizations/${orgId}/orgchart/groups/permissions`,
661
+ self._setHeader(session)
662
+ );
663
+ return self._returnData(await apiCall);
664
+ } catch (ex) {
665
+ throw ex;
666
+ }
667
+ }
668
+
669
+ /**
670
+ * @author Myndware <augusto.pissarra@myndware.com>
671
+ * @description Update user's group memberships in an organization
672
+ * @param {object} params Parameters
673
+ * @param {string} params.orgId Organization ID (required)
674
+ * @param {string} params.userId User ID (required)
675
+ * @param {array} params.groups Array of group IDs (required)
676
+ * @param {string} session JWT session token
677
+ * @return {Promise<object>} Updated groups
678
+ * @public
679
+ * @async
680
+ * @example
681
+ *
682
+ * const API = require('@docbrasil/api-systemmanager');
683
+ * const api = new API();
684
+ * const params = {
685
+ * orgId: '5edd11c46b6ce9729c2c297c',
686
+ * userId: '55e4a3bd6be6b45210833fae',
687
+ * groups: ['groupId1', 'groupId2']
688
+ * };
689
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
690
+ * await api.admin.user.updateUserGroups(params, session);
691
+ */
692
+ async updateUserGroups(params, session) {
693
+ const self = this;
694
+
695
+ try {
696
+ Joi.assert(params, Joi.object().required(), 'Parameters');
697
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization ID');
698
+ Joi.assert(params.userId, Joi.string().required(), 'User ID');
699
+ Joi.assert(params.groups, Joi.array().required(), 'Group IDs');
700
+ Joi.assert(session, Joi.string().required(), 'Session token');
701
+
702
+ const { orgId, userId, groups } = params;
703
+ const apiCall = self.client.put(
704
+ `/admin/organizations/${orgId}/orgchart/groups/${userId}`,
705
+ { groups },
706
+ self._setHeader(session)
707
+ );
708
+ return self._returnData(await apiCall);
709
+ } catch (ex) {
710
+ throw ex;
711
+ }
712
+ }
713
+
714
+ /**
715
+ * @author Myndware <augusto.pissarra@myndware.com>
716
+ * @description Get organizations the admin user can manage
717
+ * @param {string} session JWT session token
718
+ * @return {Promise<array>} Array of organizations
719
+ * @public
720
+ * @async
721
+ * @example
722
+ *
723
+ * const API = require('@docbrasil/api-systemmanager');
724
+ * const api = new API();
725
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
726
+ * const orgs = await api.admin.user.getOrganizations(session);
727
+ */
728
+ async getOrganizations(session) {
729
+ const self = this;
730
+
731
+ try {
732
+ Joi.assert(session, Joi.string().required(), 'Session token');
733
+
734
+ const apiCall = self.client.get('/admin/users/organizations', self._setHeader(session));
735
+ return self._returnData(await apiCall);
736
+ } catch (ex) {
737
+ throw ex;
738
+ }
739
+ }
740
+
741
+ /**
742
+ * @author Myndware <augusto.pissarra@myndware.com>
743
+ * @description Get users belonging to an organization
744
+ * @param {object} params Parameters
745
+ * @param {string} params.orgId Organization ID (required)
746
+ * @param {array} [params.userIds] Optional array of user IDs to filter
747
+ * @param {string} session JWT session token
748
+ * @return {Promise<array>} Array of users with id, name, email, title
749
+ * @public
750
+ * @async
751
+ * @example
752
+ *
753
+ * const API = require('@docbrasil/api-systemmanager');
754
+ * const api = new API();
755
+ * const params = { orgId: '5edd11c46b6ce9729c2c297c' };
756
+ * const session = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
757
+ * const users = await api.admin.user.getOrgUsers(params, session);
758
+ */
759
+ async getOrgUsers(params, session) {
760
+ const self = this;
761
+
762
+ try {
763
+ Joi.assert(params, Joi.object().required(), 'Parameters');
764
+ Joi.assert(params.orgId, Joi.string().required(), 'Organization ID');
765
+ Joi.assert(session, Joi.string().required(), 'Session token');
766
+
767
+ const { orgId, userIds } = params;
768
+ let url = `/admin/organizations/${orgId}/orgusers`;
769
+ if (userIds && userIds.length > 0) {
770
+ url += `?userIds=${JSON.stringify(userIds)}`;
771
+ }
772
+
773
+ const apiCall = self.client.get(url, self._setHeader(session));
774
+ return self._returnData(await apiCall);
775
+ } catch (ex) {
776
+ throw ex;
777
+ }
778
+ }
417
779
  }
418
780
 
419
781
  export default AdminUser;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docbrasil/api-systemmanager",
3
3
  "description": "Module API System Manager",
4
- "version": "1.1.76",
4
+ "version": "1.1.78",
5
5
  "scripts": {
6
6
  "htmldoc": "rm -rf docs && jsdoc api/** -d docs -t ./node_modules/better-docs",
7
7
  "doc": "rm -rf doc && mkdir doc && jsdoc2md api/**/* api/* > doc/api.md",