@lenne.tech/ng-base 14.33.0 → 14.35.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/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-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-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 +3 -3
- package/shared/classes/auth.class.d.ts +1 -0
- package/shared/services/auth.service.d.ts +15 -4
|
@@ -1,16 +1,16 @@
|
|
|
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
|
-
import * as i1$1 from '@angular/router';
|
|
13
|
-
import { NavigationEnd } from '@angular/router';
|
|
14
14
|
import Compressor from 'compressorjs';
|
|
15
15
|
import * as i2$1 from '@angular/common/http';
|
|
16
16
|
import { HttpHeaders } from '@angular/common/http';
|
|
@@ -781,6 +781,7 @@ class GraphQLMeta {
|
|
|
781
781
|
class Auth extends Standard {
|
|
782
782
|
constructor() {
|
|
783
783
|
super(...arguments);
|
|
784
|
+
this.refreshToken = undefined;
|
|
784
785
|
this.token = undefined;
|
|
785
786
|
this.user = undefined;
|
|
786
787
|
}
|
|
@@ -843,238 +844,6 @@ function debounce(delay = 300) {
|
|
|
843
844
|
};
|
|
844
845
|
}
|
|
845
846
|
|
|
846
|
-
const BASE_MODULE_CONFIG = new InjectionToken('BASE_MODULE_CONFIG');
|
|
847
|
-
|
|
848
|
-
/**
|
|
849
|
-
* Storage service for local data storage
|
|
850
|
-
*/
|
|
851
|
-
class StorageService {
|
|
852
|
-
/**
|
|
853
|
-
* Initializations
|
|
854
|
-
*/
|
|
855
|
-
constructor(moduleConfig) {
|
|
856
|
-
this.moduleConfig = moduleConfig;
|
|
857
|
-
/**
|
|
858
|
-
* Storage
|
|
859
|
-
*/
|
|
860
|
-
this.storage = null;
|
|
861
|
-
/**
|
|
862
|
-
* Prefix for storage keys
|
|
863
|
-
*/
|
|
864
|
-
this.prefix = '';
|
|
865
|
-
// Set storage
|
|
866
|
-
const type = moduleConfig.storageType ? moduleConfig.storageType : 'local';
|
|
867
|
-
if (type === 'session') {
|
|
868
|
-
this.storage = sessionStorage;
|
|
869
|
-
}
|
|
870
|
-
else {
|
|
871
|
-
if (localStorage) {
|
|
872
|
-
this.storage = localStorage;
|
|
873
|
-
}
|
|
874
|
-
else {
|
|
875
|
-
this.storage = null;
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
// Set prefix
|
|
879
|
-
this.prefix = '';
|
|
880
|
-
if (moduleConfig.prefix) {
|
|
881
|
-
this.prefix += moduleConfig.prefix + '_';
|
|
882
|
-
}
|
|
883
|
-
if (moduleConfig.version) {
|
|
884
|
-
this.prefix += moduleConfig.version + '_';
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
/**
|
|
888
|
-
* Save itemKeys
|
|
889
|
-
*
|
|
890
|
-
* If you want to save one item, use itemKeys and value parameters like these:
|
|
891
|
-
* save('KEY_OF_THE_ITEM', ITEM)
|
|
892
|
-
*
|
|
893
|
-
* If you want to save multiple items, use itemKeys only (value parameter will be ignored):
|
|
894
|
-
* save({'KEY_OF_ITEM_1': ITEM_1, 'KEY_OF_ITEM_2': ITEM_2, ...})
|
|
895
|
-
*/
|
|
896
|
-
save(itemKeys, value) {
|
|
897
|
-
// Check local storage
|
|
898
|
-
if (!this.storage) {
|
|
899
|
-
return false;
|
|
900
|
-
}
|
|
901
|
-
// Check item keys and value
|
|
902
|
-
if (!itemKeys ||
|
|
903
|
-
(typeof itemKeys === 'object' && !Object.keys(itemKeys).length) ||
|
|
904
|
-
(typeof itemKeys === 'string' && value === undefined)) {
|
|
905
|
-
return false;
|
|
906
|
-
}
|
|
907
|
-
if (typeof itemKeys === 'object') {
|
|
908
|
-
for (const [itemKey, itemValue] of Object.entries(itemKeys)) {
|
|
909
|
-
this.storage.setItem(this.prefix + itemKey, JSON.stringify(itemValue));
|
|
910
|
-
}
|
|
911
|
-
return true;
|
|
912
|
-
}
|
|
913
|
-
this.storage.setItem(this.prefix + itemKeys, JSON.stringify(value));
|
|
914
|
-
return true;
|
|
915
|
-
}
|
|
916
|
-
/**
|
|
917
|
-
* Load items via key(s)
|
|
918
|
-
*/
|
|
919
|
-
load(itemKeys) {
|
|
920
|
-
// Check local storage
|
|
921
|
-
if (!this.storage) {
|
|
922
|
-
return;
|
|
923
|
-
}
|
|
924
|
-
// Check item keys
|
|
925
|
-
if (!itemKeys || (Array.isArray(itemKeys) && !itemKeys.length)) {
|
|
926
|
-
return null;
|
|
927
|
-
}
|
|
928
|
-
if (Array.isArray(itemKeys)) {
|
|
929
|
-
const back = {};
|
|
930
|
-
itemKeys.forEach((itemKey) => {
|
|
931
|
-
const loadedItem = this.storage.getItem(this.prefix + itemKey);
|
|
932
|
-
if (loadedItem) {
|
|
933
|
-
back[itemKey] = JSON.parse(loadedItem);
|
|
934
|
-
}
|
|
935
|
-
else {
|
|
936
|
-
back[itemKey] = null;
|
|
937
|
-
}
|
|
938
|
-
});
|
|
939
|
-
return back;
|
|
940
|
-
}
|
|
941
|
-
let value = this.storage.getItem(this.prefix + itemKeys);
|
|
942
|
-
if (value) {
|
|
943
|
-
value = JSON.parse(value);
|
|
944
|
-
}
|
|
945
|
-
return value;
|
|
946
|
-
}
|
|
947
|
-
/**
|
|
948
|
-
* Remove item from storage
|
|
949
|
-
*
|
|
950
|
-
* @param itemKeys keys or key to remove
|
|
951
|
-
*/
|
|
952
|
-
remove(itemKeys) {
|
|
953
|
-
// Check local storage
|
|
954
|
-
if (!this.storage) {
|
|
955
|
-
return false;
|
|
956
|
-
}
|
|
957
|
-
if (Array.isArray(itemKeys)) {
|
|
958
|
-
itemKeys.forEach((key) => {
|
|
959
|
-
this.storage.removeItem(this.prefix + key);
|
|
960
|
-
});
|
|
961
|
-
return true;
|
|
962
|
-
}
|
|
963
|
-
this.storage.removeItem(this.prefix + itemKeys);
|
|
964
|
-
return true;
|
|
965
|
-
}
|
|
966
|
-
/**
|
|
967
|
-
* Clear local storage
|
|
968
|
-
*/
|
|
969
|
-
reset() {
|
|
970
|
-
this.storage.clear();
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
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 });
|
|
974
|
-
StorageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: StorageService, providedIn: 'root' });
|
|
975
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: StorageService, decorators: [{
|
|
976
|
-
type: Injectable,
|
|
977
|
-
args: [{
|
|
978
|
-
providedIn: 'root',
|
|
979
|
-
}]
|
|
980
|
-
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
981
|
-
type: Inject,
|
|
982
|
-
args: [BASE_MODULE_CONFIG]
|
|
983
|
-
}] }]; } });
|
|
984
|
-
|
|
985
|
-
class WsService {
|
|
986
|
-
reconnect() {
|
|
987
|
-
this.client?.restart();
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
WsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
991
|
-
WsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WsService, providedIn: 'root' });
|
|
992
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WsService, decorators: [{
|
|
993
|
-
type: Injectable,
|
|
994
|
-
args: [{
|
|
995
|
-
providedIn: 'root',
|
|
996
|
-
}]
|
|
997
|
-
}] });
|
|
998
|
-
|
|
999
|
-
/**
|
|
1000
|
-
* Authentication service
|
|
1001
|
-
*/
|
|
1002
|
-
class AuthService {
|
|
1003
|
-
/**
|
|
1004
|
-
* Constructor
|
|
1005
|
-
*/
|
|
1006
|
-
constructor(moduleConfig, storageService, wsService) {
|
|
1007
|
-
this.moduleConfig = moduleConfig;
|
|
1008
|
-
this.storageService = storageService;
|
|
1009
|
-
this.wsService = wsService;
|
|
1010
|
-
// Subjects
|
|
1011
|
-
this._currentUser = new BehaviorSubject(null);
|
|
1012
|
-
this._token = new BehaviorSubject(null);
|
|
1013
|
-
this.loadFromStorage();
|
|
1014
|
-
}
|
|
1015
|
-
loadFromStorage() {
|
|
1016
|
-
if (localStorage) {
|
|
1017
|
-
this.token = this.storageService.load('token');
|
|
1018
|
-
this.currentUser = this.storageService.load('currentUser');
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
/**
|
|
1022
|
-
* Logout
|
|
1023
|
-
*/
|
|
1024
|
-
logout() {
|
|
1025
|
-
this.storageService.remove(['token', 'currentUser']);
|
|
1026
|
-
this.currentUser = null;
|
|
1027
|
-
this.token = null;
|
|
1028
|
-
}
|
|
1029
|
-
// #################################################################
|
|
1030
|
-
// Current User
|
|
1031
|
-
// #################################################################
|
|
1032
|
-
get currentUser() {
|
|
1033
|
-
if (!localStorage) {
|
|
1034
|
-
return undefined;
|
|
1035
|
-
}
|
|
1036
|
-
return this._currentUser.value;
|
|
1037
|
-
}
|
|
1038
|
-
set currentUser(user) {
|
|
1039
|
-
this._currentUser.next(user);
|
|
1040
|
-
this.storageService.save('currentUser', user);
|
|
1041
|
-
}
|
|
1042
|
-
get currentUserObservable() {
|
|
1043
|
-
return this._currentUser.asObservable();
|
|
1044
|
-
}
|
|
1045
|
-
// #################################################################
|
|
1046
|
-
// Token
|
|
1047
|
-
// #################################################################
|
|
1048
|
-
get token() {
|
|
1049
|
-
if (!localStorage) {
|
|
1050
|
-
return undefined;
|
|
1051
|
-
}
|
|
1052
|
-
return this._token.value;
|
|
1053
|
-
}
|
|
1054
|
-
set token(token) {
|
|
1055
|
-
this._token.next(token);
|
|
1056
|
-
this.storageService.save('token', token);
|
|
1057
|
-
this.wsService.reconnect();
|
|
1058
|
-
}
|
|
1059
|
-
get tokenObservable() {
|
|
1060
|
-
if (!this._token.value) {
|
|
1061
|
-
this.loadFromStorage();
|
|
1062
|
-
}
|
|
1063
|
-
return this._token.asObservable();
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
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 });
|
|
1067
|
-
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: AuthService, providedIn: 'root' });
|
|
1068
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: AuthService, decorators: [{
|
|
1069
|
-
type: Injectable,
|
|
1070
|
-
args: [{
|
|
1071
|
-
providedIn: 'root',
|
|
1072
|
-
}]
|
|
1073
|
-
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1074
|
-
type: Inject,
|
|
1075
|
-
args: [BASE_MODULE_CONFIG]
|
|
1076
|
-
}] }, { type: StorageService }, { type: WsService }]; } });
|
|
1077
|
-
|
|
1078
847
|
/**
|
|
1079
848
|
* GraphQL request type enum
|
|
1080
849
|
*/
|
|
@@ -1085,6 +854,8 @@ var GraphQLRequestType;
|
|
|
1085
854
|
GraphQLRequestType["SUBSCRIPTION"] = "subscription";
|
|
1086
855
|
})(GraphQLRequestType || (GraphQLRequestType = {}));
|
|
1087
856
|
|
|
857
|
+
const BASE_MODULE_CONFIG = new InjectionToken('BASE_MODULE_CONFIG');
|
|
858
|
+
|
|
1088
859
|
/**
|
|
1089
860
|
* GraphQL meta service
|
|
1090
861
|
*
|
|
@@ -1695,6 +1466,298 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImpo
|
|
|
1695
1466
|
args: [BASE_MODULE_CONFIG]
|
|
1696
1467
|
}] }]; } });
|
|
1697
1468
|
|
|
1469
|
+
/**
|
|
1470
|
+
* Storage service for local data storage
|
|
1471
|
+
*/
|
|
1472
|
+
class StorageService {
|
|
1473
|
+
/**
|
|
1474
|
+
* Initializations
|
|
1475
|
+
*/
|
|
1476
|
+
constructor(moduleConfig) {
|
|
1477
|
+
this.moduleConfig = moduleConfig;
|
|
1478
|
+
/**
|
|
1479
|
+
* Storage
|
|
1480
|
+
*/
|
|
1481
|
+
this.storage = null;
|
|
1482
|
+
/**
|
|
1483
|
+
* Prefix for storage keys
|
|
1484
|
+
*/
|
|
1485
|
+
this.prefix = '';
|
|
1486
|
+
// Set storage
|
|
1487
|
+
const type = moduleConfig.storageType ? moduleConfig.storageType : 'local';
|
|
1488
|
+
if (type === 'session') {
|
|
1489
|
+
this.storage = sessionStorage;
|
|
1490
|
+
}
|
|
1491
|
+
else {
|
|
1492
|
+
if (localStorage) {
|
|
1493
|
+
this.storage = localStorage;
|
|
1494
|
+
}
|
|
1495
|
+
else {
|
|
1496
|
+
this.storage = null;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
// Set prefix
|
|
1500
|
+
this.prefix = '';
|
|
1501
|
+
if (moduleConfig.prefix) {
|
|
1502
|
+
this.prefix += moduleConfig.prefix + '_';
|
|
1503
|
+
}
|
|
1504
|
+
if (moduleConfig.version) {
|
|
1505
|
+
this.prefix += moduleConfig.version + '_';
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
/**
|
|
1509
|
+
* Save itemKeys
|
|
1510
|
+
*
|
|
1511
|
+
* If you want to save one item, use itemKeys and value parameters like these:
|
|
1512
|
+
* save('KEY_OF_THE_ITEM', ITEM)
|
|
1513
|
+
*
|
|
1514
|
+
* If you want to save multiple items, use itemKeys only (value parameter will be ignored):
|
|
1515
|
+
* save({'KEY_OF_ITEM_1': ITEM_1, 'KEY_OF_ITEM_2': ITEM_2, ...})
|
|
1516
|
+
*/
|
|
1517
|
+
save(itemKeys, value) {
|
|
1518
|
+
// Check local storage
|
|
1519
|
+
if (!this.storage) {
|
|
1520
|
+
return false;
|
|
1521
|
+
}
|
|
1522
|
+
// Check item keys and value
|
|
1523
|
+
if (!itemKeys ||
|
|
1524
|
+
(typeof itemKeys === 'object' && !Object.keys(itemKeys).length) ||
|
|
1525
|
+
(typeof itemKeys === 'string' && value === undefined)) {
|
|
1526
|
+
return false;
|
|
1527
|
+
}
|
|
1528
|
+
if (typeof itemKeys === 'object') {
|
|
1529
|
+
for (const [itemKey, itemValue] of Object.entries(itemKeys)) {
|
|
1530
|
+
this.storage.setItem(this.prefix + itemKey, JSON.stringify(itemValue));
|
|
1531
|
+
}
|
|
1532
|
+
return true;
|
|
1533
|
+
}
|
|
1534
|
+
this.storage.setItem(this.prefix + itemKeys, JSON.stringify(value));
|
|
1535
|
+
return true;
|
|
1536
|
+
}
|
|
1537
|
+
/**
|
|
1538
|
+
* Load items via key(s)
|
|
1539
|
+
*/
|
|
1540
|
+
load(itemKeys) {
|
|
1541
|
+
// Check local storage
|
|
1542
|
+
if (!this.storage) {
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1545
|
+
// Check item keys
|
|
1546
|
+
if (!itemKeys || (Array.isArray(itemKeys) && !itemKeys.length)) {
|
|
1547
|
+
return null;
|
|
1548
|
+
}
|
|
1549
|
+
if (Array.isArray(itemKeys)) {
|
|
1550
|
+
const back = {};
|
|
1551
|
+
itemKeys.forEach((itemKey) => {
|
|
1552
|
+
const loadedItem = this.storage.getItem(this.prefix + itemKey);
|
|
1553
|
+
if (loadedItem) {
|
|
1554
|
+
back[itemKey] = JSON.parse(loadedItem);
|
|
1555
|
+
}
|
|
1556
|
+
else {
|
|
1557
|
+
back[itemKey] = null;
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1560
|
+
return back;
|
|
1561
|
+
}
|
|
1562
|
+
let value = this.storage.getItem(this.prefix + itemKeys);
|
|
1563
|
+
if (value) {
|
|
1564
|
+
value = JSON.parse(value);
|
|
1565
|
+
}
|
|
1566
|
+
return value;
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* Remove item from storage
|
|
1570
|
+
*
|
|
1571
|
+
* @param itemKeys keys or key to remove
|
|
1572
|
+
*/
|
|
1573
|
+
remove(itemKeys) {
|
|
1574
|
+
// Check local storage
|
|
1575
|
+
if (!this.storage) {
|
|
1576
|
+
return false;
|
|
1577
|
+
}
|
|
1578
|
+
if (Array.isArray(itemKeys)) {
|
|
1579
|
+
itemKeys.forEach((key) => {
|
|
1580
|
+
this.storage.removeItem(this.prefix + key);
|
|
1581
|
+
});
|
|
1582
|
+
return true;
|
|
1583
|
+
}
|
|
1584
|
+
this.storage.removeItem(this.prefix + itemKeys);
|
|
1585
|
+
return true;
|
|
1586
|
+
}
|
|
1587
|
+
/**
|
|
1588
|
+
* Clear local storage
|
|
1589
|
+
*/
|
|
1590
|
+
reset() {
|
|
1591
|
+
this.storage.clear();
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
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 });
|
|
1595
|
+
StorageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: StorageService, providedIn: 'root' });
|
|
1596
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: StorageService, decorators: [{
|
|
1597
|
+
type: Injectable,
|
|
1598
|
+
args: [{
|
|
1599
|
+
providedIn: 'root',
|
|
1600
|
+
}]
|
|
1601
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1602
|
+
type: Inject,
|
|
1603
|
+
args: [BASE_MODULE_CONFIG]
|
|
1604
|
+
}] }]; } });
|
|
1605
|
+
|
|
1606
|
+
class WsService {
|
|
1607
|
+
reconnect() {
|
|
1608
|
+
this.client?.restart();
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
WsService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1612
|
+
WsService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WsService, providedIn: 'root' });
|
|
1613
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: WsService, decorators: [{
|
|
1614
|
+
type: Injectable,
|
|
1615
|
+
args: [{
|
|
1616
|
+
providedIn: 'root',
|
|
1617
|
+
}]
|
|
1618
|
+
}] });
|
|
1619
|
+
|
|
1620
|
+
/**
|
|
1621
|
+
* Authentication service
|
|
1622
|
+
*/
|
|
1623
|
+
class AuthService {
|
|
1624
|
+
/**
|
|
1625
|
+
* Constructor
|
|
1626
|
+
*/
|
|
1627
|
+
constructor(storageService, wsService, injector, router) {
|
|
1628
|
+
this.storageService = storageService;
|
|
1629
|
+
this.wsService = wsService;
|
|
1630
|
+
this.injector = injector;
|
|
1631
|
+
this.router = router;
|
|
1632
|
+
// Subjects
|
|
1633
|
+
this._currentUser = new BehaviorSubject(null);
|
|
1634
|
+
this._token = new BehaviorSubject(null);
|
|
1635
|
+
this._refreshToken = new BehaviorSubject(null);
|
|
1636
|
+
this.loadFromStorage();
|
|
1637
|
+
}
|
|
1638
|
+
requestNewToken() {
|
|
1639
|
+
return new Observable((subscriber) => {
|
|
1640
|
+
this.injector
|
|
1641
|
+
.get(GraphQLService)
|
|
1642
|
+
.graphQl('refreshToken', {
|
|
1643
|
+
fields: ['token', 'refreshToken'],
|
|
1644
|
+
})
|
|
1645
|
+
.subscribe({
|
|
1646
|
+
next: (response) => {
|
|
1647
|
+
this.token = response.token;
|
|
1648
|
+
this.refreshToken = response.refreshToken;
|
|
1649
|
+
subscriber.next(response);
|
|
1650
|
+
subscriber.complete();
|
|
1651
|
+
},
|
|
1652
|
+
error: (err) => {
|
|
1653
|
+
subscriber.error(err);
|
|
1654
|
+
},
|
|
1655
|
+
});
|
|
1656
|
+
});
|
|
1657
|
+
}
|
|
1658
|
+
loadFromStorage() {
|
|
1659
|
+
if (localStorage) {
|
|
1660
|
+
this.token = this.storageService.load('token');
|
|
1661
|
+
this.refreshToken = this.storageService.load('refreshToken');
|
|
1662
|
+
this.currentUser = this.storageService.load('currentUser');
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Logout
|
|
1667
|
+
*/
|
|
1668
|
+
logout(redirect = true) {
|
|
1669
|
+
return new Observable((subscriber) => {
|
|
1670
|
+
this.injector
|
|
1671
|
+
.get(GraphQLService)
|
|
1672
|
+
.graphQl('logout', {
|
|
1673
|
+
fields: [],
|
|
1674
|
+
})
|
|
1675
|
+
.subscribe({
|
|
1676
|
+
next: () => {
|
|
1677
|
+
this.clearSession(redirect);
|
|
1678
|
+
subscriber.next(true);
|
|
1679
|
+
subscriber.complete();
|
|
1680
|
+
},
|
|
1681
|
+
error: (err) => {
|
|
1682
|
+
subscriber.error(err);
|
|
1683
|
+
},
|
|
1684
|
+
});
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
clearSession(redirect = true) {
|
|
1688
|
+
this.storageService.remove(['token', 'refreshToken', 'currentUser']);
|
|
1689
|
+
this.currentUser = null;
|
|
1690
|
+
this.token = null;
|
|
1691
|
+
this.refreshToken = null;
|
|
1692
|
+
if (redirect) {
|
|
1693
|
+
this.router.navigate(['/auth']);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
// #################################################################
|
|
1697
|
+
// Current User
|
|
1698
|
+
// #################################################################
|
|
1699
|
+
get currentUser() {
|
|
1700
|
+
if (!localStorage) {
|
|
1701
|
+
return undefined;
|
|
1702
|
+
}
|
|
1703
|
+
return this._currentUser.value;
|
|
1704
|
+
}
|
|
1705
|
+
set currentUser(user) {
|
|
1706
|
+
this._currentUser.next(user);
|
|
1707
|
+
this.storageService.save('currentUser', user);
|
|
1708
|
+
}
|
|
1709
|
+
get currentUserObservable() {
|
|
1710
|
+
return this._currentUser.asObservable();
|
|
1711
|
+
}
|
|
1712
|
+
// #################################################################
|
|
1713
|
+
// Token
|
|
1714
|
+
// #################################################################
|
|
1715
|
+
get token() {
|
|
1716
|
+
if (!localStorage) {
|
|
1717
|
+
return undefined;
|
|
1718
|
+
}
|
|
1719
|
+
return this._token.value;
|
|
1720
|
+
}
|
|
1721
|
+
set token(token) {
|
|
1722
|
+
this._token.next(token);
|
|
1723
|
+
this.storageService.save('token', token);
|
|
1724
|
+
this.wsService.reconnect();
|
|
1725
|
+
}
|
|
1726
|
+
get tokenObservable() {
|
|
1727
|
+
if (!this._token.value) {
|
|
1728
|
+
this.loadFromStorage();
|
|
1729
|
+
}
|
|
1730
|
+
return this._token.asObservable();
|
|
1731
|
+
}
|
|
1732
|
+
// #################################################################
|
|
1733
|
+
// refreshToken
|
|
1734
|
+
// #################################################################
|
|
1735
|
+
get refreshToken() {
|
|
1736
|
+
if (!localStorage) {
|
|
1737
|
+
return undefined;
|
|
1738
|
+
}
|
|
1739
|
+
return this._refreshToken.value;
|
|
1740
|
+
}
|
|
1741
|
+
set refreshToken(refreshToken) {
|
|
1742
|
+
this._refreshToken.next(refreshToken);
|
|
1743
|
+
this.storageService.save('refreshToken', refreshToken);
|
|
1744
|
+
}
|
|
1745
|
+
get refreshTokenObservable() {
|
|
1746
|
+
if (!this._refreshToken.value) {
|
|
1747
|
+
this.loadFromStorage();
|
|
1748
|
+
}
|
|
1749
|
+
return this._refreshToken.asObservable();
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
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 });
|
|
1753
|
+
AuthService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: AuthService, providedIn: 'root' });
|
|
1754
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.12", ngImport: i0, type: AuthService, decorators: [{
|
|
1755
|
+
type: Injectable,
|
|
1756
|
+
args: [{
|
|
1757
|
+
providedIn: 'root',
|
|
1758
|
+
}]
|
|
1759
|
+
}], ctorParameters: function () { return [{ type: StorageService }, { type: WsService }, { type: i0.Injector }, { type: i1$1.Router }]; } });
|
|
1760
|
+
|
|
1698
1761
|
/**
|
|
1699
1762
|
* Loader service for loading indication
|
|
1700
1763
|
*/
|
|
@@ -2194,15 +2257,16 @@ class UserService extends GraphQLPlusService {
|
|
|
2194
2257
|
*/
|
|
2195
2258
|
login(input) {
|
|
2196
2259
|
return this.graphQl('signIn', {
|
|
2197
|
-
arguments: { input },
|
|
2198
|
-
fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
|
|
2199
|
-
type: GraphQLRequestType.QUERY,
|
|
2260
|
+
arguments: { input: { ...input, deviceDescription: navigator?.userAgent } },
|
|
2261
|
+
fields: ['refreshToken', 'token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
|
|
2200
2262
|
loading: true,
|
|
2201
2263
|
}).pipe(map$1((response) => {
|
|
2202
2264
|
this.authService.token = response.token;
|
|
2265
|
+
this.authService.refreshToken = response.refreshToken;
|
|
2203
2266
|
this.authService.currentUser = response.user;
|
|
2204
2267
|
return Auth.map({
|
|
2205
2268
|
token: response.token,
|
|
2269
|
+
refreshToken: response.refreshToken,
|
|
2206
2270
|
user: BasicUser.map(response.user),
|
|
2207
2271
|
});
|
|
2208
2272
|
}));
|
|
@@ -2214,15 +2278,16 @@ class UserService extends GraphQLPlusService {
|
|
|
2214
2278
|
*/
|
|
2215
2279
|
register(input) {
|
|
2216
2280
|
return this.graphQl('signUp', {
|
|
2217
|
-
arguments: { input },
|
|
2218
|
-
fields: ['token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
|
|
2219
|
-
type: GraphQLRequestType.MUTATION,
|
|
2281
|
+
arguments: { input: { ...input, deviceDescription: navigator?.userAgent } },
|
|
2282
|
+
fields: ['refreshToken', 'token', { user: ['id', 'firstName', 'lastName', 'email', 'roles', 'avatar'] }],
|
|
2220
2283
|
loading: true,
|
|
2221
2284
|
}).pipe(map$1((response) => {
|
|
2222
2285
|
this.authService.token = response.token;
|
|
2286
|
+
this.authService.refreshToken = response.refreshToken;
|
|
2223
2287
|
this.authService.currentUser = response.user;
|
|
2224
2288
|
return Auth.map({
|
|
2225
2289
|
token: response.token,
|
|
2290
|
+
refreshToken: response.refreshToken,
|
|
2226
2291
|
user: BasicUser.map(response.user),
|
|
2227
2292
|
});
|
|
2228
2293
|
}));
|