@thzero/library_server 0.18.21 → 0.18.22
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/README.md +112 -112
- package/boot/index.js +529 -529
- package/boot/plugins/admin/index.js +6 -6
- package/boot/plugins/admin/news.js +33 -33
- package/boot/plugins/admin/users.js +33 -33
- package/boot/plugins/api.js +64 -64
- package/boot/plugins/apiFront.js +31 -31
- package/boot/plugins/index.js +70 -70
- package/boot/plugins/news.js +44 -44
- package/boot/plugins/users.js +46 -46
- package/boot/plugins/usersExtended.js +32 -32
- package/constants.js +45 -45
- package/data/baseNews.js +42 -42
- package/data/baseSettingsUser.js +9 -9
- package/data/baseUser.js +28 -28
- package/data/index.js +24 -24
- package/data/named.js +20 -20
- package/errors/tokenExpired.js +7 -7
- package/license.md +8 -8
- package/openSource.js +66 -66
- package/package.json +38 -38
- package/repository/index.js +182 -182
- package/repository/usageMetrics/devnull.js +16 -16
- package/routes/index.js +76 -76
- package/service/admin/baseNews.js +45 -45
- package/service/admin/index.js +130 -130
- package/service/admin/news.js +6 -6
- package/service/admin/users.js +107 -107
- package/service/baseSecurity.js +183 -183
- package/service/baseUser.js +122 -122
- package/service/communication.js +6 -6
- package/service/config.js +37 -37
- package/service/crypto.js +16 -16
- package/service/discovery/index.js +6 -6
- package/service/discovery/resources/index.js +101 -101
- package/service/external.js +19 -19
- package/service/externalRest.js +19 -19
- package/service/index.js +20 -20
- package/service/monitoring.js +12 -12
- package/service/news/base.js +59 -59
- package/service/news/index.js +6 -6
- package/service/news/validation/index.js +6 -6
- package/service/plans.js +31 -31
- package/service/restCommunication.js +21 -21
- package/service/usageMetrics.js +84 -84
- package/service/utility.js +190 -190
- package/service/version.js +37 -37
- package/utility/injector.js +59 -59
- package/utility/internalIp/index.js +48 -48
- package/utility/list/doubleLinked.js +88 -88
- package/utility/list/priorityQueue.js +109 -109
- package/utility/list/queue.js +72 -72
- package/utility/os.js +20 -20
package/service/baseSecurity.js
CHANGED
|
@@ -1,183 +1,183 @@
|
|
|
1
|
-
import rbac from 'easy-rbac'
|
|
2
|
-
|
|
3
|
-
import Service from './index.js';
|
|
4
|
-
|
|
5
|
-
class BaseSecurityService extends Service {
|
|
6
|
-
constructor() {
|
|
7
|
-
super();
|
|
8
|
-
|
|
9
|
-
this._enforcer = null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
async init(injector) {
|
|
13
|
-
await super.init(injector);
|
|
14
|
-
|
|
15
|
-
const model = this._initModel();
|
|
16
|
-
if (!model)
|
|
17
|
-
return;
|
|
18
|
-
|
|
19
|
-
this._enforcer = new rbac(model)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async authorizationCheckClaims(correlationId, claims, roles, logical) {
|
|
23
|
-
try {
|
|
24
|
-
if (!claims)
|
|
25
|
-
return false;
|
|
26
|
-
if (!(claims && Array.isArray(claims)))
|
|
27
|
-
return false;
|
|
28
|
-
if (!roles)
|
|
29
|
-
return true;
|
|
30
|
-
|
|
31
|
-
if (String.isNullOrEmpty(logical) || (logical !== BaseSecurityService.logicalAnd) || (logical !== BaseSecurityService.logicalOr))
|
|
32
|
-
logical = BaseSecurityService.logicalOr;
|
|
33
|
-
|
|
34
|
-
let success = (logical === BaseSecurityService.logicalOr ? false : true);
|
|
35
|
-
|
|
36
|
-
let result;
|
|
37
|
-
let roleAct;
|
|
38
|
-
let roleObj;
|
|
39
|
-
let roleParts;
|
|
40
|
-
for (const claim of claims) {
|
|
41
|
-
this._logger.debug('BaseSecurityService', 'authorizationCheckClaims', 'authorization.claim', claim, correlationId);
|
|
42
|
-
|
|
43
|
-
for (const role of roles) {
|
|
44
|
-
this._logger.debug('BaseSecurityService', 'authorizationCheckClaims', 'role', role, correlationId);
|
|
45
|
-
|
|
46
|
-
roleParts = role.split('.');
|
|
47
|
-
if (roleParts && roleParts.length < 1)
|
|
48
|
-
success = false;
|
|
49
|
-
|
|
50
|
-
roleObj = roleParts[0];
|
|
51
|
-
roleAct = roleParts.length >= 2 ? roleParts[1] : null
|
|
52
|
-
|
|
53
|
-
result = await this.validate(claim, null, roleObj, roleAct);
|
|
54
|
-
this._logger.debug('BaseSecurityService', 'authorizationCheckClaims', 'result', result, correlationId);
|
|
55
|
-
if (logical === BaseSecurityService.logicalOr)
|
|
56
|
-
success = success || result;
|
|
57
|
-
else
|
|
58
|
-
success = success && result;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return success;
|
|
63
|
-
}
|
|
64
|
-
catch (err) {
|
|
65
|
-
this._error('BaseSecurityService', 'authorizationCheckClaims', null, err, null, null, correlationId);
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async authorizationCheckRoles(correlationId, user, roles, logical) {
|
|
71
|
-
try {
|
|
72
|
-
if (!user)
|
|
73
|
-
return false;
|
|
74
|
-
if (!roles)
|
|
75
|
-
return true;
|
|
76
|
-
|
|
77
|
-
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'user', user, correlationId);
|
|
78
|
-
if (!(user && user.roles && Array.isArray(user.roles)))
|
|
79
|
-
return false;
|
|
80
|
-
|
|
81
|
-
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'logical', logical, correlationId);
|
|
82
|
-
|
|
83
|
-
if (String.isNullOrEmpty(logical) || (logical !== BaseSecurityService.logicalAnd) || (logical !== BaseSecurityService.logicalOr))
|
|
84
|
-
logical = BaseSecurityService.logicalOr;
|
|
85
|
-
|
|
86
|
-
let success = (logical === BaseSecurityService.logicalOr ? false : true);
|
|
87
|
-
|
|
88
|
-
let result;
|
|
89
|
-
let roleAct;
|
|
90
|
-
let roleObj;
|
|
91
|
-
let roleParts;
|
|
92
|
-
for (const userRole of user.roles) {
|
|
93
|
-
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'userRole', userRole, correlationId);
|
|
94
|
-
|
|
95
|
-
for (const role of roles) {
|
|
96
|
-
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'role', role, correlationId);
|
|
97
|
-
|
|
98
|
-
roleParts = role.split('.');
|
|
99
|
-
if (roleParts && roleParts.length < 1)
|
|
100
|
-
success = false;
|
|
101
|
-
|
|
102
|
-
roleObj = roleParts[0];
|
|
103
|
-
roleAct = roleParts.length >= 2 ? roleParts[1] : null
|
|
104
|
-
|
|
105
|
-
result = await this.validate(correlationId, userRole, null, roleObj, roleAct);
|
|
106
|
-
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'result', result, correlationId);
|
|
107
|
-
if (logical === BaseSecurityService.logicalOr) {
|
|
108
|
-
if (result)
|
|
109
|
-
return result;
|
|
110
|
-
|
|
111
|
-
success = false;
|
|
112
|
-
}
|
|
113
|
-
else
|
|
114
|
-
success = success && result;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return success;
|
|
119
|
-
}
|
|
120
|
-
catch (err) {
|
|
121
|
-
this._error('BaseSecurityService', 'authorizationCheckRoles', null, err, null, null, correlationId);
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
initializeRoles(correlationId, requestRoles, roles) {
|
|
127
|
-
if (Array.isArray(roles)) {
|
|
128
|
-
this._logger.debug('BaseSecurityService', 'initalizeRoles', 'roles1a', roles, correlationId);
|
|
129
|
-
requestRoles = roles;
|
|
130
|
-
return requestRoles;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if ((typeof(roles) === 'string') || (roles instanceof String)) {
|
|
134
|
-
// this._logger.debug('BaseSecurityService', 'initalizeRoles', 'roles1b', roles, correlationId);
|
|
135
|
-
requestRoles = roles.split(',');
|
|
136
|
-
requestRoles.map(item => item ? item.trim() : item);
|
|
137
|
-
return requestRoles;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
initializeOptionsLogical(correlationId, options) {
|
|
142
|
-
if (!options)
|
|
143
|
-
return BaseSecurityService.logicalOr;
|
|
144
|
-
|
|
145
|
-
let logical = options.logical;
|
|
146
|
-
if (String.isNullOrEmpty(logical) || (logical !== BaseSecurityService.logicalAnd) || (logical !== BaseSecurityService.logicalOr))
|
|
147
|
-
logical = BaseSecurityService.logicalOr;
|
|
148
|
-
|
|
149
|
-
return logical;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
initializeOptionsRoles(correlationId, options) {
|
|
153
|
-
let roles = [];
|
|
154
|
-
if (options.roles && Array.isArray(options.roles) && (options.roles.length > 0))
|
|
155
|
-
roles = options.roles;
|
|
156
|
-
return roles;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// eslint-disable-next-line
|
|
160
|
-
async validate(correlationId, sub, dom, obj, act) {
|
|
161
|
-
if (!this._enforcer)
|
|
162
|
-
throw Error('No enforcer found');
|
|
163
|
-
|
|
164
|
-
const array = [];
|
|
165
|
-
if (dom)
|
|
166
|
-
array.push(dom);
|
|
167
|
-
array.push(obj)
|
|
168
|
-
if (act)
|
|
169
|
-
array.push(act);
|
|
170
|
-
|
|
171
|
-
const role = array.join(':');
|
|
172
|
-
return await this._enforcer.can(sub, role);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
_initModel() {
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
static logicalAnd = 'and';
|
|
180
|
-
static logicalOr = 'or';
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export default BaseSecurityService;
|
|
1
|
+
import rbac from 'easy-rbac'
|
|
2
|
+
|
|
3
|
+
import Service from './index.js';
|
|
4
|
+
|
|
5
|
+
class BaseSecurityService extends Service {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
|
|
9
|
+
this._enforcer = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async init(injector) {
|
|
13
|
+
await super.init(injector);
|
|
14
|
+
|
|
15
|
+
const model = this._initModel();
|
|
16
|
+
if (!model)
|
|
17
|
+
return;
|
|
18
|
+
|
|
19
|
+
this._enforcer = new rbac(model)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async authorizationCheckClaims(correlationId, claims, roles, logical) {
|
|
23
|
+
try {
|
|
24
|
+
if (!claims)
|
|
25
|
+
return false;
|
|
26
|
+
if (!(claims && Array.isArray(claims)))
|
|
27
|
+
return false;
|
|
28
|
+
if (!roles)
|
|
29
|
+
return true;
|
|
30
|
+
|
|
31
|
+
if (String.isNullOrEmpty(logical) || (logical !== BaseSecurityService.logicalAnd) || (logical !== BaseSecurityService.logicalOr))
|
|
32
|
+
logical = BaseSecurityService.logicalOr;
|
|
33
|
+
|
|
34
|
+
let success = (logical === BaseSecurityService.logicalOr ? false : true);
|
|
35
|
+
|
|
36
|
+
let result;
|
|
37
|
+
let roleAct;
|
|
38
|
+
let roleObj;
|
|
39
|
+
let roleParts;
|
|
40
|
+
for (const claim of claims) {
|
|
41
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckClaims', 'authorization.claim', claim, correlationId);
|
|
42
|
+
|
|
43
|
+
for (const role of roles) {
|
|
44
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckClaims', 'role', role, correlationId);
|
|
45
|
+
|
|
46
|
+
roleParts = role.split('.');
|
|
47
|
+
if (roleParts && roleParts.length < 1)
|
|
48
|
+
success = false;
|
|
49
|
+
|
|
50
|
+
roleObj = roleParts[0];
|
|
51
|
+
roleAct = roleParts.length >= 2 ? roleParts[1] : null
|
|
52
|
+
|
|
53
|
+
result = await this.validate(claim, null, roleObj, roleAct);
|
|
54
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckClaims', 'result', result, correlationId);
|
|
55
|
+
if (logical === BaseSecurityService.logicalOr)
|
|
56
|
+
success = success || result;
|
|
57
|
+
else
|
|
58
|
+
success = success && result;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return success;
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
this._error('BaseSecurityService', 'authorizationCheckClaims', null, err, null, null, correlationId);
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async authorizationCheckRoles(correlationId, user, roles, logical) {
|
|
71
|
+
try {
|
|
72
|
+
if (!user)
|
|
73
|
+
return false;
|
|
74
|
+
if (!roles)
|
|
75
|
+
return true;
|
|
76
|
+
|
|
77
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'user', user, correlationId);
|
|
78
|
+
if (!(user && user.roles && Array.isArray(user.roles)))
|
|
79
|
+
return false;
|
|
80
|
+
|
|
81
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'logical', logical, correlationId);
|
|
82
|
+
|
|
83
|
+
if (String.isNullOrEmpty(logical) || (logical !== BaseSecurityService.logicalAnd) || (logical !== BaseSecurityService.logicalOr))
|
|
84
|
+
logical = BaseSecurityService.logicalOr;
|
|
85
|
+
|
|
86
|
+
let success = (logical === BaseSecurityService.logicalOr ? false : true);
|
|
87
|
+
|
|
88
|
+
let result;
|
|
89
|
+
let roleAct;
|
|
90
|
+
let roleObj;
|
|
91
|
+
let roleParts;
|
|
92
|
+
for (const userRole of user.roles) {
|
|
93
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'userRole', userRole, correlationId);
|
|
94
|
+
|
|
95
|
+
for (const role of roles) {
|
|
96
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'role', role, correlationId);
|
|
97
|
+
|
|
98
|
+
roleParts = role.split('.');
|
|
99
|
+
if (roleParts && roleParts.length < 1)
|
|
100
|
+
success = false;
|
|
101
|
+
|
|
102
|
+
roleObj = roleParts[0];
|
|
103
|
+
roleAct = roleParts.length >= 2 ? roleParts[1] : null
|
|
104
|
+
|
|
105
|
+
result = await this.validate(correlationId, userRole, null, roleObj, roleAct);
|
|
106
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'result', result, correlationId);
|
|
107
|
+
if (logical === BaseSecurityService.logicalOr) {
|
|
108
|
+
if (result)
|
|
109
|
+
return result;
|
|
110
|
+
|
|
111
|
+
success = false;
|
|
112
|
+
}
|
|
113
|
+
else
|
|
114
|
+
success = success && result;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return success;
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
this._error('BaseSecurityService', 'authorizationCheckRoles', null, err, null, null, correlationId);
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
initializeRoles(correlationId, requestRoles, roles) {
|
|
127
|
+
if (Array.isArray(roles)) {
|
|
128
|
+
this._logger.debug('BaseSecurityService', 'initalizeRoles', 'roles1a', roles, correlationId);
|
|
129
|
+
requestRoles = roles;
|
|
130
|
+
return requestRoles;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if ((typeof(roles) === 'string') || (roles instanceof String)) {
|
|
134
|
+
// this._logger.debug('BaseSecurityService', 'initalizeRoles', 'roles1b', roles, correlationId);
|
|
135
|
+
requestRoles = roles.split(',');
|
|
136
|
+
requestRoles.map(item => item ? item.trim() : item);
|
|
137
|
+
return requestRoles;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
initializeOptionsLogical(correlationId, options) {
|
|
142
|
+
if (!options)
|
|
143
|
+
return BaseSecurityService.logicalOr;
|
|
144
|
+
|
|
145
|
+
let logical = options.logical;
|
|
146
|
+
if (String.isNullOrEmpty(logical) || (logical !== BaseSecurityService.logicalAnd) || (logical !== BaseSecurityService.logicalOr))
|
|
147
|
+
logical = BaseSecurityService.logicalOr;
|
|
148
|
+
|
|
149
|
+
return logical;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
initializeOptionsRoles(correlationId, options) {
|
|
153
|
+
let roles = [];
|
|
154
|
+
if (options.roles && Array.isArray(options.roles) && (options.roles.length > 0))
|
|
155
|
+
roles = options.roles;
|
|
156
|
+
return roles;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// eslint-disable-next-line
|
|
160
|
+
async validate(correlationId, sub, dom, obj, act) {
|
|
161
|
+
if (!this._enforcer)
|
|
162
|
+
throw Error('No enforcer found');
|
|
163
|
+
|
|
164
|
+
const array = [];
|
|
165
|
+
if (dom)
|
|
166
|
+
array.push(dom);
|
|
167
|
+
array.push(obj)
|
|
168
|
+
if (act)
|
|
169
|
+
array.push(act);
|
|
170
|
+
|
|
171
|
+
const role = array.join(':');
|
|
172
|
+
return await this._enforcer.can(sub, role);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
_initModel() {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
static logicalAnd = 'and';
|
|
180
|
+
static logicalOr = 'or';
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export default BaseSecurityService;
|
package/service/baseUser.js
CHANGED
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import Service from './index.js';
|
|
2
|
-
|
|
3
|
-
import NotImplementedError from '@thzero/library_common/errors/notImplemented.js';
|
|
4
|
-
|
|
5
|
-
class BaseUserService extends Service {
|
|
6
|
-
async fetch(correlationId, userId) {
|
|
7
|
-
const validationCheckExternalIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.externalIdSchema, userId);
|
|
8
|
-
if (this._hasFailed(validationCheckExternalIdResponse))
|
|
9
|
-
return validationCheckExternalIdResponse;
|
|
10
|
-
|
|
11
|
-
const respositoryResponse = await this._repositoryUser.fetch(correlationId, userId);
|
|
12
|
-
return respositoryResponse;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async fetchByExternalId(correlationId, externalUserId) {
|
|
16
|
-
const validationCheckExternalIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.externalIdSchema, externalUserId);
|
|
17
|
-
if (this._hasFailed(validationCheckExternalIdResponse))
|
|
18
|
-
return validationCheckExternalIdResponse;
|
|
19
|
-
|
|
20
|
-
const respositoryResponse = await this._repositoryUser.fetchByExternalId(correlationId, externalUserId);
|
|
21
|
-
return respositoryResponse;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async fetchByGamerId(correlationId, requestedGamerId) {
|
|
25
|
-
const validationRequestedGamerIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.gamerIdSchema, requestedGamerId);
|
|
26
|
-
if (this._hasFailed(validationRequestedGamerIdResponse))
|
|
27
|
-
return validationRequestedGamerIdResponse;
|
|
28
|
-
|
|
29
|
-
const respositoryResponse = await this._repositoryUser.fetchByGamerId(correlationId, requestedGamerId);
|
|
30
|
-
return respositoryResponse;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async fetchByGamerTag(correlationId, requestedUserGamerTag) {
|
|
34
|
-
const validationRequestedGamerTagResponse = this._serviceValidation.check(correlationId, this._serviceValidation.gamerTagSchema, requestedUserGamerTag);
|
|
35
|
-
if (this._hasFailed(validationRequestedGamerTagResponse))
|
|
36
|
-
return validationRequestedGamerTagResponse;
|
|
37
|
-
|
|
38
|
-
const respositoryResponse = await this._repositoryUser.fetchByGamerTag(correlationId, requestedUserGamerTag);
|
|
39
|
-
return respositoryResponse;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async refreshSettings(correlationId, params) {
|
|
43
|
-
const validationCheckExternalIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.settingsRefreshSchema, params);
|
|
44
|
-
if (this._hasFailed(validationCheckExternalIdResponse))
|
|
45
|
-
return validationCheckExternalIdResponse;
|
|
46
|
-
|
|
47
|
-
const respositoryResponse = await this._repositoryUser.refreshSettings(correlationId, params.userId);
|
|
48
|
-
return respositoryResponse;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async update(correlationId, externalUser) {
|
|
52
|
-
const validationCheckExternalUserResponse = this._serviceValidation.check(correlationId, this._serviceValidation.externalUserSchema, externalUser);
|
|
53
|
-
if (this._hasFailed(validationCheckExternalUserResponse))
|
|
54
|
-
return validationCheckExternalUserResponse;
|
|
55
|
-
|
|
56
|
-
let user = null;
|
|
57
|
-
const respositoryResponse = await this._repositoryUser.fetchByExternalId(correlationId, externalUser.id, true);
|
|
58
|
-
if (this._hasSucceeded(respositoryResponse))
|
|
59
|
-
user = respositoryResponse.results;
|
|
60
|
-
|
|
61
|
-
if (!user) {
|
|
62
|
-
user = this._initiateUser();
|
|
63
|
-
user.id = externalUser.id;
|
|
64
|
-
user.planId = this._getDefaultPlan();
|
|
65
|
-
user.roles.push(this._getDefaultUserRole());
|
|
66
|
-
this._initializeUser(user);
|
|
67
|
-
}
|
|
68
|
-
user.external = externalUser;
|
|
69
|
-
if (externalUser) {
|
|
70
|
-
if (String.isNullOrEmpty(user.email)) {
|
|
71
|
-
if (!String.isNullOrEmpty(externalUser.email)) {
|
|
72
|
-
user.email = externalUser.email;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const respositoryExternalResponse = await this._repositoryUser.updateFromExternal(correlationId, user.id, user);
|
|
78
|
-
return respositoryExternalResponse;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async updateSettings(correlationId, requestedSettings) {
|
|
82
|
-
const validationCheckSettingsResponse = this._serviceValidation.check(correlationId, this._serviceValidation.settingRequestSchema(), requestedSettings);
|
|
83
|
-
if (this._hasFailed(validationCheckSettingsResponse))
|
|
84
|
-
return validationCheckSettingsResponse;
|
|
85
|
-
|
|
86
|
-
const validationSettingsResponse = await this._updateSettingsValidation(correlationId, requestedSettings);
|
|
87
|
-
if (this._hasFailed(validationSettingsResponse))
|
|
88
|
-
return validationSettingsResponse;
|
|
89
|
-
|
|
90
|
-
const updateSettingsResponse = await this._updateSettings(correlationId, requestedSettings);
|
|
91
|
-
if (this._hasFailed(updateSettingsResponse))
|
|
92
|
-
return updateSettingsResponse;
|
|
93
|
-
|
|
94
|
-
const respositoryResponse = await this._repositoryUser.updateSettings(correlationId, requestedSettings.userId, requestedSettings.settings);
|
|
95
|
-
return respositoryResponse;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
_updateSettings(correlationId, requestedSettings) {
|
|
99
|
-
return this._success(correlationId);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
_updateSettingsValidation(correlationId, requestedSettings) {
|
|
103
|
-
return this._success(correlationId);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
_getDefaultPlan() {
|
|
107
|
-
return new NotImplementedError();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
_getDefaultUserRole() {
|
|
111
|
-
return new NotImplementedError();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
_initializeUser(user) {
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
get _repositoryUser() {
|
|
118
|
-
return new NotImplementedError();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export default BaseUserService;
|
|
1
|
+
import Service from './index.js';
|
|
2
|
+
|
|
3
|
+
import NotImplementedError from '@thzero/library_common/errors/notImplemented.js';
|
|
4
|
+
|
|
5
|
+
class BaseUserService extends Service {
|
|
6
|
+
async fetch(correlationId, userId) {
|
|
7
|
+
const validationCheckExternalIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.externalIdSchema, userId);
|
|
8
|
+
if (this._hasFailed(validationCheckExternalIdResponse))
|
|
9
|
+
return validationCheckExternalIdResponse;
|
|
10
|
+
|
|
11
|
+
const respositoryResponse = await this._repositoryUser.fetch(correlationId, userId);
|
|
12
|
+
return respositoryResponse;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async fetchByExternalId(correlationId, externalUserId) {
|
|
16
|
+
const validationCheckExternalIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.externalIdSchema, externalUserId);
|
|
17
|
+
if (this._hasFailed(validationCheckExternalIdResponse))
|
|
18
|
+
return validationCheckExternalIdResponse;
|
|
19
|
+
|
|
20
|
+
const respositoryResponse = await this._repositoryUser.fetchByExternalId(correlationId, externalUserId);
|
|
21
|
+
return respositoryResponse;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async fetchByGamerId(correlationId, requestedGamerId) {
|
|
25
|
+
const validationRequestedGamerIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.gamerIdSchema, requestedGamerId);
|
|
26
|
+
if (this._hasFailed(validationRequestedGamerIdResponse))
|
|
27
|
+
return validationRequestedGamerIdResponse;
|
|
28
|
+
|
|
29
|
+
const respositoryResponse = await this._repositoryUser.fetchByGamerId(correlationId, requestedGamerId);
|
|
30
|
+
return respositoryResponse;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async fetchByGamerTag(correlationId, requestedUserGamerTag) {
|
|
34
|
+
const validationRequestedGamerTagResponse = this._serviceValidation.check(correlationId, this._serviceValidation.gamerTagSchema, requestedUserGamerTag);
|
|
35
|
+
if (this._hasFailed(validationRequestedGamerTagResponse))
|
|
36
|
+
return validationRequestedGamerTagResponse;
|
|
37
|
+
|
|
38
|
+
const respositoryResponse = await this._repositoryUser.fetchByGamerTag(correlationId, requestedUserGamerTag);
|
|
39
|
+
return respositoryResponse;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async refreshSettings(correlationId, params) {
|
|
43
|
+
const validationCheckExternalIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.settingsRefreshSchema, params);
|
|
44
|
+
if (this._hasFailed(validationCheckExternalIdResponse))
|
|
45
|
+
return validationCheckExternalIdResponse;
|
|
46
|
+
|
|
47
|
+
const respositoryResponse = await this._repositoryUser.refreshSettings(correlationId, params.userId);
|
|
48
|
+
return respositoryResponse;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async update(correlationId, externalUser) {
|
|
52
|
+
const validationCheckExternalUserResponse = this._serviceValidation.check(correlationId, this._serviceValidation.externalUserSchema, externalUser);
|
|
53
|
+
if (this._hasFailed(validationCheckExternalUserResponse))
|
|
54
|
+
return validationCheckExternalUserResponse;
|
|
55
|
+
|
|
56
|
+
let user = null;
|
|
57
|
+
const respositoryResponse = await this._repositoryUser.fetchByExternalId(correlationId, externalUser.id, true);
|
|
58
|
+
if (this._hasSucceeded(respositoryResponse))
|
|
59
|
+
user = respositoryResponse.results;
|
|
60
|
+
|
|
61
|
+
if (!user) {
|
|
62
|
+
user = this._initiateUser();
|
|
63
|
+
user.id = externalUser.id;
|
|
64
|
+
user.planId = this._getDefaultPlan();
|
|
65
|
+
user.roles.push(this._getDefaultUserRole());
|
|
66
|
+
this._initializeUser(user);
|
|
67
|
+
}
|
|
68
|
+
user.external = externalUser;
|
|
69
|
+
if (externalUser) {
|
|
70
|
+
if (String.isNullOrEmpty(user.email)) {
|
|
71
|
+
if (!String.isNullOrEmpty(externalUser.email)) {
|
|
72
|
+
user.email = externalUser.email;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const respositoryExternalResponse = await this._repositoryUser.updateFromExternal(correlationId, user.id, user);
|
|
78
|
+
return respositoryExternalResponse;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async updateSettings(correlationId, requestedSettings) {
|
|
82
|
+
const validationCheckSettingsResponse = this._serviceValidation.check(correlationId, this._serviceValidation.settingRequestSchema(), requestedSettings);
|
|
83
|
+
if (this._hasFailed(validationCheckSettingsResponse))
|
|
84
|
+
return validationCheckSettingsResponse;
|
|
85
|
+
|
|
86
|
+
const validationSettingsResponse = await this._updateSettingsValidation(correlationId, requestedSettings);
|
|
87
|
+
if (this._hasFailed(validationSettingsResponse))
|
|
88
|
+
return validationSettingsResponse;
|
|
89
|
+
|
|
90
|
+
const updateSettingsResponse = await this._updateSettings(correlationId, requestedSettings);
|
|
91
|
+
if (this._hasFailed(updateSettingsResponse))
|
|
92
|
+
return updateSettingsResponse;
|
|
93
|
+
|
|
94
|
+
const respositoryResponse = await this._repositoryUser.updateSettings(correlationId, requestedSettings.userId, requestedSettings.settings);
|
|
95
|
+
return respositoryResponse;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
_updateSettings(correlationId, requestedSettings) {
|
|
99
|
+
return this._success(correlationId);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
_updateSettingsValidation(correlationId, requestedSettings) {
|
|
103
|
+
return this._success(correlationId);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
_getDefaultPlan() {
|
|
107
|
+
return new NotImplementedError();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
_getDefaultUserRole() {
|
|
111
|
+
return new NotImplementedError();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
_initializeUser(user) {
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
get _repositoryUser() {
|
|
118
|
+
return new NotImplementedError();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export default BaseUserService;
|
package/service/communication.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Service from './index.js';
|
|
2
|
-
|
|
3
|
-
class CommunicationService extends Service {
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export default CommunicationService;
|
|
1
|
+
import Service from './index.js';
|
|
2
|
+
|
|
3
|
+
class CommunicationService extends Service {
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export default CommunicationService;
|