roboto-js 1.7.5 → 1.8.2

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.
@@ -408,47 +408,492 @@ var RbtObject = /*#__PURE__*/function () {
408
408
  }
409
409
  return save;
410
410
  }()
411
+ /**
412
+ * Grants access to this object for specific users and/or user groups.
413
+ * Updates the IAC (Identity and Access Control) permissions.
414
+ *
415
+ * @param {Object} options - Access grant options
416
+ * @param {string[]} [options.userIds=[]] - Array of user IDs to grant read access
417
+ * @param {string[]} [options.groupIds=[]] - Array of user group IDs to grant read access
418
+ * @param {boolean} [options.write=false] - If true, grants write access instead of read access
419
+ * @param {boolean} [options.replace=false] - If true, replaces existing grants; if false, merges with existing
420
+ * @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
421
+ * @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
422
+ *
423
+ * @example
424
+ * // Grant read access to specific users
425
+ * await myObject.grantAccess({
426
+ * userIds: ['user123', 'user456']
427
+ * });
428
+ *
429
+ * @example
430
+ * // Grant read access to user groups
431
+ * await myObject.grantAccess({
432
+ * groupIds: ['grpRngAccount', 'grpAdmins']
433
+ * });
434
+ *
435
+ * @example
436
+ * // Grant write access to users and groups
437
+ * await myObject.grantAccess({
438
+ * userIds: ['user123'],
439
+ * groupIds: ['grpAdmins'],
440
+ * write: true
441
+ * });
442
+ *
443
+ * @example
444
+ * // Replace existing permissions instead of merging
445
+ * await myObject.grantAccess({
446
+ * userIds: ['user123'],
447
+ * replace: true
448
+ * });
449
+ *
450
+ * @example
451
+ * // Update permissions without auto-saving
452
+ * await myObject.grantAccess({
453
+ * userIds: ['user123'],
454
+ * save: false
455
+ * });
456
+ * // ... make other changes ...
457
+ * await myObject.save();
458
+ */
459
+ }, {
460
+ key: "grantAccess",
461
+ value: (function () {
462
+ var _grantAccess = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
463
+ var options,
464
+ _options$userIds,
465
+ userIds,
466
+ _options$groupIds,
467
+ groupIds,
468
+ _options$write,
469
+ write,
470
+ _options$replace,
471
+ replace,
472
+ _options$save,
473
+ save,
474
+ iac,
475
+ grantType,
476
+ existingUsers,
477
+ mergedUsers,
478
+ existingGroups,
479
+ mergedGroups,
480
+ _args4 = arguments;
481
+ return _regenerator().w(function (_context4) {
482
+ while (1) switch (_context4.n) {
483
+ case 0:
484
+ options = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
485
+ _options$userIds = options.userIds, userIds = _options$userIds === void 0 ? [] : _options$userIds, _options$groupIds = options.groupIds, groupIds = _options$groupIds === void 0 ? [] : _options$groupIds, _options$write = options.write, write = _options$write === void 0 ? false : _options$write, _options$replace = options.replace, replace = _options$replace === void 0 ? false : _options$replace, _options$save = options.save, save = _options$save === void 0 ? true : _options$save; // Validate inputs
486
+ if (Array.isArray(userIds)) {
487
+ _context4.n = 1;
488
+ break;
489
+ }
490
+ throw new Error('userIds must be an array');
491
+ case 1:
492
+ if (Array.isArray(groupIds)) {
493
+ _context4.n = 2;
494
+ break;
495
+ }
496
+ throw new Error('groupIds must be an array');
497
+ case 2:
498
+ // Get current IAC settings
499
+ iac = this.get('iac') || {}; // Determine which grant type to update (read or write)
500
+ grantType = write ? 'writeGrants' : 'readGrants'; // Initialize grants if they don't exist
501
+ if (!iac[grantType]) {
502
+ iac[grantType] = {};
503
+ }
504
+
505
+ // Handle users
506
+ if (userIds.length > 0) {
507
+ if (replace) {
508
+ // Replace existing users
509
+ iac[grantType].users = _toConsumableArray(userIds);
510
+ } else {
511
+ // Merge with existing users (avoiding duplicates)
512
+ existingUsers = iac[grantType].users || [];
513
+ mergedUsers = _toConsumableArray(new Set([].concat(_toConsumableArray(existingUsers), _toConsumableArray(userIds))));
514
+ iac[grantType].users = mergedUsers;
515
+ }
516
+ }
517
+
518
+ // Handle user groups
519
+ if (groupIds.length > 0) {
520
+ if (replace) {
521
+ // Replace existing groups
522
+ iac[grantType].userGroups = _toConsumableArray(groupIds);
523
+ } else {
524
+ // Merge with existing groups (avoiding duplicates)
525
+ existingGroups = iac[grantType].userGroups || [];
526
+ mergedGroups = _toConsumableArray(new Set([].concat(_toConsumableArray(existingGroups), _toConsumableArray(groupIds))));
527
+ iac[grantType].userGroups = mergedGroups;
528
+ }
529
+ }
530
+
531
+ // Update the object
532
+ this.set('iac', iac);
533
+
534
+ // Save if requested
535
+ if (!save) {
536
+ _context4.n = 4;
537
+ break;
538
+ }
539
+ _context4.n = 3;
540
+ return this.save();
541
+ case 3:
542
+ return _context4.a(2, _context4.v);
543
+ case 4:
544
+ return _context4.a(2, this);
545
+ }
546
+ }, _callee4, this);
547
+ }));
548
+ function grantAccess() {
549
+ return _grantAccess.apply(this, arguments);
550
+ }
551
+ return grantAccess;
552
+ }()
553
+ /**
554
+ * Publishes this object to make it publicly accessible (or unpublishes it).
555
+ * Adds or removes 'public_user' from the IAC read permissions.
556
+ *
557
+ * @param {Object} options - Publishing options
558
+ * @param {boolean} [options.publish=true] - If true, publishes the object; if false, unpublishes it
559
+ * @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
560
+ * @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
561
+ *
562
+ * @example
563
+ * // Publish an object (make it public)
564
+ * await myObject.publishObject();
565
+ *
566
+ * @example
567
+ * // Unpublish an object (make it private)
568
+ * await myObject.publishObject({ publish: false });
569
+ *
570
+ * @example
571
+ * // Publish without auto-saving
572
+ * await myObject.publishObject({ save: false });
573
+ * // ... make other changes ...
574
+ * await myObject.save();
575
+ */
576
+ )
577
+ }, {
578
+ key: "publishObject",
579
+ value: (function () {
580
+ var _publishObject = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
581
+ var options,
582
+ _options$publish,
583
+ publish,
584
+ _options$save2,
585
+ save,
586
+ currentIac,
587
+ iac,
588
+ _args5 = arguments;
589
+ return _regenerator().w(function (_context5) {
590
+ while (1) switch (_context5.n) {
591
+ case 0:
592
+ options = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
593
+ _options$publish = options.publish, publish = _options$publish === void 0 ? true : _options$publish, _options$save2 = options.save, save = _options$save2 === void 0 ? true : _options$save2; // Get current IAC settings and create a deep clone to ensure change detection
594
+ currentIac = this.get('iac') || {};
595
+ iac = _.cloneDeep(currentIac); // Initialize readGrants if it doesn't exist
596
+ if (!iac.readGrants) {
597
+ iac.readGrants = {};
598
+ }
599
+
600
+ // Initialize users array if it doesn't exist
601
+ if (!Array.isArray(iac.readGrants.users)) {
602
+ iac.readGrants.users = [];
603
+ }
604
+ if (publish) {
605
+ // Add public_user if not already present
606
+ if (!iac.readGrants.users.includes('public_user')) {
607
+ iac.readGrants.users.push('public_user');
608
+ }
609
+ } else {
610
+ // Remove public_user
611
+ iac.readGrants.users = iac.readGrants.users.filter(function (userId) {
612
+ return userId !== 'public_user';
613
+ });
614
+ }
615
+
616
+ // Update the object with the cloned and modified IAC
617
+ this.set('iac', iac);
618
+
619
+ // Save if requested
620
+ if (!save) {
621
+ _context5.n = 2;
622
+ break;
623
+ }
624
+ _context5.n = 1;
625
+ return this.save();
626
+ case 1:
627
+ return _context5.a(2, _context5.v);
628
+ case 2:
629
+ return _context5.a(2, this);
630
+ }
631
+ }, _callee5, this);
632
+ }));
633
+ function publishObject() {
634
+ return _publishObject.apply(this, arguments);
635
+ }
636
+ return publishObject;
637
+ }()
638
+ /**
639
+ * Unpublishes this object to remove public access.
640
+ * Removes 'public_user' from the IAC read permissions.
641
+ * This is an alias for publishObject({ publish: false }) for better code clarity.
642
+ *
643
+ * @param {Object} options - Unpublishing options
644
+ * @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
645
+ * @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
646
+ *
647
+ * @example
648
+ * // Unpublish an object (remove public access)
649
+ * await myObject.unpublishObject();
650
+ *
651
+ * @example
652
+ * // Unpublish without auto-saving
653
+ * await myObject.unpublishObject({ save: false });
654
+ * // ... make other changes ...
655
+ * await myObject.save();
656
+ */
657
+ )
658
+ }, {
659
+ key: "unpublishObject",
660
+ value: (function () {
661
+ var _unpublishObject = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
662
+ var options,
663
+ _args6 = arguments;
664
+ return _regenerator().w(function (_context6) {
665
+ while (1) switch (_context6.n) {
666
+ case 0:
667
+ options = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {};
668
+ _context6.n = 1;
669
+ return this.publishObject({
670
+ publish: false,
671
+ save: options.save !== undefined ? options.save : true
672
+ });
673
+ case 1:
674
+ return _context6.a(2, _context6.v);
675
+ }
676
+ }, _callee6, this);
677
+ }));
678
+ function unpublishObject() {
679
+ return _unpublishObject.apply(this, arguments);
680
+ }
681
+ return unpublishObject;
682
+ }()
683
+ /**
684
+ * Revokes access from specific users and/or user groups.
685
+ *
686
+ * @param {Object} options - Access revocation options
687
+ * @param {string[]} [options.userIds=[]] - Array of user IDs to remove from read or write access
688
+ * @param {string[]} [options.groupIds=[]] - Array of group IDs to remove from read or write access
689
+ * @param {boolean} [options.write=false] - If true, removes write access; if false, removes read access
690
+ * @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
691
+ * @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
692
+ *
693
+ * @example
694
+ * // Revoke read access from specific users
695
+ * await myObject.revokeAccess({
696
+ * userIds: ['user_123', 'user_456']
697
+ * });
698
+ *
699
+ * @example
700
+ * // Revoke write access from specific groups
701
+ * await myObject.revokeAccess({
702
+ * groupIds: ['grpEditors'],
703
+ * write: true
704
+ * });
705
+ *
706
+ * @example
707
+ * // Revoke access from users and groups
708
+ * await myObject.revokeAccess({
709
+ * userIds: ['user_123'],
710
+ * groupIds: ['grpViewers']
711
+ * });
712
+ *
713
+ * @example
714
+ * // Revoke without auto-saving
715
+ * await myObject.revokeAccess({
716
+ * userIds: ['user_123'],
717
+ * save: false
718
+ * });
719
+ */
720
+ )
721
+ }, {
722
+ key: "revokeAccess",
723
+ value: (function () {
724
+ var _revokeAccess = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
725
+ var options,
726
+ _options$userIds2,
727
+ userIds,
728
+ _options$groupIds2,
729
+ groupIds,
730
+ _options$write2,
731
+ write,
732
+ _options$save3,
733
+ save,
734
+ iac,
735
+ grantType,
736
+ _args7 = arguments;
737
+ return _regenerator().w(function (_context7) {
738
+ while (1) switch (_context7.n) {
739
+ case 0:
740
+ options = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
741
+ _options$userIds2 = options.userIds, userIds = _options$userIds2 === void 0 ? [] : _options$userIds2, _options$groupIds2 = options.groupIds, groupIds = _options$groupIds2 === void 0 ? [] : _options$groupIds2, _options$write2 = options.write, write = _options$write2 === void 0 ? false : _options$write2, _options$save3 = options.save, save = _options$save3 === void 0 ? true : _options$save3; // Validate inputs
742
+ if (Array.isArray(userIds)) {
743
+ _context7.n = 1;
744
+ break;
745
+ }
746
+ throw new Error('userIds must be an array');
747
+ case 1:
748
+ if (Array.isArray(groupIds)) {
749
+ _context7.n = 2;
750
+ break;
751
+ }
752
+ throw new Error('groupIds must be an array');
753
+ case 2:
754
+ // Get current IAC settings
755
+ iac = this.get('iac') || {}; // Determine which grant type to update (read or write)
756
+ grantType = write ? 'writeGrants' : 'readGrants'; // Initialize grants if they don't exist
757
+ if (!iac[grantType]) {
758
+ iac[grantType] = {};
759
+ }
760
+
761
+ // Remove specified users
762
+ if (userIds.length > 0 && Array.isArray(iac[grantType].users)) {
763
+ iac[grantType].users = iac[grantType].users.filter(function (userId) {
764
+ return !userIds.includes(userId);
765
+ });
766
+ }
767
+
768
+ // Remove specified groups
769
+ if (groupIds.length > 0 && Array.isArray(iac[grantType].userGroups)) {
770
+ iac[grantType].userGroups = iac[grantType].userGroups.filter(function (groupId) {
771
+ return !groupIds.includes(groupId);
772
+ });
773
+ }
774
+
775
+ // Update the object
776
+ this.set('iac', iac);
777
+
778
+ // Save if requested
779
+ if (!save) {
780
+ _context7.n = 4;
781
+ break;
782
+ }
783
+ _context7.n = 3;
784
+ return this.save();
785
+ case 3:
786
+ return _context7.a(2, _context7.v);
787
+ case 4:
788
+ return _context7.a(2, this);
789
+ }
790
+ }, _callee7, this);
791
+ }));
792
+ function revokeAccess() {
793
+ return _revokeAccess.apply(this, arguments);
794
+ }
795
+ return revokeAccess;
796
+ }()
797
+ /**
798
+ * Checks if this object is currently published (publicly accessible).
799
+ *
800
+ * @returns {boolean} - True if 'public_user' is in the read grants, false otherwise
801
+ *
802
+ * @example
803
+ * if (myObject.isPublished()) {
804
+ * console.log('Object is public');
805
+ * }
806
+ */
807
+ )
808
+ }, {
809
+ key: "isPublished",
810
+ value: function isPublished() {
811
+ var iac = this.get('iac');
812
+ if (!iac || !iac.readGrants || !Array.isArray(iac.readGrants.users)) {
813
+ return false;
814
+ }
815
+ return iac.readGrants.users.includes('public_user');
816
+ }
817
+
818
+ /**
819
+ * Gets the current sharing permissions for this object.
820
+ *
821
+ * @returns {Object} - Object containing read and write grants
822
+ * @returns {Object} returns.readGrants - Read access grants
823
+ * @returns {string[]} returns.readGrants.users - Array of user IDs with read access
824
+ * @returns {string[]} returns.readGrants.userGroups - Array of group IDs with read access
825
+ * @returns {string[]} returns.readGrants.organizations - Array of organization IDs with read access
826
+ * @returns {Object} returns.writeGrants - Write access grants
827
+ * @returns {string[]} returns.writeGrants.users - Array of user IDs with write access
828
+ * @returns {string[]} returns.writeGrants.userGroups - Array of group IDs with write access
829
+ * @returns {string[]} returns.writeGrants.organizations - Array of organization IDs with write access
830
+ *
831
+ * @example
832
+ * const permissions = myObject.getSharing();
833
+ * console.log('Read users:', permissions.readGrants.users);
834
+ * console.log('Read groups:', permissions.readGrants.userGroups);
835
+ */
836
+ }, {
837
+ key: "getSharing",
838
+ value: function getSharing() {
839
+ var _iac$readGrants, _iac$readGrants2, _iac$readGrants3, _iac$readGrants4, _iac$writeGrants, _iac$writeGrants2, _iac$writeGrants3, _iac$writeGrants4;
840
+ var iac = this.get('iac') || {};
841
+ return {
842
+ readGrants: {
843
+ users: ((_iac$readGrants = iac.readGrants) === null || _iac$readGrants === void 0 ? void 0 : _iac$readGrants.users) || [],
844
+ userGroups: ((_iac$readGrants2 = iac.readGrants) === null || _iac$readGrants2 === void 0 ? void 0 : _iac$readGrants2.userGroups) || [],
845
+ organizations: ((_iac$readGrants3 = iac.readGrants) === null || _iac$readGrants3 === void 0 ? void 0 : _iac$readGrants3.organizations) || [],
846
+ userSegments: ((_iac$readGrants4 = iac.readGrants) === null || _iac$readGrants4 === void 0 ? void 0 : _iac$readGrants4.userSegments) || []
847
+ },
848
+ writeGrants: {
849
+ users: ((_iac$writeGrants = iac.writeGrants) === null || _iac$writeGrants === void 0 ? void 0 : _iac$writeGrants.users) || [],
850
+ userGroups: ((_iac$writeGrants2 = iac.writeGrants) === null || _iac$writeGrants2 === void 0 ? void 0 : _iac$writeGrants2.userGroups) || [],
851
+ organizations: ((_iac$writeGrants3 = iac.writeGrants) === null || _iac$writeGrants3 === void 0 ? void 0 : _iac$writeGrants3.organizations) || [],
852
+ userSegments: ((_iac$writeGrants4 = iac.writeGrants) === null || _iac$writeGrants4 === void 0 ? void 0 : _iac$writeGrants4.userSegments) || []
853
+ }
854
+ };
855
+ }
411
856
  }, {
412
857
  key: "delete",
413
858
  value: function () {
414
- var _delete2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
859
+ var _delete2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
415
860
  var record, response, _t2;
416
- return _regenerator().w(function (_context4) {
417
- while (1) switch (_context4.p = _context4.n) {
861
+ return _regenerator().w(function (_context8) {
862
+ while (1) switch (_context8.p = _context8.n) {
418
863
  case 0:
419
864
  if (this._internalData.type) {
420
- _context4.n = 1;
865
+ _context8.n = 1;
421
866
  break;
422
867
  }
423
868
  throw new Error('Cannot delete object without type');
424
869
  case 1:
425
- _context4.p = 1;
870
+ _context8.p = 1;
426
871
  record = this.toRecord();
427
- _context4.n = 2;
872
+ _context8.n = 2;
428
873
  return this._axios.post('/object_service/deleteObject', {
429
874
  id: record.id,
430
875
  type: record.type
431
876
  });
432
877
  case 2:
433
- response = _context4.v;
878
+ response = _context8.v;
434
879
  if (!(response.data.ok === false)) {
435
- _context4.n = 3;
880
+ _context8.n = 3;
436
881
  break;
437
882
  }
438
883
  throw new Error(response.data.message);
439
884
  case 3:
440
885
  this._internalData = response.data;
441
- return _context4.a(2, this);
886
+ return _context8.a(2, this);
442
887
  case 4:
443
- _context4.p = 4;
444
- _t2 = _context4.v;
888
+ _context8.p = 4;
889
+ _t2 = _context8.v;
445
890
  console.log('RbtObject.delete.error:');
446
891
  console.log(_t2.response.data);
447
892
  throw _t2;
448
893
  case 5:
449
- return _context4.a(2);
894
+ return _context8.a(2);
450
895
  }
451
- }, _callee4, this, [[1, 4]]);
896
+ }, _callee8, this, [[1, 4]]);
452
897
  }));
453
898
  function _delete() {
454
899
  return _delete2.apply(this, arguments);