@thzero/library_server 0.17.10 → 0.17.12
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 +93 -93
- package/boot/index.js +460 -460
- 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 +57 -57
- 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 +39 -39
- package/repository/index.js +174 -174
- package/repository/usageMetrics/devnull.js +11 -11
- 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 +172 -44
- package/service/baseUser.js +122 -122
- package/service/communication.js +6 -6
- package/service/config.js +32 -32
- 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 +49 -49
- package/service/news/index.js +6 -6
- package/service/news/validation/index.js +6 -6
- package/service/plans.js +27 -27
- package/service/restCommunication.js +21 -21
- package/service/usageMetrics.js +57 -57
- package/service/utility.js +177 -177
- package/service/version.js +32 -32
- 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,44 +1,172 @@
|
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
if (!claims)
|
|
24
|
+
return false;
|
|
25
|
+
if (!(claims && Array.isArray(claims)))
|
|
26
|
+
return false;
|
|
27
|
+
if (!roles)
|
|
28
|
+
return true;
|
|
29
|
+
|
|
30
|
+
if (String.isNullOrEmpty(logical) || (logical !== BaseSecurityService.logicalAnd) || (logical !== BaseSecurityService.logicalOr))
|
|
31
|
+
logical = BaseSecurityService.logicalOr;
|
|
32
|
+
|
|
33
|
+
let success = (logical === BaseSecurityService.logicalOr ? false : true);
|
|
34
|
+
|
|
35
|
+
let result;
|
|
36
|
+
let roleAct;
|
|
37
|
+
let roleObj;
|
|
38
|
+
let roleParts;
|
|
39
|
+
for (const claim of claims) {
|
|
40
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckClaims', 'authorization.claim', claim, correlationId);
|
|
41
|
+
|
|
42
|
+
for (const role of roles) {
|
|
43
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckClaims', 'role', role, correlationId);
|
|
44
|
+
|
|
45
|
+
roleParts = role.split('.');
|
|
46
|
+
if (roleParts && roleParts.length < 1)
|
|
47
|
+
success = false;
|
|
48
|
+
|
|
49
|
+
roleObj = roleParts[0];
|
|
50
|
+
roleAct = roleParts.length >= 2 ? roleParts[1] : null
|
|
51
|
+
|
|
52
|
+
result = await this.validate(claim, null, roleObj, roleAct);
|
|
53
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckClaims', 'result', result, correlationId);
|
|
54
|
+
if (logical === BaseSecurityService.logicalOr)
|
|
55
|
+
success = success || result;
|
|
56
|
+
else
|
|
57
|
+
success = success && result;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return success;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async authorizationCheckRoles(correlationId, user, roles, logical) {
|
|
65
|
+
if (!user)
|
|
66
|
+
return false;
|
|
67
|
+
if (!roles)
|
|
68
|
+
return true;
|
|
69
|
+
|
|
70
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'user', user, correlationId);
|
|
71
|
+
if (!(user && user.roles && Array.isArray(user.roles)))
|
|
72
|
+
return false;
|
|
73
|
+
|
|
74
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'logical', logical, correlationId);
|
|
75
|
+
|
|
76
|
+
if (String.isNullOrEmpty(logical) || (logical !== BaseSecurityService.logicalAnd) || (logical !== BaseSecurityService.logicalOr))
|
|
77
|
+
logical = BaseSecurityService.logicalOr;
|
|
78
|
+
|
|
79
|
+
let success = (logical === BaseSecurityService.logicalOr ? false : true);
|
|
80
|
+
|
|
81
|
+
let result;
|
|
82
|
+
let roleAct;
|
|
83
|
+
let roleObj;
|
|
84
|
+
let roleParts;
|
|
85
|
+
for (const userRole of user.roles) {
|
|
86
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'userRole', userRole, correlationId);
|
|
87
|
+
|
|
88
|
+
for (const role of roles) {
|
|
89
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'role', role, correlationId);
|
|
90
|
+
|
|
91
|
+
roleParts = role.split('.');
|
|
92
|
+
if (roleParts && roleParts.length < 1)
|
|
93
|
+
success = false;
|
|
94
|
+
|
|
95
|
+
roleObj = roleParts[0];
|
|
96
|
+
roleAct = roleParts.length >= 2 ? roleParts[1] : null
|
|
97
|
+
|
|
98
|
+
result = await this.validate(userRole, null, roleObj, roleAct);
|
|
99
|
+
this._logger.debug('BaseSecurityService', 'authorizationCheckRoles', 'result', result, correlationId);
|
|
100
|
+
if (logical === BaseSecurityService.logicalOr) {
|
|
101
|
+
if (result)
|
|
102
|
+
return result;
|
|
103
|
+
|
|
104
|
+
success = false;
|
|
105
|
+
}
|
|
106
|
+
else
|
|
107
|
+
success = success && result;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return success;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
initializeRoles(correlationId, requestRoles, roles) {
|
|
115
|
+
if (Array.isArray(roles)) {
|
|
116
|
+
this._logger.debug('BaseSecurityService', 'initalizeRoles', 'roles1a', roles, correlationId);
|
|
117
|
+
requestRoles = roles;
|
|
118
|
+
return requestRoles;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if ((typeof(roles) === 'string') || (roles instanceof String)) {
|
|
122
|
+
// this._logger.debug('BaseSecurityService', 'initalizeRoles', 'roles1b', roles, correlationId);
|
|
123
|
+
requestRoles = roles.split(',');
|
|
124
|
+
requestRoles.map(item => item ? item.trim() : item);
|
|
125
|
+
return requestRoles;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
initializeOptionsLogical(correlationId, options) {
|
|
130
|
+
if (!options)
|
|
131
|
+
return logicalOr;
|
|
132
|
+
|
|
133
|
+
let logical = options.logical;
|
|
134
|
+
if (String.isNullOrEmpty(logical) || (logical !== logicalAnd) || (logical !== logicalOr))
|
|
135
|
+
logical = logicalOr;
|
|
136
|
+
|
|
137
|
+
return logical;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
initializeOptionsRoles(correlationId, options) {
|
|
141
|
+
let roles = [];
|
|
142
|
+
if (options.roles && Array.isArray(options.roles) && (options.roles.length > 0))
|
|
143
|
+
roles = options.roles;
|
|
144
|
+
return roles;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// eslint-disable-next-line
|
|
148
|
+
async validate(correlationId, sub, dom, obj, act) {
|
|
149
|
+
if (!this._enforcer)
|
|
150
|
+
throw Error('No enforcer found');
|
|
151
|
+
|
|
152
|
+
const array = [];
|
|
153
|
+
if (dom)
|
|
154
|
+
array.push(dom);
|
|
155
|
+
array.push(obj)
|
|
156
|
+
if (act)
|
|
157
|
+
array.push(act);
|
|
158
|
+
|
|
159
|
+
const role = array.join(':');
|
|
160
|
+
const results = await this._enforcer.can(sub, role);
|
|
161
|
+
return results;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
_initModel() {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
static logicalAnd = 'and';
|
|
169
|
+
static logicalOr = 'or';
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
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;
|
package/service/config.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import ConfigService from '@thzero/library_common_service/service/config.js';
|
|
2
|
-
|
|
3
|
-
class ServerConfigService extends ConfigService {
|
|
4
|
-
constructor(config) {
|
|
5
|
-
super(config);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
getBackend(key) {
|
|
9
|
-
if (String.isNullOrEmpty(key))
|
|
10
|
-
return null;
|
|
11
|
-
|
|
12
|
-
if (!this._config)
|
|
13
|
-
return null;
|
|
14
|
-
|
|
15
|
-
const configBackend = this._config.get('backend', null);
|
|
16
|
-
if (!configBackend)
|
|
17
|
-
return null;
|
|
18
|
-
|
|
19
|
-
if (!Array.isArray(configBackend))
|
|
20
|
-
return null;
|
|
21
|
-
|
|
22
|
-
key = key.toLowerCase();
|
|
23
|
-
for (const item of configBackend) {
|
|
24
|
-
if (item.key.toLowerCase() === key)
|
|
25
|
-
return item;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default ServerConfigService;
|
|
1
|
+
import ConfigService from '@thzero/library_common_service/service/config.js';
|
|
2
|
+
|
|
3
|
+
class ServerConfigService extends ConfigService {
|
|
4
|
+
constructor(config) {
|
|
5
|
+
super(config);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
getBackend(key) {
|
|
9
|
+
if (String.isNullOrEmpty(key))
|
|
10
|
+
return null;
|
|
11
|
+
|
|
12
|
+
if (!this._config)
|
|
13
|
+
return null;
|
|
14
|
+
|
|
15
|
+
const configBackend = this._config.get('backend', null);
|
|
16
|
+
if (!configBackend)
|
|
17
|
+
return null;
|
|
18
|
+
|
|
19
|
+
if (!Array.isArray(configBackend))
|
|
20
|
+
return null;
|
|
21
|
+
|
|
22
|
+
key = key.toLowerCase();
|
|
23
|
+
for (const item of configBackend) {
|
|
24
|
+
if (item.key.toLowerCase() === key)
|
|
25
|
+
return item;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default ServerConfigService;
|
package/service/crypto.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
|
|
3
|
-
import Service from './index.js';
|
|
4
|
-
|
|
5
|
-
const encoder = new TextEncoder();
|
|
6
|
-
|
|
7
|
-
class CryptoService extends Service {
|
|
8
|
-
async checksum(input, algorithm, encoding) {
|
|
9
|
-
return crypto
|
|
10
|
-
.createHash(algorithm || 'sha256')
|
|
11
|
-
.update(encoder.encode(input), 'utf8')
|
|
12
|
-
.digest(encoding || 'hex');
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default CryptoService;
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
import Service from './index.js';
|
|
4
|
+
|
|
5
|
+
const encoder = new TextEncoder();
|
|
6
|
+
|
|
7
|
+
class CryptoService extends Service {
|
|
8
|
+
async checksum(input, algorithm, encoding) {
|
|
9
|
+
return crypto
|
|
10
|
+
.createHash(algorithm || 'sha256')
|
|
11
|
+
.update(encoder.encode(input), 'utf8')
|
|
12
|
+
.digest(encoding || 'hex');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default CryptoService;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import BaseService from '@thzero/library_server/service/index.js';
|
|
2
|
-
|
|
3
|
-
class DiscoveryService extends BaseService {
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export default DiscoveryService;
|
|
1
|
+
import BaseService from '@thzero/library_server/service/index.js';
|
|
2
|
+
|
|
3
|
+
class DiscoveryService extends BaseService {
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export default DiscoveryService;
|