@sambath999/localize-token 12.3.3 → 12.3.4
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.
- package/bundles/sambath999-localize-token.umd.js +72 -53
- package/bundles/sambath999-localize-token.umd.js.map +1 -1
- package/esm2015/localize-logindlg/localize-logindlg.component.js +2 -2
- package/esm2015/localize-token/helpers/loccalize.api.helper.js +2 -11
- package/esm2015/localize-token/localize.api.service.js +19 -7
- package/esm2015/localize-token/localize.token.js +1 -12
- package/esm2015/localize-token/localize.token.service.js +26 -16
- package/fesm2015/sambath999-localize-token.js +44 -42
- package/fesm2015/sambath999-localize-token.js.map +1 -1
- package/localize-logindlg/localize-logindlg.component.d.ts +1 -1
- package/localize-token/helpers/loccalize.api.helper.d.ts +0 -1
- package/localize-token/localize.api.service.d.ts +4 -3
- package/localize-token/localize.token.d.ts +0 -2
- package/localize-token/localize.token.service.d.ts +7 -2
- package/package.json +1 -1
- package/sambath999-localize-token.metadata.json +1 -1
|
@@ -482,19 +482,8 @@
|
|
|
482
482
|
var LocalizeToken = /** @class */ (function () {
|
|
483
483
|
function LocalizeToken() {
|
|
484
484
|
}
|
|
485
|
-
LocalizeToken.init = function (config) {
|
|
486
|
-
LocalizeToken.config = Object.assign(Object.assign({}, LocalizeToken.config), config);
|
|
487
|
-
};
|
|
488
485
|
return LocalizeToken;
|
|
489
486
|
}());
|
|
490
|
-
LocalizeToken.config = {
|
|
491
|
-
mainDomain: extractMainDomain(),
|
|
492
|
-
authTokenName: 'auth-token',
|
|
493
|
-
refreshTokenName: '_lze_rftkp_',
|
|
494
|
-
needTenant: false,
|
|
495
|
-
isProduction: false,
|
|
496
|
-
revokeTokenUrl: ''
|
|
497
|
-
};
|
|
498
487
|
LocalizeToken.storage = new LocalizeTokenStorage();
|
|
499
488
|
LocalizeToken.httpHeaders = {
|
|
500
489
|
AUTHORIZATION: 'Authorization',
|
|
@@ -577,12 +566,28 @@
|
|
|
577
566
|
var LocalizeTokenService = /** @class */ (function () {
|
|
578
567
|
function LocalizeTokenService() {
|
|
579
568
|
this.isRevokingTokenSubject = new rxjs.BehaviorSubject(false);
|
|
569
|
+
this.defaultConfig = {
|
|
570
|
+
mainDomain: extractMainDomain(),
|
|
571
|
+
authTokenName: 'auth-token',
|
|
572
|
+
refreshTokenName: '_lze_rftkp_',
|
|
573
|
+
};
|
|
574
|
+
this._config = Object.assign({}, this.defaultConfig);
|
|
575
|
+
this.isInitialized = false;
|
|
580
576
|
this.decodeToken = function (token) { return jwt_decode__namespace.jwtDecode(token); };
|
|
581
|
-
if (!LocalizeToken.config.authTokenName || !LocalizeToken.config.refreshTokenName) {
|
|
582
|
-
throw new Error('authTokenName and refreshTokenName must be defined in LocalizeToken.config');
|
|
583
|
-
}
|
|
584
|
-
this.config = LocalizeToken.config;
|
|
585
577
|
}
|
|
578
|
+
Object.defineProperty(LocalizeTokenService.prototype, "config", {
|
|
579
|
+
get: function () {
|
|
580
|
+
this.throwIfNotInitialized();
|
|
581
|
+
return this._config;
|
|
582
|
+
},
|
|
583
|
+
enumerable: false,
|
|
584
|
+
configurable: true
|
|
585
|
+
});
|
|
586
|
+
LocalizeTokenService.prototype.init = function (config) {
|
|
587
|
+
console.warn('LocalizeTokenService is initialized.');
|
|
588
|
+
this._config = Object.assign(Object.assign({}, this.defaultConfig), config);
|
|
589
|
+
this.isInitialized = true;
|
|
590
|
+
};
|
|
586
591
|
Object.defineProperty(LocalizeTokenService.prototype, "authToken", {
|
|
587
592
|
get: function () { return this.storageGet(); },
|
|
588
593
|
set: function (value) {
|
|
@@ -601,9 +606,7 @@
|
|
|
601
606
|
Object.defineProperty(LocalizeTokenService.prototype, "accessToken", {
|
|
602
607
|
get: function () { var _a; return (_a = this.authToken) === null || _a === void 0 ? void 0 : _a.token; },
|
|
603
608
|
set: function (value) {
|
|
604
|
-
|
|
605
|
-
this.authToken = { token: value, revoke: false };
|
|
606
|
-
}
|
|
609
|
+
value && (this.authToken = { token: value, revoke: false });
|
|
607
610
|
},
|
|
608
611
|
enumerable: false,
|
|
609
612
|
configurable: true
|
|
@@ -612,9 +615,7 @@
|
|
|
612
615
|
get: function () { return this.isRevokingTokenSubject.value; /* this.authToken?.revoke ?? false */ },
|
|
613
616
|
set: function (value) {
|
|
614
617
|
this.isRevokingTokenSubject.next(value);
|
|
615
|
-
|
|
616
|
-
this.authToken = Object.assign(Object.assign({}, this.authToken), { revoke: value });
|
|
617
|
-
}
|
|
618
|
+
this.authToken && (this.authToken = Object.assign(Object.assign({}, this.authToken), { revoke: value }));
|
|
618
619
|
},
|
|
619
620
|
enumerable: false,
|
|
620
621
|
configurable: true
|
|
@@ -646,20 +647,22 @@
|
|
|
646
647
|
Object.defineProperty(LocalizeTokenService.prototype, "decodeRefreshToken", {
|
|
647
648
|
get: function () {
|
|
648
649
|
var token = LocalizeToken.storage.get(this.config.refreshTokenName);
|
|
649
|
-
|
|
650
|
-
return null;
|
|
651
|
-
return this.decodeToken(token);
|
|
650
|
+
return !token ? null : this.decodeToken(token);
|
|
652
651
|
},
|
|
653
652
|
enumerable: false,
|
|
654
653
|
configurable: true
|
|
655
654
|
});
|
|
655
|
+
LocalizeTokenService.prototype.throwIfNotInitialized = function () {
|
|
656
|
+
if (!this.isInitialized) {
|
|
657
|
+
throw new Error('LocalizeTokenService is not initialized. Call init() method before using it.');
|
|
658
|
+
}
|
|
659
|
+
};
|
|
656
660
|
return LocalizeTokenService;
|
|
657
661
|
}());
|
|
658
662
|
LocalizeTokenService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function LocalizeTokenService_Factory() { return new LocalizeTokenService(); }, token: LocalizeTokenService, providedIn: "root" });
|
|
659
663
|
LocalizeTokenService.decorators = [
|
|
660
664
|
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
|
|
661
|
-
];
|
|
662
|
-
LocalizeTokenService.ctorParameters = function () { return []; };
|
|
665
|
+
];
|
|
663
666
|
|
|
664
667
|
/**
|
|
665
668
|
* Http method options
|
|
@@ -838,15 +841,6 @@
|
|
|
838
841
|
});
|
|
839
842
|
});
|
|
840
843
|
};
|
|
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
844
|
LocalizeApiHelper.prototype.screenBlocker = function (optons, error, add) {
|
|
851
845
|
if (add === void 0) { add = true; }
|
|
852
846
|
var _a, _b, _c, _d;
|
|
@@ -893,8 +887,7 @@
|
|
|
893
887
|
this.localizeTokenService = localizeTokenService;
|
|
894
888
|
this.destroy$ = new rxjs.Subject();
|
|
895
889
|
this.isRequestingSubject = new rxjs.BehaviorSubject(false);
|
|
896
|
-
this.
|
|
897
|
-
this.needTenant = LocalizeToken.config.needTenant;
|
|
890
|
+
this.isResolvingStartupSubject = new rxjs.BehaviorSubject(false);
|
|
898
891
|
this.config = {
|
|
899
892
|
waitEachRequest: { milliseconds: 0 },
|
|
900
893
|
enableRequestCancellation: true,
|
|
@@ -920,8 +913,13 @@
|
|
|
920
913
|
return _this.request(baseUrl, path, method, reqBody, reqHeaders);
|
|
921
914
|
}; };
|
|
922
915
|
}
|
|
923
|
-
Object.defineProperty(LocalizeApiService.prototype, "
|
|
924
|
-
get: function () { return this.
|
|
916
|
+
Object.defineProperty(LocalizeApiService.prototype, "isResolvingStartup", {
|
|
917
|
+
get: function () { return this.isResolvingStartupSubject.value; },
|
|
918
|
+
enumerable: false,
|
|
919
|
+
configurable: true
|
|
920
|
+
});
|
|
921
|
+
Object.defineProperty(LocalizeApiService.prototype, "needTenant", {
|
|
922
|
+
get: function () { return this.localizeTokenService.config.needTenant; },
|
|
925
923
|
enumerable: false,
|
|
926
924
|
configurable: true
|
|
927
925
|
});
|
|
@@ -957,8 +955,9 @@
|
|
|
957
955
|
* @param apiConfigs - The API configurations.
|
|
958
956
|
*/
|
|
959
957
|
LocalizeApiService.prototype.init = function (apiConfigs) {
|
|
958
|
+
console.warn('LocalizeApiService is initialized.');
|
|
960
959
|
this.config = Object.assign(Object.assign({}, this.config), apiConfigs);
|
|
961
|
-
|
|
960
|
+
this.validateConfig(this.config);
|
|
962
961
|
};
|
|
963
962
|
LocalizeApiService.prototype.cancelPendingRequests = function () {
|
|
964
963
|
this.config.enableRequestCancellation
|
|
@@ -973,25 +972,29 @@
|
|
|
973
972
|
if (reqBody === void 0) { reqBody = null; }
|
|
974
973
|
return __awaiter(this, void 0, void 0, function () {
|
|
975
974
|
var apiOptions, error_1;
|
|
975
|
+
var _this = this;
|
|
976
976
|
return __generator(this, function (_b) {
|
|
977
977
|
switch (_b.label) {
|
|
978
|
-
case 0: return [4 /*yield*/,
|
|
978
|
+
case 0: return [4 /*yield*/, waitUntil(function () { return !_this.isResolvingStartup; }, 500)];
|
|
979
979
|
case 1:
|
|
980
980
|
_b.sent();
|
|
981
|
-
|
|
982
|
-
_b.label = 2;
|
|
981
|
+
return [4 /*yield*/, ApiHelper.invokeHook(this.config.onPrepareRequest)];
|
|
983
982
|
case 2:
|
|
984
|
-
_b.
|
|
985
|
-
|
|
983
|
+
_b.sent();
|
|
984
|
+
apiOptions = this.buildApiOptions(baseUrl, path, method, reqBody, reqHeaders);
|
|
985
|
+
_b.label = 3;
|
|
986
986
|
case 3:
|
|
987
|
+
_b.trys.push([3, 6, , 8]);
|
|
988
|
+
return [4 /*yield*/, this.toWaitForPreviousRequest()];
|
|
989
|
+
case 4:
|
|
987
990
|
_b.sent();
|
|
988
991
|
return [4 /*yield*/, ApiHelper.performRequestWithRetry(apiOptions, this.config, this.performRequest.bind(this))];
|
|
989
|
-
case
|
|
990
|
-
case
|
|
992
|
+
case 5: return [2 /*return*/, _b.sent()];
|
|
993
|
+
case 6:
|
|
991
994
|
error_1 = _b.sent();
|
|
992
995
|
return [4 /*yield*/, this.handleOnRequestError(error_1, apiOptions)];
|
|
993
|
-
case
|
|
994
|
-
case
|
|
996
|
+
case 7: return [2 /*return*/, _b.sent()];
|
|
997
|
+
case 8: return [2 /*return*/];
|
|
995
998
|
}
|
|
996
999
|
});
|
|
997
1000
|
});
|
|
@@ -1002,8 +1005,11 @@
|
|
|
1002
1005
|
return __generator(this, function (_b) {
|
|
1003
1006
|
switch (_b.label) {
|
|
1004
1007
|
case 0:
|
|
1005
|
-
if (error.status !== 401
|
|
1008
|
+
if (error.status !== 401)
|
|
1006
1009
|
throw error;
|
|
1010
|
+
return [4 /*yield*/, waitUntil(function () { return !_this.isResolvingStartup; }, 500)];
|
|
1011
|
+
case 1:
|
|
1012
|
+
_b.sent();
|
|
1007
1013
|
return [4 /*yield*/, ApiHelper.performRetry({
|
|
1008
1014
|
maxRetries: function () { return 1000; },
|
|
1009
1015
|
delay: 500,
|
|
@@ -1025,7 +1031,7 @@
|
|
|
1025
1031
|
});
|
|
1026
1032
|
}); }
|
|
1027
1033
|
})];
|
|
1028
|
-
case
|
|
1034
|
+
case 2: return [2 /*return*/, _b.sent()];
|
|
1029
1035
|
}
|
|
1030
1036
|
});
|
|
1031
1037
|
});
|
|
@@ -1066,7 +1072,7 @@
|
|
|
1066
1072
|
if (_b.sent())
|
|
1067
1073
|
return [2 /*return*/];
|
|
1068
1074
|
this.isRevokingToken = true;
|
|
1069
|
-
apiOptions = Object.assign(Object.assign({}, this.buildApiOptions(
|
|
1075
|
+
apiOptions = Object.assign(Object.assign({}, this.buildApiOptions(this.localizeTokenService.config.revokeTokenUrl)), { refreshToken: true });
|
|
1070
1076
|
return [4 /*yield*/, ApiHelper.performRequestWithRetry(apiOptions, this.config, this.performRequest.bind(this))];
|
|
1071
1077
|
case 2:
|
|
1072
1078
|
revokeToken = _b.sent();
|
|
@@ -1184,6 +1190,15 @@
|
|
|
1184
1190
|
});
|
|
1185
1191
|
});
|
|
1186
1192
|
};
|
|
1193
|
+
LocalizeApiService.prototype.validateConfig = function (config) {
|
|
1194
|
+
var _a;
|
|
1195
|
+
if (this.localizeTokenService.config.needTenant && !((_a = config.tenantTokenName) === null || _a === void 0 ? void 0 : _a.trim().length)) {
|
|
1196
|
+
throw Error('Tenant token is required but tenantTokenName is not configured');
|
|
1197
|
+
}
|
|
1198
|
+
if (!this.localizeTokenService.config.revokeTokenUrl.trim().length) {
|
|
1199
|
+
throw Error('Revoke token URL is not configured - token refresh will not work');
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1187
1202
|
return LocalizeApiService;
|
|
1188
1203
|
}());
|
|
1189
1204
|
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" });
|
|
@@ -1224,12 +1239,16 @@
|
|
|
1224
1239
|
this.messageKey = "$login-dlg";
|
|
1225
1240
|
this.loading = false;
|
|
1226
1241
|
this.success = false;
|
|
1227
|
-
this.config = LocalizeToken.config;
|
|
1228
1242
|
this.clickLogout = function () { var _a; return (_a = _this.logout) === null || _a === void 0 ? void 0 : _a.call(_this); };
|
|
1229
1243
|
this.decodeToken = this.tokenService.decodeRefreshToken;
|
|
1230
1244
|
this.loginConfig = this.dlgConfig.data.loginConfig;
|
|
1231
1245
|
this.properties = this.loginConfig.properties;
|
|
1232
1246
|
}
|
|
1247
|
+
Object.defineProperty(LocalizeLogindlgComponent.prototype, "config", {
|
|
1248
|
+
get: function () { return this.tokenService.config; },
|
|
1249
|
+
enumerable: false,
|
|
1250
|
+
configurable: true
|
|
1251
|
+
});
|
|
1233
1252
|
LocalizeLogindlgComponent.prototype.ngOnInit = function () {
|
|
1234
1253
|
var _this = this;
|
|
1235
1254
|
this.dlgConfig.closable = false;
|