@sambath999/localize-token 12.3.1 → 12.3.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.
@@ -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 () {
@@ -659,31 +661,257 @@
659
661
  */
660
662
  exports.EMethod = void 0;
661
663
  (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 = {}));
664
+ EMethod["POST"] = "post";
665
+ EMethod["GET"] = "get";
666
+ EMethod["PUT"] = "put";
667
+ EMethod["DELETE"] = "delete";
668
+ EMethod["PATCH"] = "patch";
669
+ })(exports.EMethod || (exports.EMethod = {}));
670
+
671
+ var LocalizeApiHelper = /** @class */ (function () {
672
+ function LocalizeApiHelper() {
673
+ this.defaultRetryOptions = {
674
+ connectionError: {
675
+ message: 'Connection error occurred. Please wait',
676
+ blockScreen: true,
677
+ blockScreenZIndex: 10000
678
+ }
679
+ };
680
+ }
681
+ LocalizeApiHelper.prototype.performRetry = function (options) {
682
+ return __awaiter(this, void 0, void 0, function () {
683
+ var attempts, lastError, consoleCount, styleElement, result, error_1;
684
+ return __generator(this, function (_e) {
685
+ switch (_e.label) {
686
+ case 0:
687
+ attempts = 0;
688
+ consoleCount = 0;
689
+ // Merge default retry options with provided options
690
+ options = Object.assign(Object.assign({}, this.defaultRetryOptions), options);
691
+ _e.label = 1;
692
+ case 1:
693
+ if (!(attempts < options.maxRetries())) return [3 /*break*/, 10];
694
+ _e.label = 2;
695
+ case 2:
696
+ _e.trys.push([2, 4, , 9]);
697
+ return [4 /*yield*/, options.callback()];
698
+ case 3:
699
+ result = _e.sent();
700
+ this.removeBlocker(styleElement);
701
+ return [2 /*return*/, result];
702
+ case 4:
703
+ error_1 = _e.sent();
704
+ lastError = error_1;
705
+ if (consoleCount >= 7) {
706
+ console.clear();
707
+ consoleCount = 0;
708
+ }
709
+ if (options.retryUnless && !options.retryUnless(error_1))
710
+ throw error_1; // If the error should not be retried, rethrow it
711
+ return [4 /*yield*/, this.onConnectionError(options, error_1)];
712
+ case 5:
713
+ // Handle connection error
714
+ styleElement = _e.sent();
715
+ if (!options.onError) return [3 /*break*/, 7];
716
+ return [4 /*yield*/, this.invokeHook(options.onError.bind(this, error_1))];
717
+ case 6:
718
+ _e.sent();
719
+ _e.label = 7;
720
+ case 7:
721
+ if (attempts >= options.maxRetries() - 1)
722
+ throw error_1;
723
+ attempts++;
724
+ consoleCount++;
725
+ console.warn("Attempt " + attempts + " failed. Retrying...", error_1);
726
+ return [4 /*yield*/, waitFor(options.delay)];
727
+ case 8:
728
+ _e.sent();
729
+ return [3 /*break*/, 9];
730
+ case 9: return [3 /*break*/, 1];
731
+ case 10:
732
+ console.warn("Failed after " + options.maxRetries + " attempts");
733
+ throw lastError;
734
+ }
735
+ });
736
+ });
737
+ };
738
+ LocalizeApiHelper.prototype.performRequestWithRetry = function (options, config, performRequest) {
739
+ var _a, _b, _c, _d;
740
+ return __awaiter(this, void 0, void 0, function () {
741
+ var retryUnless;
742
+ return __generator(this, function (_e) {
743
+ switch (_e.label) {
744
+ case 0:
745
+ retryUnless = ((_a = config.retryOptions) === null || _a === void 0 ? void 0 : _a.retryFunction)
746
+ || this.isConnectionError;
747
+ return [4 /*yield*/, this.performRetry({
748
+ connectionError: (_b = config.retryOptions) === null || _b === void 0 ? void 0 : _b.onConnectionError,
749
+ maxRetries: function () { var _a, _b; return (_b = (_a = config.retryOptions) === null || _a === void 0 ? void 0 : _a.maxRetries) !== null && _b !== void 0 ? _b : 1000; },
750
+ delay: (_d = (_c = config.retryOptions) === null || _c === void 0 ? void 0 : _c.delay) !== null && _d !== void 0 ? _d : 500,
751
+ callback: function () { return performRequest(options); },
752
+ retryUnless: retryUnless,
753
+ })];
754
+ case 1: return [2 /*return*/, _e.sent()];
755
+ }
756
+ });
757
+ });
758
+ };
759
+ LocalizeApiHelper.prototype.buildUrl = function (baseUrl, path) {
760
+ var normalizedUrl = "" + baseUrl.trim().replace(/\/?$/, '/') + path.trim().replace(/^\//, '');
761
+ return normalizedUrl.endsWith('/')
762
+ ? normalizedUrl.slice(0, -1)
763
+ : normalizedUrl;
764
+ };
765
+ LocalizeApiHelper.prototype.normalizeError = function (error) {
766
+ var _a, _b, _c;
767
+ return {
768
+ code: ((_a = error.error) === null || _a === void 0 ? void 0 : _a.code) || "HTTP_" + error.status,
769
+ message: ((_b = error.error) === null || _b === void 0 ? void 0 : _b.message) || error.message,
770
+ details: (_c = error.error) === null || _c === void 0 ? void 0 : _c.details,
771
+ status: error.status
772
+ };
773
+ };
774
+ LocalizeApiHelper.prototype.invokeHook = function (callback) {
775
+ return __awaiter(this, void 0, void 0, function () {
776
+ var result;
777
+ return __generator(this, function (_e) {
778
+ switch (_e.label) {
779
+ case 0:
780
+ if (!callback)
781
+ return [2 /*return*/];
782
+ result = callback();
783
+ if (!(result instanceof Promise)) return [3 /*break*/, 2];
784
+ return [4 /*yield*/, result];
785
+ case 1:
786
+ _e.sent();
787
+ _e.label = 2;
788
+ case 2: return [2 /*return*/];
789
+ }
790
+ });
791
+ });
792
+ };
793
+ LocalizeApiHelper.prototype.createRequest = function (instance, method, url, body, options) {
794
+ var _this = this;
795
+ 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) {
796
+ // Convert to a non-observable error to handle in the promise
797
+ return rxjs.throwError(function () { return _this.normalizeError(error); });
798
+ }));
799
+ return request$;
800
+ };
801
+ LocalizeApiHelper.prototype.defaultRetryFunction = function (error) {
802
+ // Don't retry for other errors (like 400, 401, 403, etc.)
803
+ if (!this.isConnectionError(error))
804
+ throw error;
805
+ return true;
806
+ };
807
+ LocalizeApiHelper.prototype.isConnectionError = function (error) {
808
+ var isNetworkError = error.status === 0;
809
+ var isServerError = error.status >= 1000 && error.status < 600;
810
+ return isNetworkError || isServerError;
811
+ };
812
+ LocalizeApiHelper.prototype.onConnectionError = function (options, error) {
813
+ var _a;
814
+ return __awaiter(this, void 0, void 0, function () {
815
+ var styleElement;
816
+ return __generator(this, function (_e) {
817
+ switch (_e.label) {
818
+ case 0:
819
+ if (!options.connectionError)
820
+ return [2 /*return*/];
821
+ if (!this.isConnectionError(error)) return [3 /*break*/, 2];
822
+ styleElement = this.screenBlocker(options, error, true);
823
+ return [4 /*yield*/, this.invokeHook((_a = options.connectionError.callback) === null || _a === void 0 ? void 0 : _a.bind(this, error))];
824
+ case 1:
825
+ _e.sent();
826
+ return [2 /*return*/, styleElement];
827
+ case 2:
828
+ this.screenBlocker(options, error, false);
829
+ styleElement === null || styleElement === void 0 ? void 0 : styleElement.remove();
830
+ _e.label = 3;
831
+ case 3: return [2 /*return*/];
832
+ }
833
+ });
834
+ });
835
+ };
836
+ LocalizeApiHelper.prototype.validateConfig = function (config) {
837
+ var _a;
838
+ if (LocalizeToken.config.needTenant && !((_a = config.tenantTokenName) === null || _a === void 0 ? void 0 : _a.trim().length)) {
839
+ throw Error('Tenant token is required but tenantTokenName is not configured');
840
+ }
841
+ if (!LocalizeToken.config.revokeTokenUrl.trim().length) {
842
+ throw Error('Revoke token URL is not configured - token refresh will not work');
843
+ }
844
+ };
845
+ LocalizeApiHelper.prototype.screenBlocker = function (optons, error, add) {
846
+ if (add === void 0) { add = true; }
847
+ var _a, _b, _c, _d;
848
+ if (!((_a = optons.connectionError) === null || _a === void 0 ? void 0 : _a.blockScreen))
849
+ return;
850
+ if (error instanceof i1.HttpErrorResponse)
851
+ error = this.normalizeError(error);
852
+ var message = ((_b = optons.connectionError) === null || _b === void 0 ? void 0 : _b.message)
853
+ || 'Connection error occurred. Please wait';
854
+ var errorMessage = (error === null || error === void 0 ? void 0 : error.message) || 'An error occurred';
855
+ var suggestinMessage = ((_c = optons.connectionError) === null || _c === void 0 ? void 0 : _c.suggestionMessage)
856
+ || 'Please check your internet connection or the server status.';
857
+ var zIndex = ((_d = optons.connectionError) === null || _d === void 0 ? void 0 : _d.blockScreenZIndex) || 10000;
858
+ var body = document.body;
859
+ 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 ";
860
+ 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 ";
861
+ var styleElement = document.createElement('style');
862
+ if (add) {
863
+ if (!document.querySelector('.lze-blocker')) {
864
+ styleElement.innerHTML = style;
865
+ document.head.appendChild(styleElement);
866
+ body.insertAdjacentHTML('beforeend', blcokerHtml);
867
+ }
868
+ }
869
+ else {
870
+ this.removeBlocker(styleElement);
871
+ }
872
+ return styleElement;
873
+ };
874
+ LocalizeApiHelper.prototype.removeBlocker = function (styleElement) {
875
+ var blocker = document.querySelector('.lze-blocker');
876
+ blocker === null || blocker === void 0 ? void 0 : blocker.remove();
877
+ styleElement === null || styleElement === void 0 ? void 0 : styleElement.remove();
878
+ };
879
+ return LocalizeApiHelper;
880
+ }());
881
+ var ApiHelper = new LocalizeApiHelper();
882
+
883
+ var SCHEMES = LocalizeToken.httpHeaders;
668
884
  var LocalizeApiService = /** @class */ (function () {
669
885
  function LocalizeApiService(httpClient, localizeTokenService) {
670
886
  var _this = this;
671
887
  this.httpClient = httpClient;
672
888
  this.localizeTokenService = localizeTokenService;
889
+ this.destroy$ = new rxjs.Subject();
673
890
  this.isRequestingSubject = new rxjs.BehaviorSubject(false);
674
- this.isResolvedStartupSubject = new rxjs.BehaviorSubject(false);
675
- this.apiConfigs = {};
891
+ this.needTenant = LocalizeToken.config.needTenant;
892
+ this.config = {
893
+ waitEachRequest: { milliseconds: 0 },
894
+ enableRequestCancellation: true,
895
+ retryOptions: {
896
+ maxRetries: 1000,
897
+ delay: 1000,
898
+ retryFunction: ApiHelper.defaultRetryFunction.bind(this),
899
+ },
900
+ };
901
+ this.apiOptions = {
902
+ method: exports.EMethod.GET,
903
+ requestBody: null,
904
+ };
676
905
  /**
677
906
  * A higher-order function that returns a curried function for making API requests.
678
907
  *
679
908
  * @param baseUrl - The base URL of the API.
680
909
  * @returns A curried function that can be used to make API requests.
681
910
  */
682
- this.func = function (baseUrl) { return function (path, method, value, isFormData, headers) {
911
+ this.func = function (baseUrl) { return function (path, method, reqBody, reqHeaders) {
683
912
  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);
913
+ if (reqBody === void 0) { reqBody = null; }
914
+ return _this.request(baseUrl, path, method, reqBody, reqHeaders);
687
915
  }; };
688
916
  }
689
917
  Object.defineProperty(LocalizeApiService.prototype, "isRequesting", {
@@ -691,8 +919,25 @@
691
919
  enumerable: false,
692
920
  configurable: true
693
921
  });
694
- Object.defineProperty(LocalizeApiService.prototype, "isResolvedStartup", {
695
- get: function () { return this.isResolvedStartupSubject.value; },
922
+ Object.defineProperty(LocalizeApiService.prototype, "isRevokingToken", {
923
+ get: function () { return this.localizeTokenService.isRevokingToken; },
924
+ set: function (value) { this.localizeTokenService.isRevokingToken = value; },
925
+ enumerable: false,
926
+ configurable: true
927
+ });
928
+ Object.defineProperty(LocalizeApiService.prototype, "accessToken", {
929
+ get: function () { return this.localizeTokenService.accessToken; },
930
+ set: function (value) { this.localizeTokenService.accessToken = value; },
931
+ enumerable: false,
932
+ configurable: true
933
+ });
934
+ Object.defineProperty(LocalizeApiService.prototype, "refreshToken", {
935
+ get: function () { return this.localizeTokenService.refreshToken; },
936
+ enumerable: false,
937
+ configurable: true
938
+ });
939
+ Object.defineProperty(LocalizeApiService.prototype, "tenantToken", {
940
+ get: function () { return this.localizeTokenService.tenantToken(this.config.tenantTokenName); },
696
941
  enumerable: false,
697
942
  configurable: true
698
943
  });
@@ -701,187 +946,235 @@
701
946
  * @param apiConfigs - The API configurations.
702
947
  */
703
948
  LocalizeApiService.prototype.init = function (apiConfigs) {
704
- this.apiConfigs = apiConfigs;
949
+ this.config = Object.assign(Object.assign({}, this.config), apiConfigs);
950
+ ApiHelper.validateConfig(this.config);
705
951
  };
706
- LocalizeApiService.prototype.base = function (baseUrl, path, method, value, isFormData, headers) {
952
+ LocalizeApiService.prototype.cancelPendingRequests = function () {
953
+ this.config.enableRequestCancellation
954
+ && this.destroy$.next();
955
+ };
956
+ LocalizeApiService.prototype.ngOnDestroy = function () {
957
+ this.destroy$.next();
958
+ this.destroy$.complete();
959
+ };
960
+ LocalizeApiService.prototype.request = function (baseUrl, path, method, reqBody, reqHeaders) {
707
961
  if (method === void 0) { method = exports.EMethod.GET; }
708
- if (value === void 0) { value = null; }
709
- if (isFormData === void 0) { isFormData = false; }
962
+ if (reqBody === void 0) { reqBody = null; }
710
963
  return __awaiter(this, void 0, void 0, function () {
711
- var url, httpMethod, request, error_1;
712
- var _this = this;
964
+ var apiOptions, error_1;
713
965
  return __generator(this, function (_b) {
714
966
  switch (_b.label) {
715
- case 0: return [4 /*yield*/, this.ifPromise(this.apiConfigs.onPrepareRequest)];
967
+ case 0: return [4 /*yield*/, ApiHelper.invokeHook(this.config.onPrepareRequest)];
716
968
  case 1:
717
969
  _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()];
970
+ apiOptions = this.buildApiOptions(baseUrl, path, method, reqBody, reqHeaders);
971
+ _b.label = 2;
723
972
  case 2:
724
- // Wait for previous request to complete
725
- _b.sent();
726
- _b.label = 3;
973
+ _b.trys.push([2, 5, , 7]);
974
+ return [4 /*yield*/, this.toWaitForPreviousRequest()];
727
975
  case 3:
728
- _b.trys.push([3, 5, , 7]);
729
- return [4 /*yield*/, this.processRequest(httpMethod, url, request())];
976
+ _b.sent();
977
+ return [4 /*yield*/, ApiHelper.performRequestWithRetry(apiOptions, this.config, this.performRequest.bind(this))];
730
978
  case 4: return [2 /*return*/, _b.sent()];
731
979
  case 5:
732
980
  error_1 = _b.sent();
733
- if (error_1.status !== 401) {
734
- throw error_1;
735
- }
736
- return [4 /*yield*/, this.onUnauthorizedError(httpMethod, url, request)];
981
+ return [4 /*yield*/, this.handleOnRequestError(error_1, apiOptions)];
737
982
  case 6: return [2 /*return*/, _b.sent()];
738
983
  case 7: return [2 /*return*/];
739
984
  }
740
985
  });
741
986
  });
742
987
  };
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;
988
+ LocalizeApiService.prototype.handleOnRequestError = function (error, options) {
760
989
  return __awaiter(this, void 0, void 0, function () {
761
990
  var _this = this;
762
991
  return __generator(this, function (_b) {
763
992
  switch (_b.label) {
764
993
  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*/];
994
+ if (error.status !== 401)
995
+ throw error;
996
+ return [4 /*yield*/, ApiHelper.performRetry({
997
+ maxRetries: function () { return 1000; },
998
+ delay: 500,
999
+ retryUnless: function (error) { return error.status === 401 || ApiHelper.isConnectionError(error); },
1000
+ callback: function () { return __awaiter(_this, void 0, void 0, function () {
1001
+ return __generator(this, function (_b) {
1002
+ switch (_b.label) {
1003
+ case 0:
1004
+ // Only handle 401 Unauthorized errors
1005
+ return [4 /*yield*/, this.revokeToken()];
1006
+ case 1:
1007
+ // Only handle 401 Unauthorized errors
1008
+ _b.sent();
1009
+ return [4 /*yield*/, this.performRequest(options)];
1010
+ case 2:
1011
+ // Retry the request with the new access token
1012
+ return [2 /*return*/, _b.sent()];
1013
+ }
1014
+ });
1015
+ }); }
1016
+ })];
1017
+ case 1: return [2 /*return*/, _b.sent()];
777
1018
  }
778
1019
  });
779
1020
  });
780
1021
  };
781
- LocalizeApiService.prototype.processRequest = function (method, url, options) {
1022
+ LocalizeApiService.prototype.performRequest = function (options) {
782
1023
  return __awaiter(this, void 0, void 0, function () {
783
- var result;
1024
+ var buildOptions, request$, response;
784
1025
  var _this = this;
785
1026
  return __generator(this, function (_b) {
786
1027
  switch (_b.label) {
787
1028
  case 0:
1029
+ buildOptions = { headers: this.buildHeaderOptions(options) };
1030
+ request$ = ApiHelper.createRequest({
1031
+ client: this.httpClient,
1032
+ destroy$: function () { return _this.destroy$; }
1033
+ }, options.method, options.requestUrl, options.requestBody, buildOptions);
1034
+ // Set the isRequesting state to true before making the request
788
1035
  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 }); })];
1036
+ return [4 /*yield*/, new Promise(function (resolve, reject) { return request$.subscribe({ next: function (res) { return resolve(res.body); }, error: reject }); })];
790
1037
  case 1:
791
- result = _b.sent();
1038
+ response = _b.sent();
1039
+ // Reset the isRequesting state after the request completes
792
1040
  this.isRequestingSubject.next(false);
793
- return [2 /*return*/, result];
1041
+ return [2 /*return*/, response];
794
1042
  }
795
1043
  });
796
1044
  });
797
1045
  };
