@sambath999/localize-token 12.3.2 → 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 +80 -50
- 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 +18 -4
- package/esm2015/localize-token/localize.token.js +1 -12
- package/esm2015/localize-token/localize.token.module.js +2 -2
- package/esm2015/localize-token/localize.token.service.js +31 -16
- package/fesm2015/sambath999-localize-token.js +49 -40
- 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 -1
- package/localize-token/localize.token.d.ts +0 -2
- package/localize-token/localize.token.service.d.ts +8 -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
|
|
@@ -638,23 +639,30 @@
|
|
|
638
639
|
var base64 = btoa(JSON.stringify(value));
|
|
639
640
|
LocalizeToken.storage.set(this.config.authTokenName, base64);
|
|
640
641
|
};
|
|
642
|
+
LocalizeTokenService.prototype.tokensValid = function (tenantTokenName) {
|
|
643
|
+
var _a, _b;
|
|
644
|
+
return !!((_a = this.refreshToken) === null || _a === void 0 ? void 0 : _a.length)
|
|
645
|
+
&& (!this.config.needTenant || !!((_b = this.tenantToken(tenantTokenName)) === null || _b === void 0 ? void 0 : _b.length));
|
|
646
|
+
};
|
|
641
647
|
Object.defineProperty(LocalizeTokenService.prototype, "decodeRefreshToken", {
|
|
642
648
|
get: function () {
|
|
643
649
|
var token = LocalizeToken.storage.get(this.config.refreshTokenName);
|
|
644
|
-
|
|
645
|
-
return null;
|
|
646
|
-
return this.decodeToken(token);
|
|
650
|
+
return !token ? null : this.decodeToken(token);
|
|
647
651
|
},
|
|
648
652
|
enumerable: false,
|
|
649
653
|
configurable: true
|
|
650
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
|
+
};
|
|
651
660
|
return LocalizeTokenService;
|
|
652
661
|
}());
|
|
653
662
|
LocalizeTokenService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function LocalizeTokenService_Factory() { return new LocalizeTokenService(); }, token: LocalizeTokenService, providedIn: "root" });
|
|
654
663
|
LocalizeTokenService.decorators = [
|
|
655
664
|
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
|
|
656
|
-
];
|
|
657
|
-
LocalizeTokenService.ctorParameters = function () { return []; };
|
|
665
|
+
];
|
|
658
666
|
|
|
659
667
|
/**
|
|
660
668
|
* Http method options
|
|
@@ -833,15 +841,6 @@
|
|
|
833
841
|
});
|
|
834
842
|
});
|
|
835
843
|
};
|
|
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
844
|
LocalizeApiHelper.prototype.screenBlocker = function (optons, error, add) {
|
|
846
845
|
if (add === void 0) { add = true; }
|
|
847
846
|
var _a, _b, _c, _d;
|
|
@@ -888,7 +887,7 @@
|
|
|
888
887
|
this.localizeTokenService = localizeTokenService;
|
|
889
888
|
this.destroy$ = new rxjs.Subject();
|
|
890
889
|
this.isRequestingSubject = new rxjs.BehaviorSubject(false);
|
|
891
|
-
this.
|
|
890
|
+
this.isResolvingStartupSubject = new rxjs.BehaviorSubject(false);
|
|
892
891
|
this.config = {
|
|
893
892
|
waitEachRequest: { milliseconds: 0 },
|
|
894
893
|
enableRequestCancellation: true,
|
|
@@ -914,6 +913,16 @@
|
|
|
914
913
|
return _this.request(baseUrl, path, method, reqBody, reqHeaders);
|
|
915
914
|
}; };
|
|
916
915
|
}
|
|
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; },
|
|
923
|
+
enumerable: false,
|
|
924
|
+
configurable: true
|
|
925
|
+
});
|
|
917
926
|
Object.defineProperty(LocalizeApiService.prototype, "isRequesting", {
|
|
918
927
|
get: function () { return this.isRequestingSubject.value; },
|
|
919
928
|
enumerable: false,
|
|
@@ -946,8 +955,9 @@
|
|
|
946
955
|
* @param apiConfigs - The API configurations.
|
|
947
956
|
*/
|
|
948
957
|
LocalizeApiService.prototype.init = function (apiConfigs) {
|
|
958
|
+
console.warn('LocalizeApiService is initialized.');
|
|
949
959
|
this.config = Object.assign(Object.assign({}, this.config), apiConfigs);
|
|
950
|
-
|
|
960
|
+
this.validateConfig(this.config);
|
|
951
961
|
};
|
|
952
962
|
LocalizeApiService.prototype.cancelPendingRequests = function () {
|
|
953
963
|
this.config.enableRequestCancellation
|
|
@@ -962,25 +972,29 @@
|
|
|
962
972
|
if (reqBody === void 0) { reqBody = null; }
|
|
963
973
|
return __awaiter(this, void 0, void 0, function () {
|
|
964
974
|
var apiOptions, error_1;
|
|
975
|
+
var _this = this;
|
|
965
976
|
return __generator(this, function (_b) {
|
|
966
977
|
switch (_b.label) {
|
|
967
|
-
case 0: return [4 /*yield*/,
|
|
978
|
+
case 0: return [4 /*yield*/, waitUntil(function () { return !_this.isResolvingStartup; }, 500)];
|
|
968
979
|
case 1:
|
|
969
980
|
_b.sent();
|
|
970
|
-
|
|
971
|
-
_b.label = 2;
|
|
981
|
+
return [4 /*yield*/, ApiHelper.invokeHook(this.config.onPrepareRequest)];
|
|
972
982
|
case 2:
|
|
973
|
-
_b.
|
|
974
|
-
|
|
983
|
+
_b.sent();
|
|
984
|
+
apiOptions = this.buildApiOptions(baseUrl, path, method, reqBody, reqHeaders);
|
|
985
|
+
_b.label = 3;
|
|
975
986
|
case 3:
|
|
987
|
+
_b.trys.push([3, 6, , 8]);
|
|
988
|
+
return [4 /*yield*/, this.toWaitForPreviousRequest()];
|
|
989
|
+
case 4:
|
|
976
990
|
_b.sent();
|
|
977
991
|
return [4 /*yield*/, ApiHelper.performRequestWithRetry(apiOptions, this.config, this.performRequest.bind(this))];
|
|
978
|
-
case
|
|
979
|
-
case
|
|
992
|
+
case 5: return [2 /*return*/, _b.sent()];
|
|
993
|
+
case 6:
|
|
980
994
|
error_1 = _b.sent();
|
|
981
995
|
return [4 /*yield*/, this.handleOnRequestError(error_1, apiOptions)];
|
|
982
|
-
case
|
|
983
|
-
case
|
|
996
|
+
case 7: return [2 /*return*/, _b.sent()];
|
|
997
|
+
case 8: return [2 /*return*/];
|
|
984
998
|
}
|
|
985
999
|
});
|
|
986
1000
|
});
|
|
@@ -993,6 +1007,9 @@
|
|
|
993
1007
|
case 0:
|
|
994
1008
|
if (error.status !== 401)
|
|
995
1009
|
throw error;
|
|
1010
|
+
return [4 /*yield*/, waitUntil(function () { return !_this.isResolvingStartup; }, 500)];
|
|
1011
|
+
case 1:
|
|
1012
|
+
_b.sent();
|
|
996
1013
|
return [4 /*yield*/, ApiHelper.performRetry({
|
|
997
1014
|
maxRetries: function () { return 1000; },
|
|
998
1015
|
delay: 500,
|
|
@@ -1014,7 +1031,7 @@
|
|
|
1014
1031
|
});
|
|
1015
1032
|
}); }
|
|
1016
1033
|
})];
|
|
1017
|
-
case
|
|
1034
|
+
case 2: return [2 /*return*/, _b.sent()];
|
|
1018
1035
|
}
|
|
1019
1036
|
});
|
|
1020
1037
|
});
|
|
@@ -1055,7 +1072,7 @@
|
|
|
1055
1072
|
if (_b.sent())
|
|
1056
1073
|
return [2 /*return*/];
|
|
1057
1074
|
this.isRevokingToken = true;
|
|
1058
|
-
apiOptions = Object.assign(Object.assign({}, this.buildApiOptions(
|
|
1075
|
+
apiOptions = Object.assign(Object.assign({}, this.buildApiOptions(this.localizeTokenService.config.revokeTokenUrl)), { refreshToken: true });
|
|
1059
1076
|
return [4 /*yield*/, ApiHelper.performRequestWithRetry(apiOptions, this.config, this.performRequest.bind(this))];
|
|
1060
1077
|
case 2:
|
|
1061
1078
|
revokeToken = _b.sent();
|
|
@@ -1173,6 +1190,15 @@
|
|
|
1173
1190
|
});
|
|
1174
1191
|
});
|
|
1175
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
|
+
};
|
|
1176
1202
|
return LocalizeApiService;
|
|
1177
1203
|
}());
|
|
1178
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" });
|
|
@@ -1196,7 +1222,7 @@
|
|
|
1196
1222
|
providers: [
|
|
1197
1223
|
LocalizeTokenService,
|
|
1198
1224
|
LocalizeApiService
|
|
1199
|
-
]
|
|
1225
|
+
]
|
|
1200
1226
|
},] }
|
|
1201
1227
|
];
|
|
1202
1228
|
|
|
@@ -1213,12 +1239,16 @@
|
|
|
1213
1239
|
this.messageKey = "$login-dlg";
|
|
1214
1240
|
this.loading = false;
|
|
1215
1241
|
this.success = false;
|
|
1216
|
-
this.config = LocalizeToken.config;
|
|
1217
1242
|
this.clickLogout = function () { var _a; return (_a = _this.logout) === null || _a === void 0 ? void 0 : _a.call(_this); };
|
|
1218
1243
|
this.decodeToken = this.tokenService.decodeRefreshToken;
|
|
1219
1244
|
this.loginConfig = this.dlgConfig.data.loginConfig;
|
|
1220
1245
|
this.properties = this.loginConfig.properties;
|
|
1221
1246
|
}
|
|
1247
|
+
Object.defineProperty(LocalizeLogindlgComponent.prototype, "config", {
|
|
1248
|
+
get: function () { return this.tokenService.config; },
|
|
1249
|
+
enumerable: false,
|
|
1250
|
+
configurable: true
|
|
1251
|
+
});
|
|
1222
1252
|
LocalizeLogindlgComponent.prototype.ngOnInit = function () {
|
|
1223
1253
|
var _this = this;
|
|
1224
1254
|
this.dlgConfig.closable = false;
|