roboto-js 1.7.5 → 1.8.1

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