798
1046
  LocalizeApiService.prototype.revokeToken = function () {
799
1047
  return __awaiter(this, void 0, void 0, function () {
800
- var reqUrl_1, reqHeaders_1, revokeToken;
801
- var _this = this;
1048
+ var apiOptions, revokeToken, error_2;
802
1049
  return __generator(this, function (_b) {
803
1050
  switch (_b.label) {
804
1051
  case 0:
805
- if (!this.localizeTokenService.isRevokingToken) return [3 /*break*/, 2];
806
- return [4 /*yield*/, waitUntil(function () { return !_this.localizeTokenService.isRevokingToken; })];
1052
+ _b.trys.push([0, 4, 6, 7]);
1053
+ return [4 /*yield*/, this.interceptRevokeToken()];
807
1054
  case 1:
808
- _b.sent();
809
- return [2 /*return*/];
1055
+ if (_b.sent())
1056
+ return [2 /*return*/];
1057
+ this.isRevokingToken = true;
1058
+ apiOptions = Object.assign(Object.assign({}, this.buildApiOptions(LocalizeToken.config.revokeTokenUrl)), { refreshToken: true });
1059
+ return [4 /*yield*/, ApiHelper.performRequestWithRetry(apiOptions, this.config, this.performRequest.bind(this))];
810
1060
  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
1061
  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];
1062
+ return [4 /*yield*/, this.handleOnTokenRevoked(revokeToken)];
1063
+ case 3:
1064
+ _b.sent();
1065
+ return [3 /*break*/, 7];
821
1066
  case 4:
822
- if (!!this.localizeTokenService.refreshToken) return [3 /*break*/, 6];
823
- return [4 /*yield*/, this.ifPromise(this.apiConfigs.onAutoLogout)];
1067
+ error_2 = _b.sent();
1068
+ // Handle the error, log it
1069
+ return [4 /*yield*/, ApiHelper.invokeHook(this.config.onAutoLogout)];
824
1070
  case 5:
1071
+ // Handle the error, log it
825
1072
  _b.sent();
826
- return [3 /*break*/, 8];
1073
+ return [3 /*break*/, 7];
827
1074
  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;
1075
+ // Reset the revoking token state
1076
+ this.isRevokingToken = false;
836
1077
  return [7 /*endfinally*/];
837
- case 10: return [2 /*return*/];
1078
+ case 7: return [2 /*return*/];
838
1079
  }
839
1080
  });
840
1081
  });
