oro-sdk-apis 5.16.0 → 6.0.0

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