oro-sdk-apis 5.17.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -650,6 +650,9 @@ var ApisPracticeManager = /*#__PURE__*/function () {
650
650
  this.getAuthTokenCbk = getAuthTokenCbk;
651
651
  this.useLocalStorage = useLocalStorage;
652
652
  this.practiceInstances = new Map();
653
+ // The refreshInstance will be a single instance that is used to refresh the tokens of others this way it will not interfere with requests made by other services
654
+ var newPracticeInstance = init(this.serviceCollReq, undefined, this.useLocalStorage);
655
+ this.practiceInstances.set('refreshInstance', newPracticeInstance);
653
656
  }
654
657
  /**
655
658
  * This function is used to get a `ServiceCollection` associated to a practice. If missing, it will initialize a new `ServiceCollection`.
@@ -660,64 +663,76 @@ var ApisPracticeManager = /*#__PURE__*/function () {
660
663
  _proto.get =
661
664
  /*#__PURE__*/
662
665
  function () {
663
- var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(practiceUuid) {
666
+ var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(practiceUuid) {
664
667
  var _this = this;
665
- var cacheKey, practiceInstance, newPracticeInstance, authTokenFunc;
666
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
667
- while (1) switch (_context2.prev = _context2.next) {
668
+ var cacheKey, practiceInstance, newPracticeInstance;
669
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
670
+ while (1) switch (_context.prev = _context.next) {
668
671
  case 0:
669
672
  cacheKey = practiceUuid != null ? practiceUuid : 'none';
670
673
  practiceInstance = this.practiceInstances.get(cacheKey);
671
674
  if (!practiceInstance) {
672
- _context2.next = 4;
675
+ _context.next = 4;
673
676
  break;
674
677
  }
675
- return _context2.abrupt("return", practiceInstance);
678
+ return _context.abrupt("return", practiceInstance);
676
679
  case 4:
677
- newPracticeInstance = init(this.serviceCollReq, undefined, this.useLocalStorage); // Create one auth token callback per practice since the practice uuid needs to change
678
- authTokenFunc = /*#__PURE__*/function () {
679
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
680
- return _regeneratorRuntime().wrap(function _callee$(_context) {
681
- while (1) switch (_context.prev = _context.next) {
682
- case 0:
683
- if (!newPracticeInstance.guardService) {
684
- _context.next = 7;
685
- break;
686
- }
687
- console.log("\x1B[36m[Auth] Refresh auth called (practiceUuid: " + practiceUuid + ")\x1B[36m");
688
- _context.next = 4;
689
- return _this.getAuthTokenCbk(newPracticeInstance.guardService, practiceUuid);
690
- case 4:
691
- return _context.abrupt("return", _context.sent);
692
- case 7:
693
- throw Error('[Auth] Unable to refresh token guard service is undefined');
694
- case 8:
695
- case "end":
696
- return _context.stop();
697
- }
698
- }, _callee);
699
- }));
700
- return function authTokenFunc() {
701
- return _ref.apply(this, arguments);
702
- };
703
- }(); // Initialize the M2M token
704
- _context2.next = 8;
705
- return authTokenFunc();
706
- case 8:
707
- // Set the refresh tokens callback
708
- newPracticeInstance.apiService.setAuthRefreshFn(authTokenFunc);
680
+ newPracticeInstance = init(this.serviceCollReq, undefined, this.useLocalStorage);
681
+ newPracticeInstance.apiService.setAuthRefreshFn(function () {
682
+ return _this.authTokenFunc(practiceUuid);
683
+ });
709
684
  this.practiceInstances.set(cacheKey, newPracticeInstance);
710
- return _context2.abrupt("return", newPracticeInstance);
711
- case 11:
685
+ return _context.abrupt("return", newPracticeInstance);
686
+ case 8:
712
687
  case "end":
713
- return _context2.stop();
688
+ return _context.stop();
714
689
  }
715
- }, _callee2, this);
690
+ }, _callee, this);
716
691
  }));
717
692
  function get(_x) {
718
693
  return _get.apply(this, arguments);
719
694
  }
720
695
  return get;
696
+ }()
697
+ /**
698
+ * Uses the refresh intance to fetch a new auth token for the given practice
699
+ * @param practiceUuid the uuid of the practice or key of a specific instance
700
+ * @returns a new authentication token
701
+ */
702
+ ;
703
+ _proto.authTokenFunc =
704
+ /*#__PURE__*/
705
+ function () {
706
+ var _authTokenFunc = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(practiceUuidOrInstanceName) {
707
+ var newPracticeInstance;
708
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
709
+ while (1) switch (_context2.prev = _context2.next) {
710
+ case 0:
711
+ _context2.next = 2;
712
+ return this.get('refreshInstance');
713
+ case 2:
714
+ newPracticeInstance = _context2.sent;
715
+ if (!newPracticeInstance.guardService) {
716
+ _context2.next = 10;
717
+ break;
718
+ }
719
+ console.log("\x1B[36m[Auth] Refresh auth called (practiceUuid: " + practiceUuidOrInstanceName + ")\x1B[36m");
720
+ _context2.next = 7;
721
+ return this.getAuthTokenCbk(newPracticeInstance.guardService, practiceUuidOrInstanceName);
722
+ case 7:
723
+ return _context2.abrupt("return", _context2.sent);
724
+ case 10:
725
+ throw Error('[Auth] Unable to refresh token guard service is undefined');
726
+ case 11:
727
+ case "end":
728
+ return _context2.stop();
729
+ }
730
+ }, _callee2, this);
731
+ }));
732
+ function authTokenFunc(_x2) {
733
+ return _authTokenFunc.apply(this, arguments);
734
+ }
735
+ return authTokenFunc;
721
736
  }();
722
737
  return ApisPracticeManager;
723
738
  }();