841
1082
  };
842
1083
  /** 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);
1084
+ LocalizeApiService.prototype.buildHeaderOptions = function (options) {
1085
+ var _b, _c, _d, _e;
1086
+ 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)));
1087
+ if (!options.refreshToken) {
1088
+ 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)));
850
1089
  }
851
- if (!isFormData) {
852
- defaultHeaders[LocalizeToken.httpHeaders.CONTENT_TYPE] = 'application/json';
853
- }
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);
1090
+ return new i1.HttpHeaders(Object.assign(Object.assign({}, headers), options.headers));
1091
+ };
1092
+ LocalizeApiService.prototype.buildApiOptions = function (baseUrl, path, method, requestBody, headers) {
1093
+ if (path === void 0) { path = ''; }
1094
+ if (method === void 0) { method = exports.EMethod.GET; }
1095
+ if (requestBody === void 0) { requestBody = null; }
1096
+ var requestUrl = ApiHelper.buildUrl(baseUrl, path);
1097
+ var isFormData = requestBody && requestBody instanceof FormData;
1098
+ return Object.assign(Object.assign({}, this.apiOptions), { headers: headers, method: method, requestUrl: requestUrl, requestBody: requestBody, isFormData: isFormData });
861
1099
  };
862
- LocalizeApiService.prototype.ifPromise = function (fn) {
1100
+ LocalizeApiService.prototype.toWaitForPreviousRequest = function () {
1101
+ var _a;
863
1102
  return __awaiter(this, void 0, void 0, function () {
864
- var _b;
865
- return __generator(this, function (_c) {
866
- switch (_c.label) {
1103
+ var _b, _c;
1104
+ var _this = this;
1105
+ return __generator(this, function (_d) {
1106
+ switch (_d.label) {
867
1107
  case 0:
868
- if (!fn)
869
- return [2 /*return*/];
870
- if (!(fn instanceof Promise)) return [3 /*break*/, 2];
871
- return [4 /*yield*/, fn()];
1108
+ _b = this.isRevokingToken;
1109
+ if (!_b) return [3 /*break*/, 2];
1110
+ return [4 /*yield*/, waitUntil(function () { return !_this.isRevokingToken; })];
872
1111
  case 1:
