ngx-techlify-core 14.12.0-beta.7 → 14.12.0-beta.9
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/esm2020/lib/core/error-handler.service.mjs +7 -6
- package/fesm2015/ngx-techlify-core.mjs +86 -86
- package/fesm2015/ngx-techlify-core.mjs.map +1 -1
- package/fesm2020/ngx-techlify-core.mjs +83 -83
- package/fesm2020/ngx-techlify-core.mjs.map +1 -1
- package/lib/core/error-handler.service.d.ts +3 -1
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import { Injectable } from "@angular/core";
|
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
3
|
import * as i1 from "./alert.service";
|
|
4
4
|
import * as i2 from "./techlify-config.model";
|
|
5
|
+
import * as i3 from "./credentials.service";
|
|
5
6
|
/**
|
|
6
7
|
* Service used to handle errors from the request
|
|
7
8
|
*
|
|
@@ -9,9 +10,10 @@ import * as i2 from "./techlify-config.model";
|
|
|
9
10
|
* @since 20171202
|
|
10
11
|
*/
|
|
11
12
|
export class ErrorHandlerService {
|
|
12
|
-
constructor(alerter, config) {
|
|
13
|
+
constructor(alerter, config, credentialsService) {
|
|
13
14
|
this.alerter = alerter;
|
|
14
15
|
this.config = config;
|
|
16
|
+
this.credentialsService = credentialsService;
|
|
15
17
|
}
|
|
16
18
|
handleError(errorResponse, msg = '') {
|
|
17
19
|
// 1 - Create empty array to store errors
|
|
@@ -38,18 +40,17 @@ export class ErrorHandlerService {
|
|
|
38
40
|
var errMessage = errors.length ? errors[0] : msg;
|
|
39
41
|
this.alerter.addAlert("Error: " + errMessage, "warning");
|
|
40
42
|
if (errorResponse.status == 403 && this.config.isLogoutWhileApiGetsFailed) {
|
|
41
|
-
|
|
42
|
-
localStorage.clear();
|
|
43
|
+
this.credentialsService.setCredentials();
|
|
43
44
|
location.reload();
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
|
-
ErrorHandlerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: ErrorHandlerService, deps: [{ token: i1.AlertService }, { token: i2.TechlifyConfig }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
48
|
+
ErrorHandlerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: ErrorHandlerService, deps: [{ token: i1.AlertService }, { token: i2.TechlifyConfig }, { token: i3.CredentialsService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
48
49
|
ErrorHandlerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: ErrorHandlerService, providedIn: 'root' });
|
|
49
50
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: ErrorHandlerService, decorators: [{
|
|
50
51
|
type: Injectable,
|
|
51
52
|
args: [{
|
|
52
53
|
providedIn: 'root'
|
|
53
54
|
}]
|
|
54
|
-
}], ctorParameters: function () { return [{ type: i1.AlertService }, { type: i2.TechlifyConfig }]; } });
|
|
55
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
55
|
+
}], ctorParameters: function () { return [{ type: i1.AlertService }, { type: i2.TechlifyConfig }, { type: i3.CredentialsService }]; } });
|
|
56
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3ItaGFuZGxlci5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvbmd4LXRlY2hsaWZ5LWNvcmUvc3JjL2xpYi9jb3JlL2Vycm9yLWhhbmRsZXIuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sZUFBZSxDQUFDOzs7OztBQUszQzs7Ozs7R0FLRztBQUlILE1BQ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clxuXHJcbiAgICBpZiAoZXJyb3JSZXNwb25zZS5zdGF0dXMgPT0gNDAzICYmIHRoaXMuY29uZmlnLmlzTG9nb3V0V2hpbGVBcGlHZXRzRmFpbGVkKSB7XHJcbiAgICAgIHRoaXMuY3JlZGVudGlhbHNTZXJ2aWNlLnNldENyZWRlbnRpYWxzKCk7XHJcbiAgICAgIGxvY2F0aW9uLnJlbG9hZCgpO1xyXG4gICAgfVxyXG4gIH1cclxufVxyXG4iXX0=
|
|
@@ -828,6 +828,87 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.7", ngImpor
|
|
|
828
828
|
}]
|
|
829
829
|
}], ctorParameters: function () { return [{ type: i1$1.MatSnackBar }]; } });
|
|
830
830
|
|
|
831
|
+
/**
|
|
832
|
+
* Provides storage for authentication credentials.
|
|
833
|
+
* The Credentials interface should be replaced with proper implementation.
|
|
834
|
+
*/
|
|
835
|
+
class CredentialsService {
|
|
836
|
+
constructor(configService, cookieService) {
|
|
837
|
+
this.configService = configService;
|
|
838
|
+
this.cookieService = cookieService;
|
|
839
|
+
this._credentials = null;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Checks is the user is authenticated.
|
|
843
|
+
* @return True if the user is authenticated.
|
|
844
|
+
*/
|
|
845
|
+
get isAuthenticated() {
|
|
846
|
+
return (!!this.credentials || !!this.cookieService.get('auth_token'));
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Gets the user credentials.
|
|
850
|
+
* @return The user credentials or null if the user is not authenticated.
|
|
851
|
+
*/
|
|
852
|
+
get credentials() {
|
|
853
|
+
if (!this._credentials) {
|
|
854
|
+
this._credentials = JSON.parse(sessionStorage.getItem(this.configService.getCredentialsKey()) || localStorage.getItem(this.configService.getCredentialsKey()));
|
|
855
|
+
}
|
|
856
|
+
return this._credentials;
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Sets the user credentials.
|
|
860
|
+
* The credentials may be persisted across sessions by setting the `remember` parameter to true.
|
|
861
|
+
* Otherwise, the credentials are only persisted for the current session.
|
|
862
|
+
* @param credentials The user credentials.
|
|
863
|
+
* @param remember True to remember credentials across sessions.
|
|
864
|
+
*/
|
|
865
|
+
setCredentials(credentials, remember) {
|
|
866
|
+
this._credentials = credentials || null;
|
|
867
|
+
if (credentials) {
|
|
868
|
+
(remember ? localStorage : sessionStorage).setItem(this.configService.getCredentialsKey(), JSON.stringify(credentials));
|
|
869
|
+
}
|
|
870
|
+
else {
|
|
871
|
+
sessionStorage.clear();
|
|
872
|
+
localStorage.clear();
|
|
873
|
+
this.cookieService.delete('auth_token', '/', this.configService.getCookieDomain());
|
|
874
|
+
this._credentials = null;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
getAccessToken() {
|
|
878
|
+
var _a, _b, _c, _d;
|
|
879
|
+
const expiration = ((_b = (_a = this.credentials) === null || _a === void 0 ? void 0 : _a.token) === null || _b === void 0 ? void 0 : _b.expires_in) || '';
|
|
880
|
+
const token = ((_d = (_c = this.credentials) === null || _c === void 0 ? void 0 : _c.token) === null || _d === void 0 ? void 0 : _d.access_token) || '';
|
|
881
|
+
if (!token || !expiration) {
|
|
882
|
+
return null;
|
|
883
|
+
}
|
|
884
|
+
if (Date.now() > parseInt(expiration)) {
|
|
885
|
+
this.setCredentials();
|
|
886
|
+
return null;
|
|
887
|
+
}
|
|
888
|
+
return token;
|
|
889
|
+
}
|
|
890
|
+
getExpiration() {
|
|
891
|
+
var _a, _b;
|
|
892
|
+
return ((_b = (_a = this.credentials) === null || _a === void 0 ? void 0 : _a.token) === null || _b === void 0 ? void 0 : _b.expires_in) || '';
|
|
893
|
+
}
|
|
894
|
+
getRefreshToken() {
|
|
895
|
+
var _a, _b;
|
|
896
|
+
return ((_b = (_a = this.credentials) === null || _a === void 0 ? void 0 : _a.token) === null || _b === void 0 ? void 0 : _b.refresh_token) || '';
|
|
897
|
+
}
|
|
898
|
+
refresh() {
|
|
899
|
+
this._credentials = null;
|
|
900
|
+
return this;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
CredentialsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: CredentialsService, deps: [{ token: ConfigService }, { token: i2$1.CookieService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
904
|
+
CredentialsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: CredentialsService, providedIn: 'root' });
|
|
905
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: CredentialsService, decorators: [{
|
|
906
|
+
type: Injectable,
|
|
907
|
+
args: [{
|
|
908
|
+
providedIn: 'root'
|
|
909
|
+
}]
|
|
910
|
+
}], ctorParameters: function () { return [{ type: ConfigService }, { type: i2$1.CookieService }]; } });
|
|
911
|
+
|
|
831
912
|
/**
|
|
832
913
|
* Service used to handle errors from the request
|
|
833
914
|
*
|
|
@@ -835,9 +916,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.7", ngImpor
|
|
|
835
916
|
* @since 20171202
|
|
836
917
|
*/
|
|
837
918
|
class ErrorHandlerService {
|
|
838
|
-
constructor(alerter, config) {
|
|
919
|
+
constructor(alerter, config, credentialsService) {
|
|
839
920
|
this.alerter = alerter;
|
|
840
921
|
this.config = config;
|
|
922
|
+
this.credentialsService = credentialsService;
|
|
841
923
|
}
|
|
842
924
|
handleError(errorResponse, msg = '') {
|
|
843
925
|
var _a, _b, _c, _d;
|
|
@@ -865,20 +947,19 @@ class ErrorHandlerService {
|
|
|
865
947
|
var errMessage = errors.length ? errors[0] : msg;
|
|
866
948
|
this.alerter.addAlert("Error: " + errMessage, "warning");
|
|
867
949
|
if (errorResponse.status == 403 && this.config.isLogoutWhileApiGetsFailed) {
|
|
868
|
-
|
|
869
|
-
localStorage.clear();
|
|
950
|
+
this.credentialsService.setCredentials();
|
|
870
951
|
location.reload();
|
|
871
952
|
}
|
|
872
953
|
}
|
|
873
954
|
}
|
|
874
|
-
ErrorHandlerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: ErrorHandlerService, deps: [{ token: AlertService }, { token: TechlifyConfig }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
955
|
+
ErrorHandlerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: ErrorHandlerService, deps: [{ token: AlertService }, { token: TechlifyConfig }, { token: CredentialsService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
875
956
|
ErrorHandlerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: ErrorHandlerService, providedIn: 'root' });
|
|
876
957
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: ErrorHandlerService, decorators: [{
|
|
877
958
|
type: Injectable,
|
|
878
959
|
args: [{
|
|
879
960
|
providedIn: 'root'
|
|
880
961
|
}]
|
|
881
|
-
}], ctorParameters: function () { return [{ type: AlertService }, { type: TechlifyConfig }]; } });
|
|
962
|
+
}], ctorParameters: function () { return [{ type: AlertService }, { type: TechlifyConfig }, { type: CredentialsService }]; } });
|
|
882
963
|
|
|
883
964
|
const log$6 = new Logger('ErrorHandlerInterceptor');
|
|
884
965
|
/**
|
|
@@ -1102,87 +1183,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.7", ngImpor
|
|
|
1102
1183
|
}]
|
|
1103
1184
|
}], ctorParameters: function () { return [{ type: ConfigService }]; } });
|
|
1104
1185
|
|
|
1105
|
-
/**
|
|
1106
|
-
* Provides storage for authentication credentials.
|
|
1107
|
-
* The Credentials interface should be replaced with proper implementation.
|
|
1108
|
-
*/
|
|
1109
|
-
class CredentialsService {
|
|
1110
|
-
constructor(configService, cookieService) {
|
|
1111
|
-
this.configService = configService;
|
|
1112
|
-
this.cookieService = cookieService;
|
|
1113
|
-
this._credentials = null;
|
|
1114
|
-
}
|
|
1115
|
-
/**
|
|
1116
|
-
* Checks is the user is authenticated.
|
|
1117
|
-
* @return True if the user is authenticated.
|
|
1118
|
-
*/
|
|
1119
|
-
get isAuthenticated() {
|
|
1120
|
-
return (!!this.credentials || !!this.cookieService.get('auth_token'));
|
|
1121
|
-
}
|
|
1122
|
-
/**
|
|
1123
|
-
* Gets the user credentials.
|
|
1124
|
-
* @return The user credentials or null if the user is not authenticated.
|
|
1125
|
-
*/
|
|
1126
|
-
get credentials() {
|
|
1127
|
-
if (!this._credentials) {
|
|
1128
|
-
this._credentials = JSON.parse(sessionStorage.getItem(this.configService.getCredentialsKey()) || localStorage.getItem(this.configService.getCredentialsKey()));
|
|
1129
|
-
}
|
|
1130
|
-
return this._credentials;
|
|
1131
|
-
}
|
|
1132
|
-
/**
|
|
1133
|
-
* Sets the user credentials.
|
|
1134
|
-
* The credentials may be persisted across sessions by setting the `remember` parameter to true.
|
|
1135
|
-
* Otherwise, the credentials are only persisted for the current session.
|
|
1136
|
-
* @param credentials The user credentials.
|
|
1137
|
-
* @param remember True to remember credentials across sessions.
|
|
1138
|
-
*/
|
|
1139
|
-
setCredentials(credentials, remember) {
|
|
1140
|
-
this._credentials = credentials || null;
|
|
1141
|
-
if (credentials) {
|
|
1142
|
-
(remember ? localStorage : sessionStorage).setItem(this.configService.getCredentialsKey(), JSON.stringify(credentials));
|
|
1143
|
-
}
|
|
1144
|
-
else {
|
|
1145
|
-
sessionStorage.clear();
|
|
1146
|
-
localStorage.clear();
|
|
1147
|
-
this.cookieService.delete('auth_token', '/', this.configService.getCookieDomain());
|
|
1148
|
-
this._credentials = null;
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
getAccessToken() {
|
|
1152
|
-
var _a, _b, _c, _d;
|
|
1153
|
-
const expiration = ((_b = (_a = this.credentials) === null || _a === void 0 ? void 0 : _a.token) === null || _b === void 0 ? void 0 : _b.expires_in) || '';
|
|
1154
|
-
const token = ((_d = (_c = this.credentials) === null || _c === void 0 ? void 0 : _c.token) === null || _d === void 0 ? void 0 : _d.access_token) || '';
|
|
1155
|
-
if (!token || !expiration) {
|
|
1156
|
-
return null;
|
|
1157
|
-
}
|
|
1158
|
-
if (Date.now() > parseInt(expiration)) {
|
|
1159
|
-
this.setCredentials();
|
|
1160
|
-
return null;
|
|
1161
|
-
}
|
|
1162
|
-
return token;
|
|
1163
|
-
}
|
|
1164
|
-
getExpiration() {
|
|
1165
|
-
var _a, _b;
|
|
1166
|
-
return ((_b = (_a = this.credentials) === null || _a === void 0 ? void 0 : _a.token) === null || _b === void 0 ? void 0 : _b.expires_in) || '';
|
|
1167
|
-
}
|
|
1168
|
-
getRefreshToken() {
|
|
1169
|
-
var _a, _b;
|
|
1170
|
-
return ((_b = (_a = this.credentials) === null || _a === void 0 ? void 0 : _a.token) === null || _b === void 0 ? void 0 : _b.refresh_token) || '';
|
|
1171
|
-
}
|
|
1172
|
-
refresh() {
|
|
1173
|
-
this._credentials = null;
|
|
1174
|
-
return this;
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
CredentialsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: CredentialsService, deps: [{ token: ConfigService }, { token: i2$1.CookieService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1178
|
-
CredentialsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: CredentialsService, providedIn: 'root' });
|
|
1179
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.7", ngImport: i0, type: CredentialsService, decorators: [{
|
|
1180
|
-
type: Injectable,
|
|
1181
|
-
args: [{
|
|
1182
|
-
providedIn: 'root'
|
|
1183
|
-
}]
|
|
1184
|
-
}], ctorParameters: function () { return [{ type: ConfigService }, { type: i2$1.CookieService }]; } });
|
|
1185
|
-
|
|
1186
1186
|
/**
|
|
1187
1187
|
* Prefixes all requests not starting with `http[s]` with `environment.serverUrl`.
|
|
1188
1188
|
*/
|