@lenne.tech/ng-base 14.34.0 → 14.36.0
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/base-components/components/model-table/model-table.component.d.ts +16 -4
- package/esm2020/base-components/components/model-table/model-table.component.mjs +77 -18
- package/esm2020/base-prototype/pages/profile/profile.component.mjs +4 -1
- package/esm2020/shared/classes/auth.class.mjs +2 -1
- package/esm2020/shared/services/auth.service.mjs +76 -13
- package/esm2020/shared/services/user.service.mjs +9 -7
- package/esm2020/src/factories/apollo-options.factory.mjs +45 -4
- package/fesm2015/lenne.tech-ng-base-base-components.mjs +69 -13
- package/fesm2015/lenne.tech-ng-base-base-components.mjs.map +1 -1
- package/fesm2015/lenne.tech-ng-base-base-prototype.mjs +3 -0
- package/fesm2015/lenne.tech-ng-base-base-prototype.mjs.map +1 -1
- package/fesm2015/lenne.tech-ng-base-shared.mjs +309 -246
- package/fesm2015/lenne.tech-ng-base-shared.mjs.map +1 -1
- package/fesm2015/lenne.tech-ng-base.mjs +42 -4
- package/fesm2015/lenne.tech-ng-base.mjs.map +1 -1
- package/fesm2020/lenne.tech-ng-base-base-components.mjs +69 -13
- package/fesm2020/lenne.tech-ng-base-base-components.mjs.map +1 -1
- package/fesm2020/lenne.tech-ng-base-base-prototype.mjs +3 -0
- package/fesm2020/lenne.tech-ng-base-base-prototype.mjs.map +1 -1
- package/fesm2020/lenne.tech-ng-base-shared.mjs +306 -241
- package/fesm2020/lenne.tech-ng-base-shared.mjs.map +1 -1
- package/fesm2020/lenne.tech-ng-base.mjs +44 -4
- package/fesm2020/lenne.tech-ng-base.mjs.map +1 -1
- package/package.json +1 -1
- package/shared/classes/auth.class.d.ts +1 -0
- package/shared/services/auth.service.d.ts +15 -4
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { GraphQLInputObjectType, GraphQLScalarType, GraphQLEnumType, GraphQLNonNull, GraphQLList, buildClientSchema, getIntrospectionQuery } from 'graphql';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
3
|
import { InjectionToken, Injectable, Inject } from '@angular/core';
|
|
4
|
-
import {
|
|
4
|
+
import { of, throwError, Observable, BehaviorSubject, map as map$1, filter } from 'rxjs';
|
|
5
5
|
import * as i1 from 'apollo-angular';
|
|
6
6
|
import { gql } from 'apollo-angular';
|
|
7
7
|
import { sha256 } from 'js-sha256';
|
|
8
8
|
import { map } from 'rxjs/operators';
|
|
9
|
+
import * as i1$1 from '@angular/router';
|
|
10
|
+
import { NavigationEnd } from '@angular/router';
|
|
9
11
|
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
|
|
10
12
|
import * as i2 from '@angular/common';
|
|
11
13
|
import { DOCUMENT } from '@angular/common';
|
|
12
14
|
import { __awaiter } from 'tslib';
|
|
13
|
-
import * as i1$1 from '@angular/router';
|
|
14
|
-
import { NavigationEnd } from '@angular/router';
|
|
15
15
|
import Compressor from 'compressorjs';
|
|
16
16
|
import * as i2$1 from '@angular/common/http';
|
|
17
17
|
import { HttpHeaders } from '@angular/common/http';
|
|
@@ -764,6 +764,7 @@ class GraphQLMeta {
|
|
|
764
764
|
class Auth extends Standard {
|
|
765
765
|
constructor() {
|
|
766
766
|
super(...arguments);
|
|
767
|
+
this.refreshToken = undefined;
|
|
767
768
|
this.token = undefined;
|
|
768
769
|
this.user = undefined;
|
|
769
770
|
}
|
|
@@ -826,243 +827,6 @@ function debounce(delay = 300) {
|
|
|
826
827
|
};
|
|
827
828
|
}
|
|
828
829
|
|
|
829
|
-
const BASE_MODULE_CONFIG = new InjectionToken('BASE_MODULE_CONFIG');
|
|
830
|
-
|
|
831
|
-
/**
|
|
832
|
-
* Storage service for local data storage
|
|
833
|
-
*/
|
|
834
|
-
class StorageService {
|
|
835
|
-
/**
|
|
836
|
-
* Initializations
|
|
837
|
-
*/
|
|
838
|
-
constructor(moduleConfig) {
|
|
839
|
-
this.moduleConfig = moduleConfig;
|
|
840
|
-
/**
|
|
841
|
-
* Storage
|
|
842
|
-
*/
|
|
843
|
-
this.storage = null;
|
|
844
|
-
/**
|
|
845
|
-
* Prefix for storage keys
|
|
846
|
-
*/
|
|
847
|
-
this.prefix = '';
|
|
848
|
-
// Set storage
|
|
849
|
-
const type = moduleConfig.storageType ? moduleConfig.storageType : 'local';
|
|
850
|
-
if (type === 'session') {
|
|
851
|
-
this.storage = sessionStorage;
|
|
852
|
-
}
|
|
853
|
-
else {
|
|
854
|
-
if (localStorage) {
|
|
855
|
-
this.storage = localStorage;
|
|
856
|
-
}
|
|
857
|
-
else {
|
|
858
|
-
this.storage = null;
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
// Set prefix
|
|
862
|
-
this.prefix = '';
|
|
863
|
-
if (moduleConfig.prefix) {
|
|
864
|
-
this.prefix += moduleConfig.prefix + '_';
|
|
865
|
-
}
|
|
866
|
-
if (moduleConfig.version) {
|
|
867
|
-
this.prefix += moduleConfig.version + '_';
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
/**
|
|
871
|
-
* Save itemKeys
|
|
872
|
-
*
|
|
873
|
-
* If you want to save one item, use itemKeys and value parameters like these:
|
|
874
|
-
* save('KEY_OF_THE_ITEM', ITEM)
|
|
875
|
-
*
|
|
876
|
-
* If you want to save multiple items, use itemKeys only (value parameter will be ignored):
|
|
877
|
-
* save({'KEY_OF_ITEM_1': ITEM_1, 'KEY_OF_ITEM_2': ITEM_2, ...})
|
|
878
|
-
*/
|
|
879
|
-
save(itemKeys, value) {
|
|
880
|
-
// Check local storage
|
|
881
|
-
if (!this.storage) {
|
|
882
|
-
return false;
|
|
883
|
-
}
|
|
884
|
-
// Check item keys and value
|
|
885
|
-
if (!itemKeys ||
|
|
886
|
-
(typeof itemKeys === 'object' && !Object.keys(itemKeys).length) ||
|
|
887
|
-
(typeof itemKeys === 'string' && value === undefined)) {
|
|
888
|
-
return false;
|
|
889
|
-
}
|
|
890
|
-
if (typeof itemKeys === 'object') {
|
|
891
|
-
for (const [itemKey, itemValue] of Object.entries(itemKeys)) {
|
|
892
|
-
this.storage.setItem(this.prefix + itemKey, JSON.stringify(itemValue));
|
|
893
|
-
}
|
|
894
|
-
return true;
|
|
895
|
-
}
|
|
896
|
-
this.storage.setItem(this.prefix + itemKeys, JSON.stringify(value));
|
|
897
|
-
return true;
|
|
898
|
-
}
|
|
899
|
-
/**
|
|
900
|
-
* Load items via key(s)
|
|
901
|
-
*/
|
|
902
|
-
load(itemKeys) {
|
|
903
|
-
// Check local storage
|
|
904
|
-
if (!this.storage) {
|
|
905
|
-
return;
|
|
906
|
-
}
|
|
907
|
-
// Check item keys
|
|
908
|
-
if (!itemKeys || (Array.isArray(itemKeys) && !itemKeys.length)) {
|
|
909
|
-
return null;
|
|
910
|
-
}
|
|
911
|
-
if (Array.isArray(itemKeys)) {
|
|
912
|
-
const back = {};
|
|
913
|
-
itemKeys.forEach((itemKey) => {
|
|
914
|
-
const loadedItem = this.storage.getItem(this.prefix + itemKey);
|
|
915
|
-
if (loadedItem) {
|
|
916
|
-
back[itemKey] = JSON.parse(loadedItem);
|
|
917
|
-
}
|
|
918
|
-
else {
|
|
919
|
-
back[itemKey] = null;
|
|
920
|
-
}
|
|
921
|
-
});
|
|
922
|
-
return back;
|
|
923
|
-
}
|
|
924
|
-
let value = this.storage.getItem(this.prefix + itemKeys);
|
|
925
|
-
if (value) {
|
|
926
|
-
value = JSON.parse(value);
|
|
927
|
-
}
|
|
928
|
-
return value;
|
|
929
|
-
}
|
|
930
|
-
/**
|
|
931
|
-
* Remove item from storage
|
|
932
|
-
*
|
|
933
|
-
* @param itemKeys keys or key to remove
|
|
934
|
-
*/
|
|
935
|
-
remove(itemKeys) {
|
|
936
|
-
// Check local storage
|
|
937
|
-
if (!this.storage) {
|
|
938
|
-
return false;
|
|
939
|
-
}
|
|
940
|
-
if (Array.isArray(itemKeys)) {
|
|
941
|
-
itemKeys.forEach((key) => {
|
|
942
|
-
this.storage.removeItem(this.prefix + key);
|
|
943
|
-
});
|
|
944
|
-
return true;
|
|
945
|
-
}
|
|
946
|
-
this.storage.removeItem(this.prefix + itemKeys);
|
|
947
|
-
return true;
|
|
948
|
-
}
|
|
949
|
-
/**
|
|
950
|
-
* Clear local storage
|
|
951
|
-
*/
|
|
952
|
-
reset() {
|
|
953
|
-
this.storage.clear();
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
StorageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: StorageService, deps: [{ token: BASE_MODULE_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
957
|
-
StorageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: StorageService, providedIn: 'root' });
|
|
958
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: StorageService, decorators: [{
|
|
959
|
-
type: Injectable,
|
|
960
|
-
args: [{
|
|
961
|
-
providedIn: 'root',
|
|
962
|
-
}]
|
|
963
|
-
}], ctorParameters: function () {
|
|
964
|
-
return [{ type: undefined, decorators: [{
|
|
965
|
-
type: Inject,
|
|
966
|
-
args: [BASE_MODULE_CONFIG]
|
|
967
|
-
}] }];
|
|
968
|
-
} });
|
|
969
|
-
|
|
970
|
-
class WsService {
|
|
971
|
-
reconnect() {
|
|
972
|
-
var _a;
|
|
973
|
-
(_a = this.client) === null || _a === void 0 ? void 0 : _a.restart();
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
WsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
977
|
-
WsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WsService, providedIn: 'root' });
|
|
978
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WsService, decorators: [{
|
|
979
|
-
type: Injectable,
|
|
980
|
-
args: [{
|
|
981
|
-
providedIn: 'root',
|
|
982
|
-
}]
|
|
983
|
-
}] });
|
|
984
|
-
|
|
985
|
-
/**
|
|
986
|
-
* Authentication service
|
|
987
|
-
*/
|
|
988
|
-
class AuthService {
|
|
989
|
-
/**
|
|
990
|
-
* Constructor
|
|
991
|
-
*/
|
|
992
|
-
constructor(moduleConfig, storageService, wsService) {
|
|
993
|
-
this.moduleConfig = moduleConfig;
|
|
994
|
-
this.storageService = storageService;
|
|
995
|
-
this.wsService = wsService;
|
|
996
|
-
// Subjects
|
|
997
|
-
this._currentUser = new BehaviorSubject(null);
|
|
998
|
-
this._token = new BehaviorSubject(null);
|
|
999
|
-
this.loadFromStorage();
|
|
1000
|
-
}
|
|
1001
|
-
loadFromStorage() {
|
|
1002
|
-
if (localStorage) {
|
|
1003
|
-
this.token = this.storageService.load('token');
|
|
1004
|
-
this.currentUser = this.storageService.load('currentUser');
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
/**
|
|
1008
|
-
* Logout
|
|
1009
|
-
*/
|
|
1010
|
-
logout() {
|
|
1011
|
-
this.storageService.remove(['token', 'currentUser']);
|
|
1012
|
-
this.currentUser = null;
|
|
1013
|
-
this.token = null;
|
|
1014
|
-
}
|
|
1015
|
-
// #################################################################
|
|
1016
|
-
// Current User
|
|
1017
|
-
// #################################################################
|
|
1018
|
-
get currentUser() {
|
|
1019
|
-
if (!localStorage) {
|
|
1020
|
-
return undefined;
|
|
1021
|
-
}
|
|
1022
|
-
return this._currentUser.value;
|
|
1023
|
-
}
|
|
1024
|
-
set currentUser(user) {
|
|
1025
|
-
this._currentUser.next(user);
|
|
1026
|
-
this.storageService.save('currentUser', user);
|
|
1027
|
-
}
|
|
1028
|
-
get currentUserObservable() {
|
|
1029
|
-
return this._currentUser.asObservable();
|
|
1030
|
-
}
|
|
1031
|
-
// #################################################################
|
|
1032
|
-
// Token
|
|
1033
|
-
// #################################################################
|
|
1034
|
-
get token() {
|
|
1035
|
-
if (!localStorage) {
|
|
1036
|
-
return undefined;
|
|
1037
|
-
}
|
|
1038
|
-
return this._token.value;
|
|
1039
|
-
}
|
|
1040
|
-
set token(token) {
|
|
1041
|
-
this._token.next(token);
|
|
1042
|
-
this.storageService.save('token', token);
|
|
1043
|
-
this.wsService.reconnect();
|
|
1044
|
-
}
|
|
1045
|
-
get tokenObservable() {
|
|
1046
|
-
if (!this._token.value) {
|
|
1047
|
-
this.loadFromStorage();
|
|
1048
|
-
}
|
|
1049
|
-
return this._token.asObservable();
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: AuthService, deps: [{ token: BASE_MODULE_CONFIG }, { token: StorageService }, { token: WsService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1053
|
-
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: AuthService, providedIn: 'root' });
|
|
1054
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: AuthService, decorators: [{
|
|
1055
|
-
type: Injectable,
|
|
1056
|
-
args: [{
|
|
1057
|
-
providedIn: 'root',
|
|
1058
|
-
}]
|
|
1059
|
-
}], ctorParameters: function () {
|
|
1060
|
-
return [{ type: undefined, decorators: [{
|
|
1061
|
-
type: Inject,
|
|
1062
|
-
args: [BASE_MODULE_CONFIG]
|
|
1063
|
-
}] }, { type: StorageService }, { type: WsService }];
|
|
1064
|
-
} });
|
|
1065
|
-
|
|
1066
830
|
/**
|
|
1067
831
|
* GraphQL request type enum
|
|
1068
832
|
*/
|
|
@@ -1073,6 +837,8 @@ var GraphQLRequestType;
|
|
|
1073
837
|
GraphQLRequestType["SUBSCRIPTION"] = "subscription";
|
|
1074
838
|
})(GraphQLRequestType || (GraphQLRequestType = {}));
|
|
1075
839
|
|
|
840
|
+
const BASE_MODULE_CONFIG = new InjectionToken('BASE_MODULE_CONFIG');
|
|
841
|
+
|
|
1076
842
|
/**
|
|
1077
843
|
* GraphQL meta service
|
|
1078
844
|
*
|
|
@@ -1655,6 +1421,301 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImpo
|
|
|
1655
1421
|
}] }];
|
|
1656
1422
|
} });
|
|
1657
1423
|
|
|
1424
|
+
/**
|
|
1425
|
+
* Storage service for local data storage
|
|
1426
|
+
*/
|
|
1427
|
+
class StorageService {
|
|
1428
|
+
/**
|
|
1429
|
+
* Initializations
|
|
1430
|
+
*/
|
|
1431
|
+
constructor(moduleConfig) {
|
|
1432
|
+
this.moduleConfig = moduleConfig;
|
|
1433
|
+
/**
|
|
1434
|
+
* Storage
|
|
1435
|
+
*/
|
|
1436
|
+
this.storage = null;
|
|
1437
|
+
/**
|
|
1438
|
+
* Prefix for storage keys
|
|
1439
|
+
*/
|
|
1440
|
+
this.prefix = '';
|
|
1441
|
+
// Set storage
|
|
1442
|
+
const type = moduleConfig.storageType ? moduleConfig.storageType : 'local';
|
|
1443
|
+
if (type === 'session') {
|
|
1444
|
+
this.storage = sessionStorage;
|
|
1445
|
+
}
|
|
1446
|
+
else {
|
|
1447
|
+
if (localStorage) {
|
|
1448
|
+
this.storage = localStorage;
|
|
1449
|
+
}
|
|
1450
|
+
else {
|
|
1451
|
+
this.storage = null;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
// Set prefix
|
|
1455
|
+
this.prefix = '';
|
|
1456
|
+
if (moduleConfig.prefix) {
|
|
1457
|
+
this.prefix += moduleConfig.prefix + '_';
|
|
1458
|
+
}
|
|
1459
|
+
if (moduleConfig.version) {
|
|
1460
|
+
this.prefix += moduleConfig.version + '_';
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
/**
|
|
1464
|
+
* Save itemKeys
|
|
1465
|
+
*
|
|
1466
|
+
* If you want to save one item, use itemKeys and value parameters like these:
|
|
1467
|
+
* save('KEY_OF_THE_ITEM', ITEM)
|
|
1468
|
+
*
|
|
1469
|
+
* If you want to save multiple items, use itemKeys only (value parameter will be ignored):
|
|
1470
|
+
* save({'KEY_OF_ITEM_1': ITEM_1, 'KEY_OF_ITEM_2': ITEM_2, ...})
|
|
1471
|
+
*/
|
|
1472
|
+
save(itemKeys, value) {
|
|
1473
|
+
// Check local storage
|
|
1474
|
+
if (!this.storage) {
|
|
1475
|
+
return false;
|
|
1476
|
+
}
|
|
1477
|
+
// Check item keys and value
|
|
1478
|
+
if (!itemKeys ||
|
|
1479
|
+
(typeof itemKeys === 'object' && !Object.keys(itemKeys).length) ||
|
|
1480
|
+
(typeof itemKeys === 'string' && value === undefined)) {
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
if (typeof itemKeys === 'object') {
|
|
1484
|
+
for (const [itemKey, itemValue] of Object.entries(itemKeys)) {
|
|
1485
|
+
this.storage.setItem(this.prefix + itemKey, JSON.stringify(itemValue));
|
|
1486
|
+
}
|
|
1487
|
+
return true;
|
|
1488
|
+
}
|
|
1489
|
+
this.storage.setItem(this.prefix + itemKeys, JSON.stringify(value));
|
|
1490
|
+
return true;
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* Load items via key(s)
|
|
1494
|
+
*/
|
|
1495
|
+
load(itemKeys) {
|
|
1496
|
+
// Check local storage
|
|
1497
|
+
if (!this.storage) {
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
// Check item keys
|
|
1501
|
+
if (!itemKeys || (Array.isArray(itemKeys) && !itemKeys.length)) {
|
|
1502
|
+
return null;
|
|
1503
|
+
}
|
|
1504
|
+
if (Array.isArray(itemKeys)) {
|
|
1505
|
+
const back = {};
|
|
1506
|
+
itemKeys.forEach((itemKey) => {
|
|
1507
|
+
const loadedItem = this.storage.getItem(this.prefix + itemKey);
|
|
1508
|
+
if (loadedItem) {
|
|
1509
|
+
back[itemKey] = JSON.parse(loadedItem);
|
|
1510
|
+
}
|
|
1511
|
+
else {
|
|
1512
|
+
back[itemKey] = null;
|
|
1513
|
+
}
|
|
1514
|
+
});
|
|
1515
|
+
return back;
|
|
1516
|
+
}
|
|
1517
|
+
let value = this.storage.getItem(this.prefix + itemKeys);
|
|
1518
|
+
if (value) {
|
|
1519
|
+
value = JSON.parse(value);
|
|
1520
|
+
}
|
|
1521
|
+
return value;
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Remove item from storage
|
|
1525
|
+
*
|
|
1526
|
+
* @param itemKeys keys or key to remove
|
|
1527
|
+
*/
|
|
1528
|
+
remove(itemKeys) {
|
|
1529
|
+
// Check local storage
|
|
1530
|
+
if (!this.storage) {
|
|
1531
|
+
return false;
|
|
1532
|
+
}
|
|
1533
|
+
if (Array.isArray(itemKeys)) {
|
|
1534
|
+
itemKeys.forEach((key) => {
|
|
1535
|
+
this.storage.removeItem(this.prefix + key);
|
|
1536
|
+
});
|
|
1537
|
+
return true;
|
|
1538
|
+
}
|
|
1539
|
+
this.storage.removeItem(this.prefix + itemKeys);
|
|
1540
|
+
return true;
|
|
1541
|
+
}
|
|
1542
|
+
/**
|
|
1543
|
+
* Clear local storage
|
|
1544
|
+
*/
|
|
1545
|
+
reset() {
|
|
1546
|
+
this.storage.clear();
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
StorageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: StorageService, deps: [{ token: BASE_MODULE_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1550
|
+
StorageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: StorageService, providedIn: 'root' });
|
|
1551
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: StorageService, decorators: [{
|
|
1552
|
+
type: Injectable,
|
|
1553
|
+
args: [{
|
|
1554
|
+
providedIn: 'root',
|
|
1555
|
+
}]
|
|
1556
|
+
}], ctorParameters: function () {
|
|
1557
|
+
return [{ type: undefined, decorators: [{
|
|
1558
|
+
type: Inject,
|
|
1559
|
+
args: [BASE_MODULE_CONFIG]
|
|
1560
|
+
}] }];
|
|
1561
|
+
} });
|
|
1562
|
+
|
|
1563
|
+
class WsService {
|
|
1564
|
+
reconnect() {
|
|
1565
|
+
var _a;
|
|
1566
|
+
(_a = this.client) === null || _a === void 0 ? void 0 : _a.restart();
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
WsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1570
|
+
WsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WsService, providedIn: 'root' });
|
|
1571
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WsService, decorators: [{
|
|
1572
|
+
type: Injectable,
|
|
1573
|
+
args: [{
|
|
1574
|
+
providedIn: 'root',
|
|
1575
|
+
}]
|
|
1576
|
+
}] });
|
|
1577
|
+
|
|
1578
|
+
/**
|
|
1579
|
+
* Authentication service
|
|
1580
|
+
*/
|
|
1581
|
+
class AuthService {
|
|
1582
|
+
/**
|
|
1583
|
+
* Constructor
|
|
1584
|
+
*/
|
|
1585
|
+
constructor(storageService, wsService, injector, router) {
|
|
1586
|
+
this.storageService = storageService;
|
|
1587
|
+
this.wsService = wsService;
|
|
1588
|
+
this.injector = injector;
|
|
1589
|
+
this.router = router;
|
|
1590
|
+
// Subjects
|
|
1591
|
+
this._currentUser = new BehaviorSubject(null);
|
|
1592
|
+
this._token = new BehaviorSubject(null);
|
|
1593
|
+
this._refreshToken = new BehaviorSubject(null);
|
|
1594
|
+
this.loadFromStorage();
|
|
1595
|
+
}
|
|
1596
|
+
requestNewToken() {
|
|
1597
|
+
return new Observable((subscriber) => {
|
|
1598
|
+
this.injector
|
|
1599
|
+
.get(GraphQLService)
|
|
1600
|
+
.graphQl('refreshToken', {
|
|
1601
|
+
fields: ['token', 'refreshToken'],
|
|
1602
|
+
})
|
|
1603
|
+
.subscribe({
|
|
1604
|
+
next: (response) => {
|
|
1605
|
+
this.token = response.token;
|
|
1606
|
+
this.refreshToken = response.refreshToken;
|
|
1607
|
+
subscriber.next(response);
|
|
1608
|
+
subscriber.complete();
|
|
1609
|
+
},
|
|
1610
|
+
error: (err) => {
|
|
1611
|
+
subscriber.error(err);
|
|
1612
|
+
},
|
|
1613
|
+
});
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
loadFromStorage() {
|
|
1617
|
+
if (localStorage) {
|
|
1618
|
+
this.token = this.storageService.load('token');
|
|
1619
|
+
this.refreshToken = this.storageService.load('refreshToken');
|
|
1620
|
+
this.currentUser = this.storageService.load('currentUser');
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
/**
|
|
1624
|
+
* Logout
|
|
1625
|
+
*/
|
|
1626
|
+
logout(redirect = true) {
|
|
1627
|
+
return new Observable((subscriber) => {
|
|
1628
|
+
this.injector
|
|
1629
|
+
.get(GraphQLService)
|
|
1630
|
+
.graphQl('logout', {
|
|
1631
|
+
fields: [],
|
|
1632
|
+
})
|
|
1633
|
+
.subscribe({
|
|
1634
|
+
next: () => {
|
|
1635
|
+
this.clearSession(redirect);
|
|
1636
|
+
subscriber.next(true);
|
|
1637
|
+
subscriber.complete();
|
|
1638
|
+
},
|
|
1639
|
+
error: (err) => {
|
|
1640
|
+
subscriber.error(err);
|
|
1641
|
+
},
|
|
1642
|
+
});
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1645
|
+
clearSession(redirect = true) {
|
|
1646
|
+
this.storageService.remove(['token', 'refreshToken', 'currentUser']);
|
|
1647
|
+
this.currentUser = null;
|
|
1648
|
+
this.token = null;
|
|
1649
|
+
this.refreshToken = null;
|
|
1650
|
+
if (redirect) {
|
|
1651
|
+
this.router.navigate(['/auth']);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
// #################################################################
|
|
1655
|
+
// Current User
|
|
1656
|
+
// #################################################################
|
|
1657
|
+
get currentUser() {
|
|
1658
|
+
if (!localStorage) {
|
|
1659
|
+
return undefined;
|
|
1660
|
+
}
|
|
1661
|
+
return this._currentUser.value;
|
|
1662
|
+
}
|
|
1663
|
+
set currentUser(user) {
|
|
1664
|
+
this._currentUser.next(user);
|
|
1665
|
+
this.storageService.save('currentUser', user);
|
|
1666
|
+
}
|
|
1667
|
+
get currentUserObservable() {
|
|
1668
|
+
return this._currentUser.asObservable();
|
|
1669
|
+
}
|
|
1670
|
+
// #################################################################
|
|
1671
|
+
// Token
|
|
1672
|
+
// #################################################################
|
|
1673
|
+
get token() {
|
|
1674
|
+
if (!localStorage) {
|
|
1675
|
+
return undefined;
|
|
1676
|
+
}
|
|
1677
|
+
return this._token.value;
|
|
1678
|
+
}
|
|
1679
|
+
set token(token) {
|
|
1680
|
+
this._token.next(token);
|
|
1681
|
+
this.storageService.save('token', token);
|
|
1682
|
+
this.wsService.reconnect();
|
|
1683
|
+
}
|
|
1684
|
+
get tokenObservable() {
|
|
1685
|
+
if (!this._token.value) {
|
|
1686
|
+
this.loadFromStorage();
|
|
1687
|
+
}
|
|
1688
|
+
return this._token.asObservable();
|
|
1689
|
+
}
|
|
1690
|
+
// #################################################################
|
|
1691
|
+
// refreshToken
|
|
1692
|
+
// #################################################################
|
|
1693
|
+
get refreshToken() {
|
|
1694
|
+
if (!localStorage) {
|
|
1695
|
+
return undefined;
|
|
1696
|
+
}
|
|
1697
|
+
return this._refreshToken.value;
|
|
1698
|
+
}
|
|
1699
|
+
set refreshToken(refreshToken) {
|
|
1700
|
+
this._refreshToken.next(refreshToken);
|
|
1701
|
+
this.storageService.save('refreshToken', refreshToken);
|
|
1702
|
+
}
|
|
1703
|
+
get refreshTokenObservable() {
|
|
1704
|
+
if (!this._refreshToken.value) {
|
|
1705
|
+
this.loadFromStorage();
|
|
1706
|
+
}
|
|
1707
|
+
return this._refreshToken.asObservable();
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
AuthService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: AuthService, deps: [{ token: StorageService }, { token: WsService }, { token: i0.Injector }, { token: i1$1.Router }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1711
|
+
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: AuthService, providedIn: 'root' });
|
|
1712
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: AuthService, decorators: [{
|
|
1713
|
+
type: Injectable,
|
|
1714
|
+
args: [{
|
|
1715
|
+
providedIn: 'root',
|
|
1716
|
+
}]
|
|
1717
|
+
}], ctorParameters: function () { return [{ type: StorageService }, { type: WsService }, { type: i0.Injector }, { type: i1$1.Router }]; } });
|
|
1718
|
+
|
|
1658
1719
|
/**
|
|
1659
1720
|
* Loader service for loading indication
|
|
1660
1721
|
*/
|
|
@@ -2148,15 +2209,16 @@ class UserService extends GraphQLPlusService {
|
|
|
2148
2209
|
*/
|
|
2149
2210
|
login(input) {
|
|
2150
2211
|
return this.graphQl('signIn', {
|
|
2151
|
-
arguments: { input },
|
|
2152
|
-
fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
|
|
2153
|
-
type: GraphQLRequestType.QUERY,
|
|
2212
|
+
arguments: { input: Object.assign(Object.assign({}, input), { deviceDescription: navigator === null || navigator === void 0 ? void 0 : navigator.userAgent }) },
|
|
2213
|
+
fields: ['refreshToken', 'token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
|
|
2154
2214
|
loading: true,
|
|
2155
2215
|
}).pipe(map$1((response) => {
|
|
2156
2216
|
this.authService.token = response.token;
|
|
2217
|
+
this.authService.refreshToken = response.refreshToken;
|
|
2157
2218
|
this.authService.currentUser = response.user;
|
|
2158
2219
|
return Auth.map({
|
|
2159
2220
|
token: response.token,
|
|
2221
|
+
refreshToken: response.refreshToken,
|
|
2160
2222
|
user: BasicUser.map(response.user),
|
|
2161
2223
|
});
|
|
2162
2224
|
}));
|
|
@@ -2168,15 +2230,16 @@ class UserService extends GraphQLPlusService {
|
|
|
2168
2230
|
*/
|
|
2169
2231
|
register(input) {
|
|
2170
2232
|
return this.graphQl('signUp', {
|
|
2171
|
-
arguments: { input },
|
|
2172
|
-
fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
|
|
2173
|
-
type: GraphQLRequestType.MUTATION,
|
|
2233
|
+
arguments: { input: Object.assign(Object.assign({}, input), { deviceDescription: navigator === null || navigator === void 0 ? void 0 : navigator.userAgent }) },
|
|
2234
|
+
fields: ['refreshToken', 'token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
|
|
2174
2235
|
loading: true,
|
|
2175
2236
|
}).pipe(map$1((response) => {
|
|
2176
2237
|
this.authService.token = response.token;
|
|
2238
|
+
this.authService.refreshToken = response.refreshToken;
|
|
2177
2239
|
this.authService.currentUser = response.user;
|
|
2178
2240
|
return Auth.map({
|
|
2179
2241
|
token: response.token,
|
|
2242
|
+
refreshToken: response.refreshToken,
|
|
2180
2243
|
user: BasicUser.map(response.user),
|
|
2181
2244
|
});
|
|
2182
2245
|
}));
|