873
- _b = _c.sent();
1112
+ _b = (_d.sent());
1113
+ _d.label = 2;
1114
+ case 2:
1115
+ _b;
1116
+ // to wait for each request in 50ms, even if the request is not completed
1117
+ _c = ((_a = this.config.waitEachRequest) === null || _a === void 0 ? void 0 : _a.milliseconds);
1118
+ if (!_c)
1119
+ // to wait for each request in 50ms, even if the request is not completed
1120
+ return [3 /*break*/, 4];
1121
+ return [4 /*yield*/, waitFor(this.config.waitEachRequest.milliseconds, this.isRequesting)];
1122
+ case 3:
1123
+ _c = (_d.sent());
1124
+ _d.label = 4;
1125
+ case 4:
1126
+ // to wait for each request in 50ms, even if the request is not completed
1127
+ _c;
1128
+ return [2 /*return*/];
1129
+ }
1130
+ });
1131
+ });
1132
+ };
1133
+ LocalizeApiService.prototype.handleOnTokenRevoked = function (response) {
1134
+ return __awaiter(this, void 0, void 0, function () {
1135
+ return __generator(this, function (_b) {
1136
+ switch (_b.label) {
1137
+ case 0:
1138
+ if (!(response === null || response === void 0 ? void 0 : response.status)) return [3 /*break*/, 1];
1139
+ // If the response is successful, update the access token
1140
+ this.accessToken = response.message;
874
1141
  return [3 /*break*/, 3];
1142
+ case 1:
1143
+ // If the response indicates an error, invoke the onRevokeUnauthorized hook
1144
+ console.warn('Token revocation failed, refresh token is expired.', response.message);
1145
+ return [4 /*yield*/, ApiHelper.invokeHook(this.config.onRevokeUnauthorized)];
1146
+ case 2:
1147
+ _b.sent();
1148
+ _b.label = 3;
1149
+ case 3: return [2 /*return*/];
1150
+ }
1151
+ });
1152
+ });
1153
+ };
1154
+ LocalizeApiService.prototype.interceptRevokeToken = function () {
1155
+ return __awaiter(this, void 0, void 0, function () {
1156
+ var _this = this;
1157
+ return __generator(this, function (_b) {
1158
+ switch (_b.label) {
1159
+ case 0:
1160
+ if (!this.isRevokingToken) return [3 /*break*/, 2];
1161
+ console.warn('Token is already being revoked. Waiting for the current operation to complete...');
1162
+ return [4 /*yield*/, waitUntil(function () { return !_this.isRevokingToken; })];
1163
+ case 1:
1164
+ _b.sent();
1165
+ return [2 /*return*/, true];
875
1166
  case 2:
876
- _b = fn();
877
- _c.label = 3;
878
- case 3: return [2 /*return*/, _b];
1167
+ if (!this.refreshToken) {
1168
+ // await ApiHelper.invokeHook(this.apiConfigs.onAutoLogout);
1169
+ throw new Error('Refresh token is missing. Please login again.');
1170
+ }
1171
+ return [2 /*return*/, false];
879
1172
  }
880
1173
  });
881
1174
  });
882
1175
  };
