@sambath999/localize-token 12.3.1 → 12.3.3

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('jwt-decode'), require('@angular/common/http'), require('primeng/api'), require('primeng/dynamicdialog'), require('@angular/common'), require('primeng/toast'), require('primeng/inputtext'), require('primeng/button'), require('@angular/platform-browser'), require('@angular/forms')) :
3
- typeof define === 'function' && define.amd ? define('@sambath999/localize-token', ['exports', '@angular/core', 'rxjs', 'jwt-decode', '@angular/common/http', 'primeng/api', 'primeng/dynamicdialog', '@angular/common', 'primeng/toast', 'primeng/inputtext', 'primeng/button', '@angular/platform-browser', '@angular/forms'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.sambath999 = global.sambath999 || {}, global.sambath999["localize-token"] = {}), global.ng.core, global.rxjs, global.jwt_decode, global.ng.common.http, global.api, global.dynamicdialog, global.ng.common, global.toast, global.inputtext, global.button, global.ng.platformBrowser, global.ng.forms));
5
- })(this, (function (exports, i0, rxjs, jwt_decode, i1, api, dynamicdialog, common, toast, inputtext, button, platformBrowser, forms) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('jwt-decode'), require('@angular/common/http'), require('primeng/api'), require('primeng/dynamicdialog'), require('@angular/platform-browser'), require('@angular/common'), require('primeng/toast'), require('primeng/inputtext'), require('primeng/button'), require('@angular/forms')) :
3
+ typeof define === 'function' && define.amd ? define('@sambath999/localize-token', ['exports', '@angular/core', 'rxjs', 'jwt-decode', '@angular/common/http', 'primeng/api', 'primeng/dynamicdialog', '@angular/platform-browser', '@angular/common', 'primeng/toast', 'primeng/inputtext', 'primeng/button', '@angular/forms'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.sambath999 = global.sambath999 || {}, global.sambath999["localize-token"] = {}), global.ng.core, global.rxjs, global.jwt_decode, global.ng.common.http, global.api, global.dynamicdialog, global.ng.platformBrowser, global.ng.common, global.toast, global.inputtext, global.button, global.ng.forms));
5
+ })(this, (function (exports, i0, rxjs, jwt_decode, i1, api, dynamicdialog, platformBrowser, common, toast, inputtext, button, forms) { 'use strict';
6
6
 
7
7
  function _interopNamespace(e) {
8
8
  if (e && e.__esModule) return e;
@@ -620,6 +620,8 @@
620
620
  configurable: true
621
621
  });
622
622
  LocalizeTokenService.prototype.tenantToken = function (name) {
623
+ if (!name)
624
+ return undefined;
623
625
  return LocalizeToken.storage.get(name);
624
626
  };
625
627
  LocalizeTokenService.prototype.storageGet = function () {
@@ -636,6 +638,11 @@
636
638
  var base64 = btoa(JSON.stringify(value));
637
639
  LocalizeToken.storage.set(this.config.authTokenName, base64);
638
640
  };
641
+ LocalizeTokenService.prototype.tokensValid = function (tenantTokenName) {
642
+ var _a, _b;
643
+ return !!((_a = this.refreshToken) === null || _a === void 0 ? void 0 : _a.length)
644
+ && (!this.config.needTenant || !!((_b = this.tenantToken(tenantTokenName)) === null || _b === void 0 ? void 0 : _b.length));
645
+ };
639
646
  Object.defineProperty(LocalizeTokenService.prototype, "decodeRefreshToken", {
640
647
  get: function () {
641
648
  var token = LocalizeToken.storage.get(this.config.refreshTokenName);
@@ -659,40 +666,289 @@
659
666
  */
660
667
  exports.EMethod = void 0;
661
668
  (function (EMethod) {
662
- EMethod[EMethod["POST"] = 1] = "POST";
663
- EMethod[EMethod["GET"] = 2] = "GET";
664
- EMethod[EMethod["PUT"] = 3] = "PUT";
665
- EMethod[EMethod["DELETE"] = 4] = "DELETE";
666
- EMethod[EMethod["PATCH"] = 5] = "PATCH";
667
- })(exports.EMethod || (exports.EMethod = {}));
669
+ EMethod["POST"] = "post";
670
+ EMethod["GET"] = "get";
671
+ EMethod["PUT"] = "put";
672
+ EMethod["DELETE"] = "delete";
673
+ EMethod["PATCH"] = "patch";
674
+ })(exports.EMethod || (exports.EMethod = {}));
675
+
676
+ var LocalizeApiHelper = /** @class */ (function () {
677
+ function LocalizeApiHelper() {
678
+ this.defaultRetryOptions = {
679
+ connectionError: {
680
+ message: 'Connection error occurred. Please wait',
681
+ blockScreen: true,
682
+ blockScreenZIndex: 10000
683
+ }
684
+ };
685
+ }
686
+ LocalizeApiHelper.prototype.performRetry = function (options) {
687
+ return __awaiter(this, void 0, void 0, function () {
688
+ var attempts, lastError, consoleCount, styleElement, result, error_1;
689
+ return __generator(this, function (_e) {
690
+ switch (_e.label) {
691
+ case 0:
692
+ attempts = 0;
693
+ consoleCount = 0;
694
+ // Merge default retry options with provided options
695
+ options = Object.assign(Object.assign({}, this.defaultRetryOptions), options);
696
+ _e.label = 1;
697
+ case 1:
698
+ if (!(attempts < options.maxRetries())) return [3 /*break*/, 10];
699
+ _e.label = 2;
700
+ case 2:
701
+ _e.trys.push([2, 4, , 9]);
702
+ return [4 /*yield*/, options.callback()];
703
+ case 3:
704
+ result = _e.sent();
705
+ this.removeBlocker(styleElement);
706
+ return [2 /*return*/, result];
707
+ case 4:
708
+ error_1 = _e.sent();
709
+ lastError = error_1;
710
+ if (consoleCount >= 7) {
711
+ console.clear();
712
+ consoleCount = 0;
713
+ }
714
+ if (options.retryUnless && !options.retryUnless(error_1))
715
+ throw error_1; // If the error should not be retried, rethrow it
716
+ return [4 /*yield*/, this.onConnectionError(options, error_1)];
717
+ case 5:
718
+ // Handle connection error
719
+ styleElement = _e.sent();
720
+ if (!options.onError) return [3 /*break*/, 7];
721
+ return [4 /*yield*/, this.invokeHook(options.onError.bind(this, error_1))];
722
+ case 6:
723
+ _e.sent();
724
+ _e.label = 7;
725
+ case 7:
726
+ if (attempts >= options.maxRetries() - 1)
727
+ throw error_1;
728
+ attempts++;
729
+ consoleCount++;
730
+ console.warn("Attempt " + attempts + " failed. Retrying...", error_1);
731
+ return [4 /*yield*/, waitFor(options.delay)];
732
+ case 8:
733
+ _e.sent();
734
+ return [3 /*break*/, 9];
735
+ case 9: return [3 /*break*/, 1];
736
+ case 10:
737
+ console.warn("Failed after " + options.maxRetries + " attempts");
738
+ throw lastError;
739
+ }
740
+ });
741
+ });
742
+ };
743
+ LocalizeApiHelper.prototype.performRequestWithRetry = function (options, config, performRequest) {
744
+ var _a, _b, _c, _d;
745
+ return __awaiter(this, void 0, void 0, function () {
746
+ var retryUnless;
747
+ return __generator(this, function (_e) {
748
+ switch (_e.label) {
749
+ case 0:
750
+ retryUnless = ((_a = config.retryOptions) === null || _a === void 0 ? void 0 : _a.retryFunction)
751
+ || this.isConnectionError;
752
+ return [4 /*yield*/, this.performRetry({
753
+ connectionError: (_b = config.retryOptions) === null || _b === void 0 ? void 0 : _b.onConnectionError,
754
+ maxRetries: function () { var _a, _b; return (_b = (_a = config.retryOptions) === null || _a === void 0 ? void 0 : _a.maxRetries) !== null && _b !== void 0 ? _b : 1000; },
755
+ delay: (_d = (_c = config.retryOptions) === null || _c === void 0 ? void 0 : _c.delay) !== null && _d !== void 0 ? _d : 500,
756
+ callback: function () { return performRequest(options); },
757
+ retryUnless: retryUnless,
758
+ })];
759
+ case 1: return [2 /*return*/, _e.sent()];
760
+ }
761
+ });
762
+ });
763
+ };
764
+ LocalizeApiHelper.prototype.buildUrl = function (baseUrl, path) {
765
+ var normalizedUrl = "" + baseUrl.trim().replace(/\/?$/, '/') + path.trim().replace(/^\//, '');
766
+ return normalizedUrl.endsWith('/')
767
+ ? normalizedUrl.slice(0, -1)
768
+ : normalizedUrl;
769
+ };
770
+ LocalizeApiHelper.prototype.normalizeError = function (error) {
771
+ var _a, _b, _c;
772
+ return {
773
+ code: ((_a = error.error) === null || _a === void 0 ? void 0 : _a.code) || "HTTP_" + error.status,
774
+ message: ((_b = error.error) === null || _b === void 0 ? void 0 : _b.message) || error.message,
775
+ details: (_c = error.error) === null || _c === void 0 ? void 0 : _c.details,
776
+ status: error.status
777
+ };
778
+ };
779
+ LocalizeApiHelper.prototype.invokeHook = function (callback) {
780
+ return __awaiter(this, void 0, void 0, function () {
781
+ var result;
782
+ return __generator(this, function (_e) {
783
+ switch (_e.label) {
784
+ case 0:
785
+ if (!callback)
786
+ return [2 /*return*/];
787
+ result = callback();
788
+ if (!(result instanceof Promise)) return [3 /*break*/, 2];
789
+ return [4 /*yield*/, result];
790
+ case 1:
791
+ _e.sent();
792
+ _e.label = 2;
793
+ case 2: return [2 /*return*/];
794
+ }
795
+ });
796
+ });
797
+ };
798
+ LocalizeApiHelper.prototype.createRequest = function (instance, method, url, body, options) {
799
+ var _this = this;
800
+ var request$ = instance.client.request(method, url, Object.assign(Object.assign({}, options), { body: body, observe: 'response' })).pipe(rxjs.takeUntil(instance.destroy$()), rxjs.catchError(function (error) {
801
+ // Convert to a non-observable error to handle in the promise
802
+ return rxjs.throwError(function () { return _this.normalizeError(error); });
803
+ }));
804
+ return request$;
805
+ };
806
+ LocalizeApiHelper.prototype.defaultRetryFunction = function (error) {
807
+ // Don't retry for other errors (like 400, 401, 403, etc.)
808
+ if (!this.isConnectionError(error))
809
+ throw error;
810
+ return true;
811
+ };
812
+ LocalizeApiHelper.prototype.isConnectionError = function (error) {
813
+ var isNetworkError = error.status === 0;
814
+ var isServerError = error.status >= 1000 && error.status < 600;
815
+ return isNetworkError || isServerError;
816
+ };
817
+ LocalizeApiHelper.prototype.onConnectionError = function (options, error) {
818
+ var _a;
819
+ return __awaiter(this, void 0, void 0, function () {
820
+ var styleElement;
821
+ return __generator(this, function (_e) {
822
+ switch (_e.label) {
823
+ case 0:
824
+ if (!options.connectionError)
825
+ return [2 /*return*/];
826
+ if (!this.isConnectionError(error)) return [3 /*break*/, 2];
827
+ styleElement = this.screenBlocker(options, error, true);
828
+ return [4 /*yield*/, this.invokeHook((_a = options.connectionError.callback) === null || _a === void 0 ? void 0 : _a.bind(this, error))];
829
+ case 1:
830
+ _e.sent();
831
+ return [2 /*return*/, styleElement];
832
+ case 2:
833
+ this.screenBlocker(options, error, false);
834
+ styleElement === null || styleElement === void 0 ? void 0 : styleElement.remove();
835
+ _e.label = 3;
836
+ case 3: return [2 /*return*/];
837
+ }
838
+ });
839
+ });
840
+ };
841
+ LocalizeApiHelper.prototype.validateConfig = function (config) {
842
+ var _a;
843
+ if (LocalizeToken.config.needTenant && !((_a = config.tenantTokenName) === null || _a === void 0 ? void 0 : _a.trim().length)) {
844
+ throw Error('Tenant token is required but tenantTokenName is not configured');
845
+ }
846
+ if (!LocalizeToken.config.revokeTokenUrl.trim().length) {
847
+ throw Error('Revoke token URL is not configured - token refresh will not work');
848
+ }
849
+ };
850
+ LocalizeApiHelper.prototype.screenBlocker = function (optons, error, add) {
851
+ if (add === void 0) { add = true; }
852
+ var _a, _b, _c, _d;
853
+ if (!((_a = optons.connectionError) === null || _a === void 0 ? void 0 : _a.blockScreen))
854
+ return;
855
+ if (error instanceof i1.HttpErrorResponse)
856
+ error = this.normalizeError(error);
857
+ var message = ((_b = optons.connectionError) === null || _b === void 0 ? void 0 : _b.message)
858
+ || 'Connection error occurred. Please wait';
859
+ var errorMessage = (error === null || error === void 0 ? void 0 : error.message) || 'An error occurred';
860
+ var suggestinMessage = ((_c = optons.connectionError) === null || _c === void 0 ? void 0 : _c.suggestionMessage)
861
+ || 'Please check your internet connection or the server status.';
862
+ var zIndex = ((_d = optons.connectionError) === null || _d === void 0 ? void 0 : _d.blockScreenZIndex) || 10000;
863
+ var body = document.body;
864
+ var blcokerHtml = "\n <div class=\"lze-blocker\">\n <div class=\"lze-blocker__message\">\n " + message + "\n <span class=\"lze-blocker__dotting\">\n <span class=\"lze-blocker__dot\"></span>\n <span class=\"lze-blocker__dot\"></span>\n <span class=\"lze-blocker__dot\"></span>\n </span>\n </div>\n <div class=\"lze-blocker__error\">" + errorMessage + "</div>\n <div class=\"lze-blocker__error_suggestion\">" + suggestinMessage + "</div>\n <div class=\"lze-blocker__spinner\"></div>\n </div>\n ";
865
+ var style = "\n .lze-blocker {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.8);\n z-index: " + zIndex + ";\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: column;\n color: #fff;\n font-family: Arial, sans-serif;\n text-align: center;\n padding: 20px;\n box-sizing: border-box;\n overflow: hidden;\n user-select: none;\n }\n \n .lze-blocker__spinner {\n border: 4px solid rgba(255, 255, 255, 0.1);\n border-top: 4px solid #fff;\n border-radius: 50%;\n width: 50px;\n height: 50px;\n animation: spin 1s linear infinite;\n margin-top: 20px;\n }\n\n .lze-blocker__message {\n color: #fff;\n font-size: 18px;\n margin-bottom: 10px;\n }\n \n .lze-blocker__dotting {\n display: inline-block;\n vertical-align: middle;\n }\n .lze-blocker__dot {\n display: inline-block;\n width: 7px;\n height: 7px;\n background-color: #ffffff;\n border-radius: 50%;\n margin-left: 3px;\n opacity: 0.3;\n animation: dotting 1s infinite;\n }\n .lze-blocker__dot:nth-child(1) {\n animation-delay: 0s;\n opacity: 1;\n }\n .lze-blocker__dot:nth-child(2) {\n animation-delay: 0.2s;\n }\n .lze-blocker__dot:nth-child(3) {\n animation-delay: 0.4s;\n }\n\n @keyframes dotting {\n 0%, 80%, 100% { opacity: 0.3; }\n 40% { opacity: 1; }\n }\n\n .lze-blocker__error {\n color: #f00;\n font-size: 14px;\n margin-bottom: 10px;\n text-shadow: 0 0 1px #ff5f5f;\n }\n\n .lze-blocker__error_suggestion {\n color: #ccc;\n font-size: 14px;\n margin-top: 10px;\n }\n \n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n ";
866
+ var styleElement = document.createElement('style');
867
+ if (add) {
868
+ if (!document.querySelector('.lze-blocker')) {
869
+ styleElement.innerHTML = style;
870
+ document.head.appendChild(styleElement);
871
+ body.insertAdjacentHTML('beforeend', blcokerHtml);
872
+ }
873
+ }
874
+ else {
875
+ this.removeBlocker(styleElement);
876
+ }
877
+ return styleElement;
878
+ };
879
+ LocalizeApiHelper.prototype.removeBlocker = function (styleElement) {
880
+ var blocker = document.querySelector('.lze-blocker');
881
+ blocker === null || blocker === void 0 ? void 0 : blocker.remove();
882
+ styleElement === null || styleElement === void 0 ? void 0 : styleElement.remove();
883
+ };
884
+ return LocalizeApiHelper;
885
+ }());
886
+ var ApiHelper = new LocalizeApiHelper();
887
+
888
+ var SCHEMES = LocalizeToken.httpHeaders;
668
889
  var LocalizeApiService = /** @class */ (function () {
669
890
  function LocalizeApiService(httpClient, localizeTokenService) {
670
891
  var _this = this;
671
892
  this.httpClient = httpClient;
672
893
  this.localizeTokenService = localizeTokenService;
894
+ this.destroy$ = new rxjs.Subject();
673
895
  this.isRequestingSubject = new rxjs.BehaviorSubject(false);
674
896
  this.isResolvedStartupSubject = new rxjs.BehaviorSubject(false);
675
- this.apiConfigs = {};
897
+ this.needTenant = LocalizeToken.config.needTenant;
898
+ this.config = {
899
+ waitEachRequest: { milliseconds: 0 },
900
+ enableRequestCancellation: true,
901
+ retryOptions: {
902
+ maxRetries: 1000,
903
+ delay: 1000,
904
+ retryFunction: ApiHelper.defaultRetryFunction.bind(this),
905
+ },
906
+ };
907
+ this.apiOptions = {
908
+ method: exports.EMethod.GET,
909
+ requestBody: null,
910
+ };
676
911
  /**
677
912
  * A higher-order function that returns a curried function for making API requests.
678
913
  *
679
914
  * @param baseUrl - The base URL of the API.
680
915
  * @returns A curried function that can be used to make API requests.
681
916
  */
682
- this.func = function (baseUrl) { return function (path, method, value, isFormData, headers) {
917
+ this.func = function (baseUrl) { return function (path, method, reqBody, reqHeaders) {
683
918
  if (method === void 0) { method = exports.EMethod.GET; }
684
- if (value === void 0) { value = null; }
685
- if (isFormData === void 0) { isFormData = false; }
686
- return _this.base(baseUrl, path, method, value, isFormData, headers);
919
+ if (reqBody === void 0) { reqBody = null; }
920
+ return _this.request(baseUrl, path, method, reqBody, reqHeaders);
687
921
  }; };
688
922
  }
923
+ Object.defineProperty(LocalizeApiService.prototype, "isResolvedStartup", {
924
+ get: function () { return this.isResolvedStartupSubject.value; },
925
+ enumerable: false,
926
+ configurable: true
927
+ });
689
928
  Object.defineProperty(LocalizeApiService.prototype, "isRequesting", {
690
929
  get: function () { return this.isRequestingSubject.value; },
691
930
  enumerable: false,
692
931
  configurable: true
693
932
  });
694
- Object.defineProperty(LocalizeApiService.prototype, "isResolvedStartup", {
695
- get: function () { return this.isResolvedStartupSubject.value; },
933
+ Object.defineProperty(LocalizeApiService.prototype, "isRevokingToken", {
934
+ get: function () { return this.localizeTokenService.isRevokingToken; },
935
+ set: function (value) { this.localizeTokenService.isRevokingToken = value; },
936
+ enumerable: false,
937
+ configurable: true
938
+ });
939
+ Object.defineProperty(LocalizeApiService.prototype, "accessToken", {
940
+ get: function () { return this.localizeTokenService.accessToken; },
941
+ set: function (value) { this.localizeTokenService.accessToken = value; },
942
+ enumerable: false,
943
+ configurable: true
944
+ });
945
+ Object.defineProperty(LocalizeApiService.prototype, "refreshToken", {
946
+ get: function () { return this.localizeTokenService.refreshToken; },
947
+ enumerable: false,
948
+ configurable: true
949
+ });
950
+ Object.defineProperty(LocalizeApiService.prototype, "tenantToken", {
951
+ get: function () { return this.localizeTokenService.tenantToken(this.config.tenantTokenName); },
696
952
  enumerable: false,
697
953
  configurable: true
698
954
  });
@@ -701,187 +957,235 @@
701
957
  * @param apiConfigs - The API configurations.
702
958
  */
703
959
  LocalizeApiService.prototype.init = function (apiConfigs) {
704
- this.apiConfigs = apiConfigs;
960
+ this.config = Object.assign(Object.assign({}, this.config), apiConfigs);
961
+ ApiHelper.validateConfig(this.config);
962
+ };
963
+ LocalizeApiService.prototype.cancelPendingRequests = function () {
964
+ this.config.enableRequestCancellation
965
+ && this.destroy$.next();
966
+ };
967
+ LocalizeApiService.prototype.ngOnDestroy = function () {
968
+ this.destroy$.next();
969
+ this.destroy$.complete();
705
970
  };
706
- LocalizeApiService.prototype.base = function (baseUrl, path, method, value, isFormData, headers) {
971
+ LocalizeApiService.prototype.request = function (baseUrl, path, method, reqBody, reqHeaders) {
707
972
  if (method === void 0) { method = exports.EMethod.GET; }
708
- if (value === void 0) { value = null; }
709
- if (isFormData === void 0) { isFormData = false; }
973
+ if (reqBody === void 0) { reqBody = null; }
710
974
  return __awaiter(this, void 0, void 0, function () {
711
- var url, httpMethod, request, error_1;
712
- var _this = this;
975
+ var apiOptions, error_1;
713
976
  return __generator(this, function (_b) {
714
977
  switch (_b.label) {
715
- case 0: return [4 /*yield*/, this.ifPromise(this.apiConfigs.onPrepareRequest)];
978
+ case 0: return [4 /*yield*/, ApiHelper.invokeHook(this.config.onPrepareRequest)];
716
979
  case 1:
717
980
  _b.sent();
718
- url = "" + baseUrl.trim().replace(/\/?$/, '/') + path.trim().replace(/^\//, '');
719
- httpMethod = exports.EMethod[method].toLowerCase();
720
- request = function () { return { body: value, headers: _this.options(isFormData, headers) }; };
721
- // Wait for previous request to complete
722
- return [4 /*yield*/, this.toWaitForPreviousRequest()];
981
+ apiOptions = this.buildApiOptions(baseUrl, path, method, reqBody, reqHeaders);
982
+ _b.label = 2;
723
983
  case 2:
724
- // Wait for previous request to complete
725
- _b.sent();
726
- _b.label = 3;
984
+ _b.trys.push([2, 5, , 7]);
985
+ return [4 /*yield*/, this.toWaitForPreviousRequest()];
727
986
  case 3:
728
- _b.trys.push([3, 5, , 7]);
729
- return [4 /*yield*/, this.processRequest(httpMethod, url, request())];
987
+ _b.sent();
988
+ return [4 /*yield*/, ApiHelper.performRequestWithRetry(apiOptions, this.config, this.performRequest.bind(this))];
730
989
  case 4: return [2 /*return*/, _b.sent()];
731
990
  case 5:
732
991
  error_1 = _b.sent();
733
- if (error_1.status !== 401) {
734
- throw error_1;
735
- }
736
- return [4 /*yield*/, this.onUnauthorizedError(httpMethod, url, request)];
992
+ return [4 /*yield*/, this.handleOnRequestError(error_1, apiOptions)];
737
993
  case 6: return [2 /*return*/, _b.sent()];
738
994
  case 7: return [2 /*return*/];
739
995
  }
740
996
  });
741
997
  });
742
998
  };
743
- LocalizeApiService.prototype.onUnauthorizedError = function (httpMethod, url, request) {
744
- return __awaiter(this, void 0, void 0, function () {
745
- return __generator(this, function (_b) {
746
- switch (_b.label) {
747
- case 0: return [4 /*yield*/, this.revokeToken()];
748
- case 1:
749
- _b.sent();
750
- if (!!this.isResolvedStartup) return [3 /*break*/, 3];
751
- return [4 /*yield*/, this.processRequest(httpMethod, url, request())];
752
- case 2: return [2 /*return*/, _b.sent()];
753
- case 3: return [2 /*return*/];
754
- }
755
- });
756
- });
757
- };
758
- LocalizeApiService.prototype.toWaitForPreviousRequest = function () {
759
- var _a;
999
+ LocalizeApiService.prototype.handleOnRequestError = function (error, options) {
760
1000
  return __awaiter(this, void 0, void 0, function () {
761
1001
  var _this = this;
762
1002
  return __generator(this, function (_b) {
763
1003
  switch (_b.label) {
764
1004
  case 0:
765
- if (!this.localizeTokenService.isRevokingToken) return [3 /*break*/, 2];
766
- return [4 /*yield*/, waitUntil(function () { return !_this.localizeTokenService.isRevokingToken; })];
767
- case 1:
768
- _b.sent();
769
- _b.label = 2;
770
- case 2:
771
- if (!((_a = this.apiConfigs.waitEachRequest) === null || _a === void 0 ? void 0 : _a.milliseconds)) return [3 /*break*/, 4];
772
- return [4 /*yield*/, waitFor(this.apiConfigs.waitEachRequest.milliseconds, this.isRequesting)];
773
- case 3:
774
- _b.sent();
775
- _b.label = 4;
776
- case 4: return [2 /*return*/];
1005
+ if (error.status !== 401 || this.isResolvedStartup)
1006
+ throw error;
1007
+ return [4 /*yield*/, ApiHelper.performRetry({
1008
+ maxRetries: function () { return 1000; },
1009
+ delay: 500,
1010
+ retryUnless: function (error) { return error.status === 401 || ApiHelper.isConnectionError(error); },
1011
+ callback: function () { return __awaiter(_this, void 0, void 0, function () {
1012
+ return __generator(this, function (_b) {
1013
+ switch (_b.label) {
1014
+ case 0:
1015
+ // Only handle 401 Unauthorized errors
1016
+ return [4 /*yield*/, this.revokeToken()];
1017
+ case 1:
1018
+ // Only handle 401 Unauthorized errors
1019
+ _b.sent();
1020
+ return [4 /*yield*/, this.performRequest(options)];
1021
+ case 2:
1022
+ // Retry the request with the new access token
1023
+ return [2 /*return*/, _b.sent()];
1024
+ }
1025
+ });
1026
+ }); }
1027
+ })];
1028
+ case 1: return [2 /*return*/, _b.sent()];
777
1029
  }
778
1030
  });
779
1031
  });
780
1032
  };
781
- LocalizeApiService.prototype.processRequest = function (method, url, options) {
1033
+ LocalizeApiService.prototype.performRequest = function (options) {
782
1034
  return __awaiter(this, void 0, void 0, function () {
783
- var result;
1035
+ var buildOptions, request$, response;
784
1036
  var _this = this;
785
1037
  return __generator(this, function (_b) {
786
1038
  switch (_b.label) {
787
1039
  case 0:
1040
+ buildOptions = { headers: this.buildHeaderOptions(options) };
1041
+ request$ = ApiHelper.createRequest({
1042
+ client: this.httpClient,
1043
+ destroy$: function () { return _this.destroy$; }
1044
+ }, options.method, options.requestUrl, options.requestBody, buildOptions);
1045
+ // Set the isRequesting state to true before making the request
788
1046
  this.isRequestingSubject.next(true);
789
- return [4 /*yield*/, new Promise(function (resolve, reject) { return _this.httpClient.request(method, url, options).subscribe({ next: resolve, error: reject }); })];
1047
+ return [4 /*yield*/, new Promise(function (resolve, reject) { return request$.subscribe({ next: function (res) { return resolve(res.body); }, error: reject }); })];
790
1048
  case 1:
791
- result = _b.sent();
1049
+ response = _b.sent();
1050
+ // Reset the isRequesting state after the request completes
792
1051
  this.isRequestingSubject.next(false);
793
- return [2 /*return*/, result];
1052
+ return [2 /*return*/, response];
794
1053
  }
795
1054
  });
796
1055
  });
797
1056
  };
798
1057
  LocalizeApiService.prototype.revokeToken = function () {
799
1058
  return __awaiter(this, void 0, void 0, function () {
800
- var reqUrl_1, reqHeaders_1, revokeToken;
801
- var _this = this;
1059
+ var apiOptions, revokeToken, error_2;
802
1060
  return __generator(this, function (_b) {
803
1061
  switch (_b.label) {
804
1062
  case 0:
805
- if (!this.localizeTokenService.isRevokingToken) return [3 /*break*/, 2];
806
- return [4 /*yield*/, waitUntil(function () { return !_this.localizeTokenService.isRevokingToken; })];
1063
+ _b.trys.push([0, 4, 6, 7]);
1064
+ return [4 /*yield*/, this.interceptRevokeToken()];
807
1065
  case 1:
808
- _b.sent();
809
- return [2 /*return*/];
1066
+ if (_b.sent())
1067
+ return [2 /*return*/];
1068
+ this.isRevokingToken = true;
1069
+ apiOptions = Object.assign(Object.assign({}, this.buildApiOptions(LocalizeToken.config.revokeTokenUrl)), { refreshToken: true });
1070
+ return [4 /*yield*/, ApiHelper.performRequestWithRetry(apiOptions, this.config, this.performRequest.bind(this))];
810
1071
  case 2:
811
- _b.trys.push([2, , 9, 10]);
812
- this.localizeTokenService.isRevokingToken = true;
813
- reqUrl_1 = LocalizeToken.config.revokeTokenUrl;
814
- reqHeaders_1 = this.options().append(LocalizeToken.httpHeaders.X_REFRESH_TOKEN, "" + this.localizeTokenService.refreshToken);
815
- return [4 /*yield*/, new Promise(function (resolve, reject) { return _this.httpClient.get(reqUrl_1, { headers: reqHeaders_1 }).subscribe({ next: resolve, error: reject }); })];
816
- case 3:
817
1072
  revokeToken = _b.sent();
818
- if (!(revokeToken === null || revokeToken === void 0 ? void 0 : revokeToken.status)) return [3 /*break*/, 4];
819
- this.localizeTokenService.accessToken = revokeToken.message;
820
- return [3 /*break*/, 8];
1073
+ return [4 /*yield*/, this.handleOnTokenRevoked(revokeToken)];
1074
+ case 3:
1075
+ _b.sent();
1076
+ return [3 /*break*/, 7];
821
1077
  case 4:
822
- if (!!this.localizeTokenService.refreshToken) return [3 /*break*/, 6];
823
- return [4 /*yield*/, this.ifPromise(this.apiConfigs.onAutoLogout)];
1078
+ error_2 = _b.sent();
1079
+ // Handle the error, log it
1080
+ return [4 /*yield*/, ApiHelper.invokeHook(this.config.onAutoLogout)];
824
1081
  case 5:
1082
+ // Handle the error, log it
825
1083
  _b.sent();
826
- return [3 /*break*/, 8];
1084
+ return [3 /*break*/, 7];
827
1085
  case 6:
828
- if (!this.apiConfigs.onRevokeUnauthorized) return [3 /*break*/, 8];
829
- return [4 /*yield*/, this.ifPromise(this.apiConfigs.onRevokeUnauthorized)];
830
- case 7:
831
- _b.sent();
832
- _b.label = 8;
833
- case 8: return [3 /*break*/, 10];
834
- case 9:
835
- this.localizeTokenService.isRevokingToken = false;
1086
+ // Reset the revoking token state
1087
+ this.isRevokingToken = false;
836
1088
  return [7 /*endfinally*/];
837
- case 10: return [2 /*return*/];
1089
+ case 7: return [2 /*return*/];
838
1090
  }
839
1091
  });
840
1092
  });
841
1093
  };
842
1094
  /** default http request options */
843
- LocalizeApiService.prototype.options = function (isFormData, headers) {
844
- var _b;
845
- if (isFormData === void 0) { isFormData = false; }
846
- if (headers === void 0) { headers = {}; }
847
- var defaultHeaders = (_b = {}, _b[LocalizeToken.httpHeaders.AUTHORIZATION] = "Bearer " + this.localizeTokenService.accessToken, _b);
848
- if (LocalizeToken.config.needTenant) {
849
- defaultHeaders[LocalizeToken.httpHeaders.X_TENANT] = "" + this.localizeTokenService.tenantToken(this.apiConfigs.tenantTokenName);
850
- }
851
- if (!isFormData) {
852
- defaultHeaders[LocalizeToken.httpHeaders.CONTENT_TYPE] = 'application/json';
1095
+ LocalizeApiService.prototype.buildHeaderOptions = function (options) {
1096
+ var _b, _c, _d, _e;
1097
+ var headers = Object.assign(Object.assign({}, (options.refreshToken && (_b = {}, _b[SCHEMES.X_REFRESH_TOKEN] = "" + this.refreshToken, _b))), (!options.isFormData && (_c = {}, _c[SCHEMES.CONTENT_TYPE] = 'application/json', _c)));
1098
+ if (!options.refreshToken) {
1099
+ headers = Object.assign(Object.assign(Object.assign({}, headers), (_d = {}, _d[SCHEMES.AUTHORIZATION] = "Bearer " + this.accessToken, _d)), (this.needTenant && (_e = {}, _e[SCHEMES.X_TENANT] = "" + this.tenantToken, _e)));
853
1100
  }
854
- var filteredHeaders = Object.keys(defaultHeaders).filter(function (key) { return !Object.keys(headers).includes(key); })
855
- .reduce(function (acc, key) {
856
- var _b;
857
- return (Object.assign(Object.assign({}, acc), (_b = {}, _b[key] = defaultHeaders[key], _b)));
858
- }, {});
859
- var mergedHeaders = Object.assign(Object.assign({}, filteredHeaders), headers);
860
- return new i1.HttpHeaders(mergedHeaders);
1101
+ return new i1.HttpHeaders(Object.assign(Object.assign({}, headers), options.headers));
861
1102
  };
862
- LocalizeApiService.prototype.ifPromise = function (fn) {
1103
+ LocalizeApiService.prototype.buildApiOptions = function (baseUrl, path, method, requestBody, headers) {
1104
+ if (path === void 0) { path = ''; }
1105
+ if (method === void 0) { method = exports.EMethod.GET; }
1106
+ if (requestBody === void 0) { requestBody = null; }
1107
+ var requestUrl = ApiHelper.buildUrl(baseUrl, path);
1108
+ var isFormData = requestBody && requestBody instanceof FormData;
1109
+ return Object.assign(Object.assign({}, this.apiOptions), { headers: headers, method: method, requestUrl: requestUrl, requestBody: requestBody, isFormData: isFormData });
1110
+ };
1111
+ LocalizeApiService.prototype.toWaitForPreviousRequest = function () {
1112
+ var _a;
863
1113
  return __awaiter(this, void 0, void 0, function () {
864
- var _b;
865
- return __generator(this, function (_c) {
866
- switch (_c.label) {
1114
+ var _b, _c;
1115
+ var _this = this;
1116
+ return __generator(this, function (_d) {
1117
+ switch (_d.label) {
867
1118
  case 0:
868
- if (!fn)
869
- return [2 /*return*/];
870
- if (!(fn instanceof Promise)) return [3 /*break*/, 2];
871
- return [4 /*yield*/, fn()];
1119
+ _b = this.isRevokingToken;
1120
+ if (!_b) return [3 /*break*/, 2];
1121
+ return [4 /*yield*/, waitUntil(function () { return !_this.isRevokingToken; })];
872
1122
  case 1:
873
- _b = _c.sent();
1123
+ _b = (_d.sent());
1124
+ _d.label = 2;
1125
+ case 2:
1126
+ _b;
1127
+ // to wait for each request in 50ms, even if the request is not completed
1128
+ _c = ((_a = this.config.waitEachRequest) === null || _a === void 0 ? void 0 : _a.milliseconds);
1129
+ if (!_c)
1130
+ // to wait for each request in 50ms, even if the request is not completed
1131
+ return [3 /*break*/, 4];
1132
+ return [4 /*yield*/, waitFor(this.config.waitEachRequest.milliseconds, this.isRequesting)];
1133
+ case 3:
1134
+ _c = (_d.sent());
1135
+ _d.label = 4;
1136
+ case 4:
1137
+ // to wait for each request in 50ms, even if the request is not completed
1138
+ _c;
1139
+ return [2 /*return*/];
1140
+ }
1141
+ });
1142
+ });
1143
+ };
1144
+ LocalizeApiService.prototype.handleOnTokenRevoked = function (response) {
1145
+ return __awaiter(this, void 0, void 0, function () {
1146
+ return __generator(this, function (_b) {
1147
+ switch (_b.label) {
1148
+ case 0:
1149
+ if (!(response === null || response === void 0 ? void 0 : response.status)) return [3 /*break*/, 1];
1150
+ // If the response is successful, update the access token
1151
+ this.accessToken = response.message;
874
1152
  return [3 /*break*/, 3];
1153
+ case 1:
1154
+ // If the response indicates an error, invoke the onRevokeUnauthorized hook
1155
+ console.warn('Token revocation failed, refresh token is expired.', response.message);
1156
+ return [4 /*yield*/, ApiHelper.invokeHook(this.config.onRevokeUnauthorized)];
1157
+ case 2:
1158
+ _b.sent();
1159
+ _b.label = 3;
1160
+ case 3: return [2 /*return*/];
1161
+ }
1162
+ });
1163
+ });
1164
+ };
1165
+ LocalizeApiService.prototype.interceptRevokeToken = function () {
1166
+ return __awaiter(this, void 0, void 0, function () {
1167
+ var _this = this;
1168
+ return __generator(this, function (_b) {
1169
+ switch (_b.label) {
1170
+ case 0:
1171
+ if (!this.isRevokingToken) return [3 /*break*/, 2];
1172
+ console.warn('Token is already being revoked. Waiting for the current operation to complete...');
1173
+ return [4 /*yield*/, waitUntil(function () { return !_this.isRevokingToken; })];
1174
+ case 1:
1175
+ _b.sent();
1176
+ return [2 /*return*/, true];
875
1177
  case 2:
876
- _b = fn();
877
- _c.label = 3;
878
- case 3: return [2 /*return*/, _b];
1178
+ if (!this.refreshToken) {
1179
+ // await ApiHelper.invokeHook(this.apiConfigs.onAutoLogout);
1180
+ throw new Error('Refresh token is missing. Please login again.');
1181
+ }
1182
+ return [2 /*return*/, false];
879
1183
  }
880
1184
  });
881
1185
  });
882
1186
  };
883
1187
  return LocalizeApiService;
884
- }()); //class
1188
+ }());
885
1189
  LocalizeApiService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function LocalizeApiService_Factory() { return new LocalizeApiService(i0__namespace.ɵɵinject(i1__namespace.HttpClient), i0__namespace.ɵɵinject(LocalizeTokenService)); }, token: LocalizeApiService, providedIn: "root" });
886
1190
  LocalizeApiService.decorators = [
887
1191
  { type: i0.Injectable, args: [{
@@ -903,12 +1207,12 @@
903
1207
  providers: [
904
1208
  LocalizeTokenService,
905
1209
  LocalizeApiService
906
- ],
1210
+ ]
907
1211
  },] }
908
1212
  ];
909
1213
 
910
1214
  var LocalizeLogindlgComponent = /** @class */ (function () {
911
- function LocalizeLogindlgComponent(messageService, cdt, dlgRef, dlgConfig, tokenService, httpClient) {
1215
+ function LocalizeLogindlgComponent(messageService, cdt, dlgRef, dlgConfig, tokenService, httpClient, sanitizer) {
912
1216
  var _this = this;
913
1217
  this.messageService = messageService;
914
1218
  this.cdt = cdt;
@@ -916,6 +1220,7 @@
916
1220
  this.dlgConfig = dlgConfig;
917
1221
  this.tokenService = tokenService;
918
1222
  this.httpClient = httpClient;
1223
+ this.sanitizer = sanitizer;
919
1224
  this.messageKey = "$login-dlg";
920
1225
  this.loading = false;
921
1226
  this.success = false;
@@ -923,6 +1228,7 @@
923
1228
  this.clickLogout = function () { var _a; return (_a = _this.logout) === null || _a === void 0 ? void 0 : _a.call(_this); };
924
1229
  this.decodeToken = this.tokenService.decodeRefreshToken;
925
1230
  this.loginConfig = this.dlgConfig.data.loginConfig;
1231
+ this.properties = this.loginConfig.properties;
926
1232
  }
927
1233
  LocalizeLogindlgComponent.prototype.ngOnInit = function () {
928
1234
  var _this = this;
@@ -942,69 +1248,77 @@
942
1248
  return __awaiter(this, void 0, void 0, function () {
943
1249
  var loginRes, cookieOptions;
944
1250
  var _this = this;
945
- return __generator(this, function (_c) {
946
- switch (_c.label) {
1251
+ return __generator(this, function (_d) {
1252
+ switch (_d.label) {
947
1253
  case 0:
948
1254
  if (!this.isValidPassword) {
949
- this.showMessage("error", "Password is required and must be at least 6 characters");
950
- return [2 /*return*/];
1255
+ return [2 /*return*/, this.showMessage("error", "Password is required and must be at least 6 characters")];
951
1256
  }
952
1257
  this.loading = true;
953
1258
  return [4 /*yield*/, this.login()];
954
1259
  case 1:
955
- loginRes = _c.sent();
1260
+ loginRes = _d.sent();
956
1261
  if (!(loginRes === null || loginRes === void 0 ? void 0 : loginRes.status)) {
957
- this.showMessage("error", (_a = loginRes.message) !== null && _a !== void 0 ? _a : "An error occurred");
958
- return [2 /*return*/];
1262
+ return [2 /*return*/, this.showMessage("error", (_a = loginRes.message) !== null && _a !== void 0 ? _a : "An error occurred")];
959
1263
  }
960
1264
  this.tokenService.accessToken = loginRes.tokens.accessToken;
961
- cookieOptions = { expires: (_b = this.loginConfig.expire) !== null && _b !== void 0 ? _b : 5 };
1265
+ cookieOptions = { expires: (_b = this.loginConfig.expire) !== null && _b !== void 0 ? _b : 365 };
962
1266
  LocalizeToken.storage.set(this.config.refreshTokenName, loginRes.tokens.refreshToken, cookieOptions);
963
1267
  this.success = true;
964
- setTimeout(function () { return _this.dlgRef.close(true); }, 2000);
1268
+ setTimeout(function () {
1269
+ _this.dlgConfig.dismissableMask = true;
1270
+ _this.dlgConfig.modal = false;
1271
+ _this.dlgRef.close(true);
1272
+ }, 2000);
965
1273
  return [2 /*return*/];
966
1274
  }
967
1275
  });
968
1276
  });
969
1277
  };
970
1278
  LocalizeLogindlgComponent.prototype.login = function () {
1279
+ var _a, _b, _c;
971
1280
  return __awaiter(this, void 0, void 0, function () {
972
1281
  var e_1;
973
1282
  var _this = this;
974
- return __generator(this, function (_c) {
975
- switch (_c.label) {
1283
+ return __generator(this, function (_d) {
1284
+ switch (_d.label) {
976
1285
  case 0:
977
- if (!this.loginUrl || !this.loginUrl.trim().length) {
1286
+ if (!((_a = this.loginUrl) === null || _a === void 0 ? void 0 : _a.trim().length)) {
978
1287
  this.showMessage("error", "Login url is required");
979
1288
  throw new Error("Login url is required");
980
1289
  }
981
- _c.label = 1;
1290
+ _d.label = 1;
982
1291
  case 1:
983
- _c.trys.push([1, 3, , 4]);
984
- return [4 /*yield*/, new Promise(function (resolve, reject) { return _this.httpClient.post(_this.loginUrl, { password: _this.password.trim() }, { headers: _this.getHeaders() })
985
- .subscribe({ next: resolve, error: reject }); })];
986
- case 2: return [2 /*return*/, _c.sent()];
987
- case 3:
988
- e_1 = _c.sent();
1292
+ _d.trys.push([1, 5, , 6]);
1293
+ if (!this.loginConfig.loginFunction) return [3 /*break*/, 3];
1294
+ console.log("Using custom login function");
1295
+ return [4 /*yield*/, this.loginConfig.loginFunction((_c = (_b = this.decodeToken) === null || _b === void 0 ? void 0 : _b.email) !== null && _c !== void 0 ? _c : '', this.password.trim(), this.getHeaders())];
1296
+ case 2: return [2 /*return*/, _d.sent()];
1297
+ case 3: return [4 /*yield*/, new Promise(function (resolve, reject) { return _this.httpClient.post(_this.loginUrl, { password: _this.password.trim() }, { headers: _this.getHeaders() }).subscribe({ next: resolve, error: reject }); })];
1298
+ case 4: return [2 /*return*/, _d.sent()];
1299
+ case 5:
1300
+ e_1 = _d.sent();
989
1301
  this.showMessage("error", e_1.message);
990
1302
  return [2 /*return*/, null];
991
- case 4: return [2 /*return*/];
1303
+ case 6: return [2 /*return*/];
992
1304
  }
993
1305
  });
994
1306
  });
995
1307
  };
996
1308
  LocalizeLogindlgComponent.prototype.getHeaders = function () {
997
- var _c;
1309
+ var _d;
998
1310
  var _a, _b;
999
- return _c = {},
1000
- _c[LocalizeToken.httpHeaders.X_REFRESH_TOKEN] = (_a = LocalizeToken.storage.get(this.config.refreshTokenName)) !== null && _a !== void 0 ? _a : "",
1001
- _c[LocalizeToken.httpHeaders.X_TENANT] = (_b = LocalizeToken.storage.get(this.loginConfig.tenantTokenName)) !== null && _b !== void 0 ? _b : "",
1002
- _c;
1311
+ return _d = {},
1312
+ _d[LocalizeToken.httpHeaders.X_REFRESH_TOKEN] = (_a = LocalizeToken.storage.get(this.config.refreshTokenName)) !== null && _a !== void 0 ? _a : "",
1313
+ _d[LocalizeToken.httpHeaders.X_TENANT] = (_b = LocalizeToken.storage.get(this.loginConfig.tenantTokenName)) !== null && _b !== void 0 ? _b : "",
1314
+ _d;
1003
1315
  };
1004
1316
  Object.defineProperty(LocalizeLogindlgComponent.prototype, "isValidPassword", {
1005
1317
  get: function () {
1006
1318
  this.loading = false;
1007
- return this.password && this.password.trim().length >= 6 && this.password.trim().length <= 50;
1319
+ return this.properties.passwordValidator
1320
+ ? this.properties.passwordValidator(this.password)
1321
+ : this.password && this.password.trim().length >= 6 && this.password.trim().length <= 50;
1008
1322
  },
1009
1323
  enumerable: false,
1010
1324
  configurable: true
@@ -1013,15 +1327,23 @@
1013
1327
  this.messageService.add({ key: this.messageKey, severity: severity, summary: summary });
1014
1328
  this.loading = false;
1015
1329
  };
1330
+ Object.defineProperty(LocalizeLogindlgComponent.prototype, "sanitizedTitle", {
1331
+ get: function () {
1332
+ var _a;
1333
+ return this.sanitizer.bypassSecurityTrustHtml((_a = this.properties.title) !== null && _a !== void 0 ? _a : '');
1334
+ },
1335
+ enumerable: false,
1336
+ configurable: true
1337
+ });
1016
1338
  return LocalizeLogindlgComponent;
1017
1339
  }());
1018
1340
  LocalizeLogindlgComponent.decorators = [
1019
1341
  { type: i0.Component, args: [{
1020
- template: "<p-toast key=\"$login-dlg\" position=\"top-center\"></p-toast>\n <div id=\"login-dlg-wrap\">\n <div id=\"login-dlg-header\">\n <div id=\"login-logo\" class=\"p-mb-2\"></div>\n <h3 *ngIf=\"!success\">Your session is expired! <br> Please login again to continue.</h3>\n <h3 *ngIf=\"success\" style=\"color:green !important;\">You haved successfully logged in.</h3>\n </div>\n <div id=\"login-dlg-content\">\n <ng-container *ngIf=\"!success\">\n <div *ngIf=\"loading\" class=\"loader-wrap\">\n <div class=\"login-dlg-loader\"></div>\n </div>\n <div class=\"login-dlg-elm\">\n <div class=\"p-inputgroup\">\n <span class=\"p-inputgroup-addon\">\n <i class=\"material-icons-round\">person</i>\n </span>\n <input disabled pInputText type=\"text\" placeholder=\"Username\" [value]=\"decodeToken?.email\" />\n </div>\n </div>\n \n <div class=\"login-dlg-elm\">\n <div class=\"p-inputgroup\">\n <span class=\"p-inputgroup-addon\">\n <i class=\"material-icons-round\">lock</i>\n </span>\n <input [disabled]=\"loading\" (keydown.enter)=\"clickLogin()\" pInputText type=\"password\" placeholder=\"Password\" [(ngModel)]=\"password\"\n autofocus />\n </div>\n </div>\n <div class=\"login-dlg-elm\">\n <button style=\"width: 100%;\" pButton type=\"button\" label=\"Login\" (click)=\"clickLogin()\"\n [disabled]=\"!password || loading\"></button>\n </div>\n \n <div class=\"login-dlg-elm\" style=\"display:flex;align-items: center;user-select: none;\">\n <span>No, I want to login with another user.</span>\n <button class=\"p-button-text\" pButton type=\"button\" label=\"Logout\" (click)=\"clickLogout()\"></button>\n </div>\n </ng-container>\n \n <ng-container *ngIf=\"success\">\n <div style=\"margin-top:35px;\"></div>\n <div class=\"check-animation-wrap\">\n <div class=\"check-main-container\">\n <div class=\"check-container\">\n <div class=\"check-background\">\n <svg viewBox=\"0 0 65 51\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M7 25L27.3077 44L58.5 7\" stroke=\"white\" stroke-width=\"13\" stroke-linecap=\"round\"\n stroke-linejoin=\"round\"></path>\n </svg>\n </div>\n </div>\n </div>\n </div>\n </ng-container>\n </div>\n </div>",
1342
+ template: "<p-toast key=\"$login-dlg\" position=\"top-center\"></p-toast>\n <div id=\"login-dlg-wrap\">\n <div id=\"login-dlg-header\">\n <div id=\"login-logo\" class=\"p-mb-2\" style=\"background: url('{{properties.logoImage}}') no-repeat\"></div>\n <h3 *ngIf=\"!success\" [innerHTML]=\"sanitizedTitle\"></h3>\n <h3 *ngIf=\"success\" style=\"color:green !important;\">{{properties.loginSuccessMessage}}</h3>\n </div>\n <div id=\"login-dlg-content\">\n <ng-container *ngIf=\"!success\">\n <div *ngIf=\"loading\" class=\"loader-wrap\">\n <div class=\"login-dlg-loader\"></div>\n </div>\n <div class=\"login-dlg-elm\">\n <div class=\"p-inputgroup\">\n <span class=\"p-inputgroup-addon\">\n <i class=\"material-icons-round\">person</i>\n </span>\n <input disabled pInputText type=\"text\" placeholder=\"{{properties.username?.placeHolder}}\" [value]=\"decodeToken?.email\" />\n </div>\n </div>\n \n <div class=\"login-dlg-elm\">\n <div class=\"p-inputgroup\">\n <span class=\"p-inputgroup-addon\">\n <i class=\"material-icons-round\">lock</i>\n </span>\n <input [disabled]=\"loading\" (keydown.enter)=\"clickLogin()\" pInputText type=\"password\" \n placeholder=\"{{properties.password?.placeHolder}}\" [(ngModel)]=\"password\"\n autofocus />\n </div>\n </div>\n <div class=\"login-dlg-elm\">\n <button style=\"width: 100%;\" pButton type=\"button\" label=\"{{properties.loginButton?.placeHolder}}\" (click)=\"clickLogin()\"\n [disabled]=\"!password || loading\"></button>\n </div>\n \n <div class=\"login-dlg-elm login-dlg-suggest\" style=\"display:flex;align-items: center;user-select: none;\">\n <span>{{properties.logoutButton?.message}}</span>\n <button class=\"p-button-text\" pButton type=\"button\" label=\"{{properties.logoutButton?.placeHolder}}\" \n (click)=\"clickLogout()\"></button>\n </div>\n </ng-container>\n \n <ng-container *ngIf=\"success\">\n <div style=\"margin-top:35px;\"></div>\n <div class=\"check-animation-wrap\">\n <div class=\"check-main-container\">\n <div class=\"check-container\">\n <div class=\"check-background\">\n <svg viewBox=\"0 0 65 51\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n <path d=\"M7 25L27.3077 44L58.5 7\" stroke=\"white\" stroke-width=\"13\" stroke-linecap=\"round\"\n stroke-linejoin=\"round\"></path>\n </svg>\n </div>\n </div>\n </div>\n </div>\n </ng-container>\n </div>\n </div>",
1021
1343
  selector: "app-localize-logindlg",
1022
1344
  providers: [api.MessageService],
1023
1345
  encapsulation: i0.ViewEncapsulation.None,
1024
- styles: ["\n #login-dlg-wrap {\n width: 100%;\n max-width: 400px;\n margin: 0 auto;\n padding: 30px;\n }\n \n .login-dlg-elm {\n margin-top: 1rem;\n }\n \n #login-dlg-header {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n }\n \n #login-dlg-header h3 {\n font-weight: bold;\n font-size: 0.9rem;\n color: orange;\n text-align: center;\n }\n \n #login-logo {\n height: 40px;\n width: 40px;\n background: url(\"/assets/images/logo-300px.png\") no-repeat;\n background-size: contain;\n }\n \n #login-dlg-content .p-inputgroup {\n height: 45px;\n }\n \n #login-dlg-content .p-inputgroup .p-inputgroup-addon {\n height: 45px;\n border-radius: 15px 0 0 15px;\n width: 50px;\n }\n \n #login-dlg-content .p-inputgroup .p-inputgroup-addon * {\n font-size: 1rem;\n }\n \n #login-dlg-content .p-inputgroup input {\n height: 45px;\n border-radius: 0 15px 15px 0;\n }\n \n #login-dlg-content button {\n height: 45px;\n border-radius: 15px;\n }\n \n /*check animation block*/\n \n .check-animation-wrap {\n top: 0;\n left: 0;\n position: absolute;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: calc(100% - 200px);\n min-height: 400px;\n }\n \n .check-main-container {\n width: 100%;\n height: 100vh;\n display: flex;\n flex-flow: column;\n justify-content: center;\n align-items: center;\n }\n \n .check-container {\n width: 6.25rem;\n height: 7.5rem;\n display: flex;\n flex-flow: column;\n align-items: center;\n justify-content: space-between;\n }\n \n .check-container .check-background {\n width: 100%;\n height: calc(100% - 1.25rem);\n background: linear-gradient(to bottom right, #5de593, #41d67c);\n box-shadow: 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset;\n transform: scale(0.84);\n border-radius: 50%;\n animation: animateContainer 0.75s ease-out forwards 0.75s;\n display: flex;\n align-items: center;\n justify-content: center;\n opacity: 0;\n }\n \n .check-container .check-background svg {\n width: 65%;\n transform: translateY(0.25rem);\n stroke-dasharray: 80;\n stroke-dashoffset: 80;\n animation: animateCheck 0.35s forwards 1.25s ease-out;\n min-width: auto !important;\n }\n \n .check-container .check-shadow {\n bottom: calc(-15% - 5px);\n left: 0;\n border-radius: 50%;\n background: radial-gradient(closest-side, rgba(73, 218, 131, 1), transparent);\n animation: animateShadow 0.75s ease-out forwards 0.75s;\n }\n \n @keyframes animateContainer {\n 0% {\n opacity: 0;\n transform: scale(0);\n box-shadow: 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset;\n }\n \n 25% {\n opacity: 1;\n transform: scale(0.9);\n box-shadow: 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset;\n }\n \n 43.75% {\n transform: scale(1.15);\n box-shadow: 0px 0px 0px 43.334px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset;\n }\n \n 62.5% {\n transform: scale(1);\n box-shadow: 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 21.667px rgba(255, 255, 255, 0.25) inset;\n }\n \n 81.25% {\n box-shadow: 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset;\n }\n \n 100% {\n opacity: 1;\n box-shadow: 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset;\n }\n }\n \n @keyframes animateCheck {\n from {\n stroke-dashoffset: 80;\n }\n \n to {\n stroke-dashoffset: 0;\n }\n }\n \n @keyframes animateShadow {\n 0% {\n opacity: 0;\n width: 100%;\n height: 15%;\n }\n \n 25% {\n opacity: 0.25;\n }\n \n 43.75% {\n width: 40%;\n height: 7%;\n opacity: 0.35;\n }\n \n 100% {\n width: 85%;\n height: 15%;\n opacity: 0.25;\n }\n }\n #login-dlg-wrap .loader-wrap {\n display: flex;\n justify-content: center;\n align-items: center;\n height:100%;\n width:100%;\n position: absolute;\n top: 0;\n left: 0;\n z-index: 100;\n background: #ffffff42;\n backdrop-filter: blur(1px);\n }\n\n #login-dlg-wrap .login-dlg-loader {\n border: 15px solid #e7e7e7;\n border-top: 15px solid #52dba1;\n border-radius: 50%;\n width: 100px;\n height: 100px;\n animation: spinloader 2s linear infinite;\n }\n\n #login-dlg-wrap .loader-wrap::before {\n content: \"\";\n position: absolute;\n width: 70px;\n height: 70px;\n transform: translate(-50%, -50%);\n z-index: 1;\n border: 15px solid #e7e7e700;\n border-top: 15px solid #52dba1c9;\n border-radius: 50%;\n animation: spinloader .75s linear infinite;\n }\n\n @keyframes spinloader {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n "]
1346
+ styles: ["\n #login-dlg-wrap {\n width: 100%;\n max-width: 400px;\n margin: 0 auto;\n padding: 30px;\n height: 100%;\n }\n \n .login-dlg-elm {\n margin-top: 1rem;\n }\n\n .login-dlg-elm.login-dlg-suggest {\n display: flex ;\n align-items: center;\n user-select: none;\n border-bottom: solid 1px #ddd;\n border-radius: 5px;\n padding: 5px 10px;\n background: #f9f9f9;\n box-shadow: 1px 5px 10px -12px #000;\n }\n \n #login-dlg-header {\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n }\n \n #login-dlg-header h3 {\n font-weight: bold;\n font-size: 0.9rem;\n color: orange;\n text-align: center;\n }\n \n #login-logo {\n height: 55px;\n width: 55px;\n /* background: url(\"/assets/images/logo-300px.png\") no-repeat; */\n background-size: contain !important;\n }\n \n #login-dlg-content .p-inputgroup {\n height: 45px;\n }\n \n #login-dlg-content .p-inputgroup .p-inputgroup-addon {\n height: 45px;\n border-radius: 15px 0 0 15px;\n width: 50px;\n }\n #login-dlg-content *{\n font-size: .9rem;\n /* font-family: 'Lexend', 'Roboto', sans-serif, 'material-icons-round'; */\n }\n \n #login-dlg-content .p-inputgroup .p-inputgroup-addon * {\n font-size: 1rem;\n }\n \n #login-dlg-content .p-inputgroup input {\n height: 45px;\n border-radius: 0 15px 15px 0;\n }\n \n #login-dlg-content button {\n height: 45px;\n border-radius: 15px;\n }\n \n /*check animation block*/\n \n .check-animation-wrap {\n top: 0;\n left: 0;\n position: absolute;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n width: 100%;\n height: calc(100% - 200px);\n min-height: 400px;\n }\n \n .check-main-container {\n width: 100%;\n height: 100vh;\n display: flex;\n flex-flow: column;\n justify-content: center;\n align-items: center;\n }\n \n .check-container {\n width: 6.25rem;\n height: 7.5rem;\n display: flex;\n flex-flow: column;\n align-items: center;\n justify-content: space-between;\n }\n \n .check-container .check-background {\n width: 100%;\n height: calc(100% - 1.25rem);\n background: linear-gradient(to bottom right, #5de593, #41d67c);\n box-shadow: 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset;\n transform: scale(0.84);\n border-radius: 50%;\n animation: animateContainer 0.75s ease-out forwards 0.75s;\n display: flex;\n align-items: center;\n justify-content: center;\n opacity: 0;\n }\n \n .check-container .check-background svg {\n width: 65%;\n transform: translateY(0.25rem);\n stroke-dasharray: 80;\n stroke-dashoffset: 80;\n animation: animateCheck 0.35s forwards 1.25s ease-out;\n min-width: auto !important;\n }\n \n .check-container .check-shadow {\n bottom: calc(-15% - 5px);\n left: 0;\n border-radius: 50%;\n background: radial-gradient(closest-side, rgba(73, 218, 131, 1), transparent);\n animation: animateShadow 0.75s ease-out forwards 0.75s;\n }\n \n @keyframes animateContainer {\n 0% {\n opacity: 0;\n transform: scale(0);\n box-shadow: 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset;\n }\n \n 25% {\n opacity: 1;\n transform: scale(0.9);\n box-shadow: 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset;\n }\n \n 43.75% {\n transform: scale(1.15);\n box-shadow: 0px 0px 0px 43.334px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 65px rgba(255, 255, 255, 0.25) inset;\n }\n \n 62.5% {\n transform: scale(1);\n box-shadow: 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 21.667px rgba(255, 255, 255, 0.25) inset;\n }\n \n 81.25% {\n box-shadow: 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset;\n }\n \n 100% {\n opacity: 1;\n box-shadow: 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset, 0px 0px 0px 0px rgba(255, 255, 255, 0.25) inset;\n }\n }\n \n @keyframes animateCheck {\n from {\n stroke-dashoffset: 80;\n }\n \n to {\n stroke-dashoffset: 0;\n }\n }\n \n @keyframes animateShadow {\n 0% {\n opacity: 0;\n width: 100%;\n height: 15%;\n }\n \n 25% {\n opacity: 0.25;\n }\n \n 43.75% {\n width: 40%;\n height: 7%;\n opacity: 0.35;\n }\n \n 100% {\n width: 85%;\n height: 15%;\n opacity: 0.25;\n }\n }\n #login-dlg-wrap .loader-wrap {\n display: flex;\n justify-content: center;\n align-items: center;\n height:100%;\n width:100%;\n position: absolute;\n top: 0;\n left: 0;\n z-index: 100;\n background: #ffffff42;\n backdrop-filter: blur(1px);\n }\n\n #login-dlg-wrap .login-dlg-loader {\n border: 15px solid #e7e7e7;\n border-top: 15px solid #52dba1;\n border-radius: 50%;\n width: 100px;\n height: 100px;\n animation: spinloader 2s linear infinite;\n }\n\n #login-dlg-wrap .loader-wrap::before {\n content: \"\";\n position: absolute;\n width: 70px;\n height: 70px;\n transform: translate(-50%, -50%);\n z-index: 1;\n border: 15px solid #e7e7e700;\n border-top: 15px solid #52dba1c9;\n border-radius: 50%;\n animation: spinloader .75s linear infinite;\n }\n\n @keyframes spinloader {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n "]
1025
1347
  },] }
1026
1348
  ];
1027
1349
  LocalizeLogindlgComponent.ctorParameters = function () { return [
@@ -1030,7 +1352,8 @@
1030
1352
  { type: dynamicdialog.DynamicDialogRef },
1031
1353
  { type: dynamicdialog.DynamicDialogConfig },
1032
1354
  { type: LocalizeTokenService },
1033
- { type: i1.HttpClient }
1355
+ { type: i1.HttpClient },
1356
+ { type: platformBrowser.DomSanitizer }
1034
1357
  ]; };
1035
1358
 
1036
1359
  var LocalizeLogindlgService = /** @class */ (function () {
@@ -1040,15 +1363,12 @@
1040
1363
  LocalizeLogindlgService.prototype.openLoginDialog = function (loginConfig, config) {
1041
1364
  return __awaiter(this, void 0, void 0, function () {
1042
1365
  var dialogService, dialog;
1043
- return __generator(this, function (_a) {
1044
- switch (_a.label) {
1366
+ return __generator(this, function (_b) {
1367
+ switch (_b.label) {
1045
1368
  case 0:
1046
- config !== null && config !== void 0 ? config : (config = {
1047
- header: 'Login',
1048
- height: '650px',
1049
- style: { 'max-width': '400px', width: '100%', 'height': '650px' },
1050
- });
1051
- config.data = Object.assign(Object.assign({}, config.data || {}), { loginConfig: loginConfig });
1369
+ config = this.intercepDialogConfig(config);
1370
+ this.initConfig(loginConfig);
1371
+ config.data = Object.assign(Object.assign({}, (config.data || {})), { loginConfig: loginConfig });
1052
1372
  dialogService = this.injector.get(dynamicdialog.DialogService);
1053
1373
  dialog = dialogService.open(LocalizeLogindlgComponent, config);
1054
1374
  return [4 /*yield*/, new Promise(function (resolve) { return dialog.onClose.subscribe(function (res) {
@@ -1057,12 +1377,42 @@
1057
1377
  }
1058
1378
  }); })];
1059
1379
  case 1:
1060
- _a.sent();
1380
+ _b.sent();
1061
1381
  return [2 /*return*/];
1062
1382
  }
1063
1383
  });
1064
1384
  });
1065
1385
  };
1386
+ LocalizeLogindlgService.prototype.intercepDialogConfig = function (config) {
1387
+ config !== null && config !== void 0 ? config : (config = {
1388
+ header: 'Login',
1389
+ style: { 'max-width': '400px', width: '100%', 'height': '650px' },
1390
+ modal: true,
1391
+ closable: false,
1392
+ showHeader: false,
1393
+ });
1394
+ config = Object.assign(Object.assign({}, config), {
1395
+ contentStyle: { 'height': '100%', 'border-radius': '20px' }
1396
+ });
1397
+ config.style = Object.assign(Object.assign({}, config.style), { 'border-radius': '20px' });
1398
+ return config;
1399
+ };
1400
+ LocalizeLogindlgService.prototype.initConfig = function (loginConfig) {
1401
+ var _a;
1402
+ loginConfig !== null && loginConfig !== void 0 ? loginConfig : (loginConfig = {});
1403
+ (_a = loginConfig.properties) !== null && _a !== void 0 ? _a : (loginConfig.properties = {
1404
+ title: 'Your session is expired!<br/> Please login again to continue.',
1405
+ loginSuccessMessage: 'You have successfully logged in.',
1406
+ logoImage: '/assets/images/logo-300px.png',
1407
+ username: { placeHolder: 'Username' },
1408
+ password: { placeHolder: 'Password' },
1409
+ loginButton: { placeHolder: 'Login' },
1410
+ logoutButton: {
1411
+ message: 'No, I want to login with another user.',
1412
+ placeHolder: 'Logout'
1413
+ }
1414
+ });
1415
+ };
1066
1416
  return LocalizeLogindlgService;
1067
1417
  }());
1068
1418
  LocalizeLogindlgService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function LocalizeLogindlgService_Factory() { return new LocalizeLogindlgService(i0__namespace.ɵɵinject(i0__namespace.INJECTOR)); }, token: LocalizeLogindlgService, providedIn: "root" });
@@ -1101,6 +1451,7 @@
1101
1451
  * Generated bundle index. Do not edit.
1102
1452
  */
1103
1453
 
1454
+ exports.ApiHelper = ApiHelper;
1104
1455
  exports.LocalizeApiService = LocalizeApiService;
1105
1456
  exports.LocalizeLogindlgComponent = LocalizeLogindlgComponent;
1106
1457
  exports.LocalizeLogindlgModule = LocalizeLogindlgModule;