zek 17.3.86 → 17.3.92
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/esm2022/lib/models/flatten-tree.mjs +2 -0
- package/esm2022/lib/services/auth-guard.service.mjs +2 -2
- package/esm2022/lib/services/auth.service.mjs +54 -38
- package/esm2022/lib/services/web.api.mjs +16 -10
- package/esm2022/lib/utils/array-helper.mjs +43 -41
- package/fesm2022/zek.mjs +109 -86
- package/fesm2022/zek.mjs.map +1 -1
- package/lib/models/flatten-tree.d.ts +6 -0
- package/lib/services/auth.service.d.ts +14 -5
- package/lib/utils/array-helper.d.ts +3 -4
- package/package.json +1 -1
package/fesm2022/zek.mjs
CHANGED
|
@@ -97,54 +97,56 @@ class ArrayHelper {
|
|
|
97
97
|
return array;
|
|
98
98
|
return array.filter(x => x !== undefined && x !== null && x[key] === filterValue);
|
|
99
99
|
}
|
|
100
|
-
static
|
|
100
|
+
static flatten(array, indent = 0) {
|
|
101
101
|
let result = [];
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
result.
|
|
106
|
-
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
static getChildren(tree, indent = 1) {
|
|
112
|
-
let result = [];
|
|
113
|
-
if (tree.children) {
|
|
114
|
-
tree.childrenCount = tree.children.length;
|
|
115
|
-
tree.children.forEach(child => {
|
|
116
|
-
child.indent = indent;
|
|
117
|
-
result.push(child);
|
|
118
|
-
result = result.concat(this.getChildren(child, indent + 1));
|
|
119
|
-
});
|
|
102
|
+
// If the input is an array of trees, we process each one
|
|
103
|
+
if (Array.isArray(array)) {
|
|
104
|
+
for (const item of array) {
|
|
105
|
+
result = result.concat(this.flatten(item, indent));
|
|
106
|
+
}
|
|
120
107
|
}
|
|
121
108
|
else {
|
|
122
|
-
tree
|
|
109
|
+
// Add the current tree node to the result
|
|
110
|
+
const item = Object.assign({}, array);
|
|
111
|
+
item.indent = indent;
|
|
112
|
+
item.count = Array.isArray(array.children)
|
|
113
|
+
? array.children.length
|
|
114
|
+
: 0;
|
|
115
|
+
delete item.children;
|
|
116
|
+
delete item.childrenIds;
|
|
117
|
+
result.push(item);
|
|
118
|
+
// If there are children, recursively flatten them
|
|
119
|
+
if (Array.isArray(array.children)) {
|
|
120
|
+
for (const child of array.children) {
|
|
121
|
+
result = result.concat(this.flatten(child, indent + 1));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
123
124
|
}
|
|
124
|
-
delete tree.children;
|
|
125
|
-
delete tree.childrenIds;
|
|
126
|
-
//delete tree.childrenCount;
|
|
127
|
-
//delete tree.indent;
|
|
128
125
|
return result;
|
|
129
126
|
}
|
|
130
|
-
static
|
|
127
|
+
static flattenDropDownList(tree, indent = 0) {
|
|
131
128
|
let result = [];
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
result = result.concat(this.
|
|
136
|
-
}
|
|
129
|
+
// If the input is an array of trees, we process each one
|
|
130
|
+
if (Array.isArray(tree)) {
|
|
131
|
+
for (const item of tree) {
|
|
132
|
+
result = result.concat(this.flattenDropDownList(item, indent));
|
|
133
|
+
}
|
|
137
134
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
135
|
+
else {
|
|
136
|
+
// Add the current tree node to the result
|
|
137
|
+
let item = {
|
|
138
|
+
key: tree.key,
|
|
139
|
+
value: ' '.repeat(indent) + tree.value,
|
|
140
|
+
indent: indent,
|
|
141
|
+
count: Array.isArray(tree.children) ? tree.children.length : 0
|
|
142
|
+
};
|
|
143
|
+
result.push(item);
|
|
144
|
+
// If there are children, recursively flatten them
|
|
145
|
+
if (Array.isArray(tree.children)) {
|
|
146
|
+
for (const child of tree.children) {
|
|
147
|
+
result = result.concat(this.flattenDropDownList(child, indent + 1));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
148
150
|
}
|
|
149
151
|
return result;
|
|
150
152
|
}
|
|
@@ -1434,7 +1436,7 @@ class ValidationHelper {
|
|
|
1434
1436
|
class AuthService {
|
|
1435
1437
|
constructor() {
|
|
1436
1438
|
this._isInitialized = false;
|
|
1437
|
-
this.
|
|
1439
|
+
this._auth = false;
|
|
1438
1440
|
this._user = null;
|
|
1439
1441
|
}
|
|
1440
1442
|
static { this.USER_KEY = 'user'; }
|
|
@@ -1442,20 +1444,27 @@ class AuthService {
|
|
|
1442
1444
|
get user() {
|
|
1443
1445
|
if (!this._isInitialized) {
|
|
1444
1446
|
const user = StorageHelper.get(AuthService.USER_KEY);
|
|
1445
|
-
|
|
1446
|
-
user.id = ObjectHelper.isDefined(user.id) ? Convert.parseNumber(user.id) : user.id;
|
|
1447
|
-
user.expired = ObjectHelper.isDefined(user.expired) ? DateHelper.parseDate(user.expired) : user.expired;
|
|
1448
|
-
user.refreshTokenTime = ObjectHelper.isDefined(user.refreshTokenTime) ? DateHelper.parseDate(user.refreshTokenTime) : user.refreshTokenTime;
|
|
1449
|
-
if (Array.isArray(user.roles)) {
|
|
1450
|
-
user.roles = user.roles.map(function (e) { return e ? e.toUpperCase() : e; });
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
this._user = user;
|
|
1454
|
-
this._isInitialized = true;
|
|
1455
|
-
this._starRefreshTokenTimer();
|
|
1447
|
+
this._init(user);
|
|
1456
1448
|
}
|
|
1457
1449
|
return this._user;
|
|
1458
1450
|
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Inits user (parses fields and starts refresh token timer if needed)
|
|
1453
|
+
* @param user user from json or storage
|
|
1454
|
+
*/
|
|
1455
|
+
_init(user) {
|
|
1456
|
+
if (user) {
|
|
1457
|
+
//convert string to specified types
|
|
1458
|
+
user.expired = ObjectHelper.isDefined(user.expired) ? DateHelper.parseDate(user.expired) : user.expired;
|
|
1459
|
+
user.refreshTokenTime = ObjectHelper.isDefined(user.refreshTokenTime) ? DateHelper.parseDate(user.refreshTokenTime) : user.refreshTokenTime;
|
|
1460
|
+
if (Array.isArray(user.roles)) {
|
|
1461
|
+
user.roles = user.roles.map(function (e) { return e ? e.toUpperCase() : e; });
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
this._user = user;
|
|
1465
|
+
this._isInitialized = true;
|
|
1466
|
+
this._starRefreshTokenTimer();
|
|
1467
|
+
}
|
|
1459
1468
|
_starRefreshTokenTimer() {
|
|
1460
1469
|
this._stopRefreshTokenTimer();
|
|
1461
1470
|
const user = this._user;
|
|
@@ -1483,15 +1492,24 @@ class AuthService {
|
|
|
1483
1492
|
this._onRefreshTokenSubject.next();
|
|
1484
1493
|
}
|
|
1485
1494
|
}
|
|
1486
|
-
|
|
1487
|
-
const expired = this.getExpired()
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1495
|
+
get _isAuthenticated() {
|
|
1496
|
+
const expired = this.getExpired();
|
|
1497
|
+
return new Date() < expired;
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Dynamic property. gets auth user and checks expired;
|
|
1501
|
+
*/
|
|
1502
|
+
get isAuthenticated() {
|
|
1503
|
+
const newValue = this._isAuthenticated;
|
|
1504
|
+
if (this._auth !== newValue) {
|
|
1505
|
+
this._auth = newValue;
|
|
1492
1506
|
//if user is signed in and expired we need to logout (remove from localStorage)
|
|
1493
1507
|
if (!newValue) {
|
|
1494
|
-
this.logout();
|
|
1508
|
+
this.logout(); //this executes emitOnSignedIn so we don't need here execute emitOnSignedIn
|
|
1509
|
+
}
|
|
1510
|
+
else {
|
|
1511
|
+
//this line need if you already logged in and refresh page. (System will init user from storage and verify)
|
|
1512
|
+
this.emitOnSignedIn();
|
|
1495
1513
|
}
|
|
1496
1514
|
return newValue;
|
|
1497
1515
|
}
|
|
@@ -1499,7 +1517,7 @@ class AuthService {
|
|
|
1499
1517
|
}
|
|
1500
1518
|
emitOnSignedIn() {
|
|
1501
1519
|
if (this._onSignedInSubject) {
|
|
1502
|
-
this._onSignedInSubject.next(this.
|
|
1520
|
+
this._onSignedInSubject.next(this._auth);
|
|
1503
1521
|
}
|
|
1504
1522
|
}
|
|
1505
1523
|
get onSignedIn() {
|
|
@@ -1520,29 +1538,29 @@ class AuthService {
|
|
|
1520
1538
|
throw new Error("onRefreshTokenObservable is undefined");
|
|
1521
1539
|
return this._onRefreshTokenObservable;
|
|
1522
1540
|
}
|
|
1523
|
-
|
|
1541
|
+
_login(user) {
|
|
1524
1542
|
StorageHelper.set(AuthService.USER_KEY, user);
|
|
1525
|
-
this._user = null;
|
|
1526
1543
|
this._isInitialized = false; //user get method will init user
|
|
1527
|
-
this.
|
|
1544
|
+
this._init(user);
|
|
1545
|
+
this._auth = ObjectHelper.isDefined(user);
|
|
1546
|
+
this.emitOnSignedIn();
|
|
1547
|
+
}
|
|
1548
|
+
login(user) {
|
|
1549
|
+
this._login(user);
|
|
1528
1550
|
}
|
|
1529
1551
|
logout() {
|
|
1530
|
-
this.
|
|
1552
|
+
this._login(null);
|
|
1531
1553
|
}
|
|
1532
1554
|
getExpired() {
|
|
1533
|
-
|
|
1534
|
-
if (user) {
|
|
1535
|
-
return user.expired;
|
|
1536
|
-
}
|
|
1537
|
-
return null;
|
|
1538
|
-
}
|
|
1539
|
-
getRefreshTokenExpired() {
|
|
1540
|
-
const user = this.user;
|
|
1541
|
-
if (user) {
|
|
1542
|
-
return user.refreshTokenTime;
|
|
1543
|
-
}
|
|
1544
|
-
return null;
|
|
1555
|
+
return this.user?.expired ?? new Date(0); // if getExpired is null return min JS date;
|
|
1545
1556
|
}
|
|
1557
|
+
// protected getRefreshTokenExpired(): Date | null | undefined {
|
|
1558
|
+
// const user = this.user;
|
|
1559
|
+
// if (user) {
|
|
1560
|
+
// return user.refreshTokenTime;
|
|
1561
|
+
// }
|
|
1562
|
+
// return null;
|
|
1563
|
+
// }
|
|
1546
1564
|
// isInRole(allowedRoles: string[]): boolean {
|
|
1547
1565
|
// if (!allowedRoles || allowedRoles.length === 0) {
|
|
1548
1566
|
// return true;
|
|
@@ -1622,7 +1640,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.4", ngImpor
|
|
|
1622
1640
|
const zekAuthGuard = (route, state) => {
|
|
1623
1641
|
const auth = inject(AuthService);
|
|
1624
1642
|
const router = inject(Router);
|
|
1625
|
-
if (!auth.isAuthenticated
|
|
1643
|
+
if (!auth.isAuthenticated) {
|
|
1626
1644
|
router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
|
|
1627
1645
|
return false;
|
|
1628
1646
|
}
|
|
@@ -1932,7 +1950,8 @@ class WebApiClient {
|
|
|
1932
1950
|
this.baseUrl = baseUrl;
|
|
1933
1951
|
}
|
|
1934
1952
|
get(url, params) {
|
|
1935
|
-
|
|
1953
|
+
const combinedUrl = UrlHelper.combine(this.baseUrl, url);
|
|
1954
|
+
return this.http.get(combinedUrl, { headers: this.getHeaders(), params: this.toHttpParams(params) });
|
|
1936
1955
|
/*.catch(catchError(this.handleError(url)))
|
|
1937
1956
|
.do((res: Response) => {
|
|
1938
1957
|
// Handle success, maybe display notification
|
|
@@ -1945,16 +1964,20 @@ class WebApiClient {
|
|
|
1945
1964
|
*/
|
|
1946
1965
|
}
|
|
1947
1966
|
getString(url, params) {
|
|
1948
|
-
|
|
1967
|
+
const combinedUrl = UrlHelper.combine(this.baseUrl, url);
|
|
1968
|
+
return this.http.get(combinedUrl, { headers: this.getHeaders(), responseType: 'text', params: this.toHttpParams(params) });
|
|
1949
1969
|
}
|
|
1950
1970
|
getBytes(url, params) {
|
|
1951
|
-
|
|
1971
|
+
const combinedUrl = UrlHelper.combine(this.baseUrl, url);
|
|
1972
|
+
return this.http.get(combinedUrl, { headers: this.getHeaders(), responseType: 'arraybuffer', params: this.toHttpParams(params) });
|
|
1952
1973
|
}
|
|
1953
1974
|
getBlob(url, params) {
|
|
1954
|
-
|
|
1975
|
+
const combinedUrl = UrlHelper.combine(this.baseUrl, url);
|
|
1976
|
+
return this.http.get(combinedUrl, { headers: this.getHeaders(), responseType: 'blob', params: this.toHttpParams(params) });
|
|
1955
1977
|
}
|
|
1956
1978
|
postBlob(url, body) {
|
|
1957
|
-
|
|
1979
|
+
const combinedUrl = UrlHelper.combine(this.baseUrl, url);
|
|
1980
|
+
return this.http.post(combinedUrl, body, { headers: this.getHeaders(), responseType: 'blob' });
|
|
1958
1981
|
}
|
|
1959
1982
|
toHttpParams(obj) {
|
|
1960
1983
|
if (!obj)
|
|
@@ -1997,26 +2020,26 @@ class WebApiClient {
|
|
|
1997
2020
|
// return undefined;
|
|
1998
2021
|
//}
|
|
1999
2022
|
post(url, body) {
|
|
2000
|
-
return this.http.post(this.baseUrl
|
|
2023
|
+
return this.http.post(UrlHelper.combine(this.baseUrl, url), body, { headers: this.getHeaders(body) });
|
|
2001
2024
|
//.pipe(
|
|
2002
2025
|
//catchError(this.handleError(url))
|
|
2003
2026
|
//);
|
|
2004
2027
|
}
|
|
2005
2028
|
put(url, body) {
|
|
2006
|
-
return this.http.put(this.baseUrl
|
|
2029
|
+
return this.http.put(UrlHelper.combine(this.baseUrl, url), body, { headers: this.getHeaders(body) });
|
|
2007
2030
|
//.pipe(
|
|
2008
2031
|
//catchError(this.handleError(url))
|
|
2009
2032
|
//);
|
|
2010
2033
|
}
|
|
2011
2034
|
delete(url, body) {
|
|
2012
|
-
return this.http.request('delete', this.baseUrl
|
|
2035
|
+
return this.http.request('delete', UrlHelper.combine(this.baseUrl, url), { body, headers: this.getHeaders(body) });
|
|
2013
2036
|
//return this.http.delete(environment.url + url, { headers: this.getHeaders() });
|
|
2014
2037
|
//.pipe(
|
|
2015
2038
|
//catchError(this.handleError(url))
|
|
2016
2039
|
//);
|
|
2017
2040
|
}
|
|
2018
2041
|
patch(url, body) {
|
|
2019
|
-
return this.http.patch(this.baseUrl
|
|
2042
|
+
return this.http.patch(UrlHelper.combine(this.baseUrl, url), body, { headers: this.getHeaders(body) });
|
|
2020
2043
|
}
|
|
2021
2044
|
getHeaders(body) {
|
|
2022
2045
|
let httpHeaders = new HttpHeaders();
|