883
1176
  return LocalizeApiService;
884
- }()); //class
1177
+ }());
885
1178
  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
1179
  LocalizeApiService.decorators = [
887
1180
  { type: i0.Injectable, args: [{
@@ -908,7 +1201,7 @@
908
1201
  ];
909
1202
 
910
1203
  var LocalizeLogindlgComponent = /** @class */ (function () {
911
- function LocalizeLogindlgComponent(messageService, cdt, dlgRef, dlgConfig, tokenService, httpClient) {
1204
+ function LocalizeLogindlgComponent(messageService, cdt, dlgRef, dlgConfig, tokenService, httpClient, sanitizer) {
912
1205
  var _this = this;
913
1206
  this.messageService = messageService;
914
1207
  this.cdt = cdt;
@@ -916,6 +1209,7 @@
916
1209
  this.dlgConfig = dlgConfig;
917
1210
  this.tokenService = tokenService;
918
1211
  this.httpClient = httpClient;
1212
+ this.sanitizer = sanitizer;
919
1213
  this.messageKey = "$login-dlg";
920
1214
  this.loading = false;
921
1215
  this.success = false;
@@ -923,6 +1217,7 @@
923
1217
  this.clickLogout = function () { var _a; return (_a = _this.logout) === null || _a === void 0 ? void 0 : _a.call(_this); };
924
1218
  this.decodeToken = this.tokenService.decodeRefreshToken;
925
1219
  this.loginConfig = this.dlgConfig.data.loginConfig;
1220
+ this.properties = this.loginConfig.properties;
926
1221
  }
927
1222
  LocalizeLogindlgComponent.prototype.ngOnInit = function () {
928
1223
  var _this = this;
@@ -942,69 +1237,77 @@
942
1237
  return __awaiter(this, void 0, void 0, function () {
943
1238
  var loginRes, cookieOptions;
944
1239
  var _this = this;
945
- return __generator(this, function (_c) {
946
- switch (_c.label) {
1240
+ return __generator(this, function (_d) {
1241
+ switch (_d.label) {
947
1242
  case 0:
948
1243
  if (!this.isValidPassword) {
949
- this.showMessage("error", "Password is required and must be at least 6 characters");
950
- return [2 /*return*/];
1244
+ return [2 /*return*/, this.showMessage("error", "Password is required and must be at least 6 characters")];
951
1245
  }
952
1246
  this.loading = true;
953
1247
  return [4 /*yield*/, this.login()];
954
1248
  case 1:
955
- loginRes = _c.sent();
1249
+ loginRes = _d.sent();
956
1250
  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*/];
1251
+ return [2 /*return*/, this.showMessage("error", (_a = loginRes.message) !== null && _a !== void 0 ? _a : "An error occurred")];
959
1252
  }
960
1253
  this.tokenService.accessToken = loginRes.tokens.accessToken;
961
- cookieOptions = { expires: (_b = this.loginConfig.expire) !== null && _b !== void 0 ? _b : 5 };
1254
+ cookieOptions = { expires: (_b = this.loginConfig.expire) !== null && _b !== void 0 ? _b : 365 };
962
1255
  LocalizeToken.storage.set(this.config.refreshTokenName, loginRes.tokens.refreshToken, cookieOptions);
963
1256
  this.success = true;
964
- setTimeout(function () { return _this.dlgRef.close(true); }, 2000);
1257
+ setTimeout(function () {
1258
+ _this.dlgConfig.dismissableMask = true;
1259
+ _this.dlgConfig.modal = false;
1260
+ _this.dlgRef.close(true);
1261
+ }, 2000);
965
1262
  return [2 /*return*/];
966
1263
  }
967
1264
  });
968
1265
  });
969
1266
  };
970
1267
  LocalizeLogindlgComponent.prototype.login = function () {
1268
+ var _a, _b, _c;
971
1269
  return __awaiter(this, void 0, void 0, function () {
972
1270
  var e_1;
973
1271
  var _this = this;
974
- return __generator(this, function (_c) {
975
- switch (_c.label) {
1272
+ return __generator(this, function (_d) {
1273
+ switch (_d.label) {
976
1274
  case 0:
977
- if (!this.loginUrl || !this.loginUrl.trim().length) {
1275
+ if (!((_a = this.loginUrl) === null || _a === void 0 ? void 0 : _a.trim().length)) {
978
1276
  this.showMessage("error", "Login url is required");
979
1277
  throw new Error("Login url is required");
980
1278
  }
981
- _c.label = 1;
1279
+ _d.label = 1;
982
1280
  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();
1281
+ _d.trys.push([1, 5, , 6]);
1282
+ if (!this.loginConfig.loginFunction) return [3 /*break*/, 3];
1283
+ console.log("Using custom login function");
1284
+ 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())];
1285
+ case 2: return [2 /*return*/, _d.sent()];
1286
+ 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 }); })];
1287
+ case 4: return [2 /*return*/, _d.sent()];
1288
+ case 5:
1289
+ e_1 = _d.sent();
989
1290
  this.showMessage("error", e_1.message);
990
1291
  return [2 /*return*/, null];
991
- case 4: return [2 /*return*/];
1292
+ case 6: return [2 /*return*/];
992
1293
  }
993
1294
  });
994
1295
  });
995
1296
  };
996
1297
  LocalizeLogindlgComponent.prototype.getHeaders = function () {
997
- var _c;
1298
+ var _d;
998
1299
  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;
1300
+ return _d = {},
1301
+ _d[LocalizeToken.httpHeaders.X_REFRESH_TOKEN] = (_a = LocalizeToken.storage.get(this.config.refreshTokenName)) !== null && _a !== void 0 ? _a : "",
1302
+ _d[LocalizeToken.httpHeaders.X_TENANT] = (_b = LocalizeToken.storage.get(this.loginConfig.tenantTokenName)) !== null && _b !== void 0 ? _b : "",
1303
+ _d;
1003
1304
  };
1004
1305
  Object.defineProperty(LocalizeLogindlgComponent.prototype, "isValidPassword", {
1005
1306
  get: function () {
1006
1307
  this.loading = false;
1007
- return this.password && this.password.trim().length >= 6 && this.password.trim().length <= 50;
1308
+ return this.properties.passwordValidator
1309
+ ? this.properties.passwordValidator(this.password)
1310
+ : this.password && this.password.trim().length >= 6 && this.password.trim().length <= 50;
1008
1311
  },
1009
1312
  enumerable: false,
1010
1313
  configurable: true
@@ -1013,15 +1316,23 @@
1013
1316
  this.messageService.add({ key: this.messageKey, severity: severity, summary: summary });
1014
1317
  this.loading = false;
1015
1318
  };
1319
+ Object.defineProperty(LocalizeLogindlgComponent.prototype, "sanitizedTitle", {
1320
+ get: function () {
1321
+ var _a;
1322
+ return this.sanitizer.bypassSecurityTrustHtml((_a = this.properties.title) !== null && _a !== void 0 ? _a : '');
1323
+ },
1324
+ enumerable: false,
1325
+ configurable: true
1326
+ });
1016
1327
  return LocalizeLogindlgComponent;
1017
1328
  }());
1018
1329
  LocalizeLogindlgComponent.decorators = [
1019
1330
  { 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>",
1331
+ 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
1332
  selector: "app-localize-logindlg",
1022
1333
  providers: [api.MessageService],
1023
1334
  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 "]
1335
+ 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
1336
  },] }
1026
1337
  ];
1027
1338
  LocalizeLogindlgComponent.ctorParameters = function () { return [
@@ -1030,7 +1341,8 @@
1030
1341
  { type: dynamicdialog.DynamicDialogRef },
1031
1342
  { type: dynamicdialog.DynamicDialogConfig },
1032
1343
  { type: LocalizeTokenService },
1033
- { type: i1.HttpClient }
1344
+ { type: i1.HttpClient },
1345
+ { type: platformBrowser.DomSanitizer }
1034
1346
  ]; };
1035
1347
 
1036
1348
  var LocalizeLogindlgService = /** @class */ (function () {
@@ -1040,15 +1352,12 @@
1040
1352
  LocalizeLogindlgService.prototype.openLoginDialog = function (loginConfig, config) {
1041
1353
  return __awaiter(this, void 0, void 0, function () {
1042
1354
  var dialogService, dialog;
1043
- return __generator(this, function (_a) {
1044
- switch (_a.label) {
1355
+ return __generator(this, function (_b) {
1356
+ switch (_b.label) {
1045
1357
  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 });
1358
+ config = this.intercepDialogConfig(config);
1359
+ this.initConfig(loginConfig);
1360
+ config.data = Object.assign(Object.assign({}, (config.data || {})), { loginConfig: loginConfig });
1052
1361
  dialogService = this.injector.get(dynamicdialog.DialogService);
1053
1362
  dialog = dialogService.open(LocalizeLogindlgComponent, config);
1054
1363
  return [4 /*yield*/, new Promise(function (resolve) { return dialog.onClose.subscribe(function (res) {
@@ -1057,12 +1366,42 @@
1057
1366
  }
1058
1367
  }); })];
1059
1368
  case 1:
1060
- _a.sent();
1369
+ _b.sent();
1061
1370
  return [2 /*return*/];
1062
1371
  }
1063
1372
  });
1064
1373
  });
1065
1374
  };
1375
+ LocalizeLogindlgService.prototype.intercepDialogConfig = function (config) {
1376
+ config !== null && config !== void 0 ? config : (config = {
1377
+ header: 'Login',
1378
+ style: { 'max-width': '400px', width: '100%', 'height': '650px' },
1379
+ modal: true,
1380
+ closable: false,
1381
+ showHeader: false,
1382
+ });
1383
+ config = Object.assign(Object.assign({}, config), {
1384
+ contentStyle: { 'height': '100%', 'border-radius': '20px' }
1385
+ });
1386
+ config.style = Object.assign(Object.assign({}, config.style), { 'border-radius': '20px' });
1387
+ return config;
1388
+ };
1389
+ LocalizeLogindlgService.prototype.initConfig = function (loginConfig) {
1390
+ var _a;
1391
+ loginConfig !== null && loginConfig !== void 0 ? loginConfig : (loginConfig = {});
1392
+ (_a = loginConfig.properties) !== null && _a !== void 0 ? _a : (loginConfig.properties = {
1393
+ title: 'Your session is expired!<br/> Please login again to continue.',
1394
+ loginSuccessMessage: 'You have successfully logged in.',
1395
+ logoImage: '/assets/images/logo-300px.png',
1396
+ username: { placeHolder: 'Username' },
1397
+ password: { placeHolder: 'Password' },
1398
+ loginButton: { placeHolder: 'Login' },
1399
+ logoutButton: {
1400
+ message: 'No, I want to login with another user.',
1401
+ placeHolder: 'Logout'
1402
+ }
1403
+ });
1404
+ };
1066
1405
  return LocalizeLogindlgService;
1067
1406
  }());
1068
1407
  LocalizeLogindlgService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function LocalizeLogindlgService_Factory() { return new LocalizeLogindlgService(i0__namespace.ɵɵinject(i0__namespace.INJECTOR)); }, token: LocalizeLogindlgService, providedIn: "root" });
@@ -1101,6 +1440,7 @@
1101
1440
  * Generated bundle index. Do not edit.
1102
1441
  */
1103
1442
 
1443
+ exports.ApiHelper = ApiHelper;
1104
1444
  exports.LocalizeApiService = LocalizeApiService;
1105
1445
  exports.LocalizeLogindlgComponent = LocalizeLogindlgComponent;
1106
1446
  exports.LocalizeLogindlgModule = LocalizeLogindlgModule;