@thzero/library_server 0.18.7 → 0.18.8

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.
Files changed (53) hide show
  1. package/README.md +93 -93
  2. package/boot/index.js +475 -466
  3. package/boot/plugins/admin/index.js +6 -6
  4. package/boot/plugins/admin/news.js +33 -33
  5. package/boot/plugins/admin/users.js +33 -33
  6. package/boot/plugins/api.js +64 -64
  7. package/boot/plugins/apiFront.js +31 -31
  8. package/boot/plugins/index.js +70 -70
  9. package/boot/plugins/news.js +44 -44
  10. package/boot/plugins/users.js +46 -46
  11. package/boot/plugins/usersExtended.js +32 -32
  12. package/constants.js +45 -45
  13. package/data/baseNews.js +42 -42
  14. package/data/baseSettingsUser.js +9 -9
  15. package/data/baseUser.js +28 -28
  16. package/data/index.js +24 -24
  17. package/data/named.js +20 -20
  18. package/errors/tokenExpired.js +7 -7
  19. package/license.md +8 -8
  20. package/openSource.js +66 -66
  21. package/package.json +38 -38
  22. package/repository/index.js +182 -182
  23. package/repository/usageMetrics/devnull.js +16 -16
  24. package/routes/index.js +76 -76
  25. package/service/admin/baseNews.js +45 -45
  26. package/service/admin/index.js +130 -130
  27. package/service/admin/news.js +6 -6
  28. package/service/admin/users.js +107 -107
  29. package/service/baseSecurity.js +183 -183
  30. package/service/baseUser.js +122 -122
  31. package/service/communication.js +6 -6
  32. package/service/config.js +37 -37
  33. package/service/crypto.js +16 -16
  34. package/service/discovery/index.js +6 -6
  35. package/service/discovery/resources/index.js +101 -101
  36. package/service/external.js +19 -19
  37. package/service/externalRest.js +19 -19
  38. package/service/index.js +20 -20
  39. package/service/monitoring.js +12 -12
  40. package/service/news/base.js +59 -59
  41. package/service/news/index.js +6 -6
  42. package/service/news/validation/index.js +6 -6
  43. package/service/plans.js +31 -31
  44. package/service/restCommunication.js +21 -21
  45. package/service/usageMetrics.js +84 -84
  46. package/service/utility.js +188 -188
  47. package/service/version.js +37 -37
  48. package/utility/injector.js +59 -59
  49. package/utility/internalIp/index.js +48 -48
  50. package/utility/list/doubleLinked.js +88 -88
  51. package/utility/list/priorityQueue.js +109 -109
  52. package/utility/list/queue.js +72 -72
  53. package/utility/os.js +20 -20
@@ -1,130 +1,130 @@
1
- import LibraryCommonUtility from '@thzero/library_common/utility/index.js';
2
-
3
- import NotImplementedError from '@thzero/library_common/errors/notImplemented.js';
4
-
5
- import Service from '../index.js';
6
-
7
- class BaseAdminService extends Service {
8
- async create(correlationId, user, requestedValue) {
9
- if (!this._allowsCreate)
10
- return this._error('BaseAdminService', 'create', null, null, null, null, correlationId);
11
-
12
- const validationResponse = this._validateUser(correlationId, user);
13
- if (this._hasFailed(validationResponse))
14
- return validationResponse;
15
-
16
- this._logger.debug('BaseAdminService', 'create', 'requestedValue', requestedValue, correlationId);
17
- const validationCheckValueResponse = this._validateCreate(correlationId, requestedValue);
18
- if (this._hasFailed(validationCheckValueResponse))
19
- return validationCheckValueResponse;
20
-
21
- const respositoryResponse = await this._repository.create(correlationId, user.id, requestedValue);
22
- return respositoryResponse;
23
- }
24
-
25
- async delete(correlationId, user, id) {
26
- if (!this._allowsDelete)
27
- return this._error('BaseAdminService', 'delete', null, null, null, null, correlationId);
28
-
29
- const validationCheckIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.idSchema, id, null, this._validationCheckKey);
30
- if (this._hasFailed(validationCheckIdResponse))
31
- return validationCheckIdResponse;
32
-
33
- const respositoryResponse = await this._repository.delete(correlationId, id);
34
- return respositoryResponse;
35
- }
36
-
37
- async search(correlationId, user, params) {
38
- const validationCheckParamsResponse = this._validateSearch(correlationId, params);
39
- if (this._hasFailed(validationCheckParamsResponse))
40
- return validationCheckParamsResponse;
41
-
42
- const respositoryResponse = await this._repository.search(correlationId, params);
43
- return respositoryResponse;
44
- }
45
-
46
- async update(correlationId, user, id, requestedValue) {
47
- if (!this._allowsUpdate)
48
- return this._error('BaseAdminService', 'update', 'requestedValue', null, null, null, correlationId);
49
-
50
- const validationResponse = this._validateUser(correlationId, user);
51
- if (this._hasFailed(validationResponse))
52
- return validationResponse;
53
-
54
- const validationIdResponse = this._validateId(correlationId, id, this._validationCheckKey);
55
- if (this._hasFailed(validationIdResponse))
56
- return validationIdResponse;
57
-
58
- this._logger.debug('BaseAdminService', 'update', 'requestedValue', requestedValue, correlationId);
59
- const validationCheckValueUpdateResponse = this._validateUpdate(correlationId, requestedValue);
60
- if (this._hasFailed(validationCheckValueUpdateResponse))
61
- return validationCheckValueUpdateResponse;
62
-
63
- let value = this._initializeData();
64
- const fetchRespositoryResponse = await this._repository.fetch(correlationId, id);
65
- if (this._hasSucceeded(fetchRespositoryResponse) && fetchRespositoryResponse.results)
66
- value = LibraryCommonUtility.map(this._initializeData(), fetchRespositoryResponse.results, true);
67
-
68
- const validResponse = this._checkUpdatedTimestamp(correlationId, value, requestedValue, 'value');
69
- if (this._hasFailed(validResponse))
70
- return validResponse;
71
-
72
- value.map(requestedValue);
73
-
74
- const respositoryResponse = await this._repository.update(correlationId, user.id, value);
75
- return respositoryResponse;
76
- }
77
-
78
- get _allowsCreate() {
79
- return true
80
- }
81
-
82
- get _allowsDelete() {
83
- return true
84
- }
85
-
86
- get _allowsUpdate() {
87
- return true
88
- }
89
-
90
- _initializeData() {
91
- throw new NotImplementedError()
92
- }
93
-
94
- get _repository() {
95
- throw new NotImplementedError()
96
- }
97
-
98
- _validateCreate(correlationId, requestedValue) {
99
- return this._serviceValidation.check(correlationId, this._validationCreateSchema, requestedValue, null, this._validationCheckKey);
100
- }
101
-
102
- get _validationCreateSchema() {
103
- throw new NotImplementedError()
104
- }
105
-
106
- _validateSearch(correlationId, requestedValue) {
107
- if (this._validationSearchSchema === null)
108
- return this._success(correlationId)
109
-
110
- return this._serviceValidation.check(correlationId, this._validationSearchSchema, requestedValue, null, this._validationCheckKey);
111
- }
112
-
113
- get _validationSearchSchema() {
114
- return null
115
- }
116
-
117
- _validateUpdate(correlationId, requestedValue) {
118
- return this._serviceValidation.check(correlationId, this._validationUpdateSchema, requestedValue, null, this._validationCheckKey);
119
- }
120
-
121
- get _validationUpdateSchema() {
122
- throw new NotImplementedError()
123
- }
124
-
125
- get _validationCheckKey() {
126
- throw new NotImplementedError()
127
- }
128
- }
129
-
130
- export default BaseAdminService;
1
+ import LibraryCommonUtility from '@thzero/library_common/utility/index.js';
2
+
3
+ import NotImplementedError from '@thzero/library_common/errors/notImplemented.js';
4
+
5
+ import Service from '../index.js';
6
+
7
+ class BaseAdminService extends Service {
8
+ async create(correlationId, user, requestedValue) {
9
+ if (!this._allowsCreate)
10
+ return this._error('BaseAdminService', 'create', null, null, null, null, correlationId);
11
+
12
+ const validationResponse = this._validateUser(correlationId, user);
13
+ if (this._hasFailed(validationResponse))
14
+ return validationResponse;
15
+
16
+ this._logger.debug('BaseAdminService', 'create', 'requestedValue', requestedValue, correlationId);
17
+ const validationCheckValueResponse = this._validateCreate(correlationId, requestedValue);
18
+ if (this._hasFailed(validationCheckValueResponse))
19
+ return validationCheckValueResponse;
20
+
21
+ const respositoryResponse = await this._repository.create(correlationId, user.id, requestedValue);
22
+ return respositoryResponse;
23
+ }
24
+
25
+ async delete(correlationId, user, id) {
26
+ if (!this._allowsDelete)
27
+ return this._error('BaseAdminService', 'delete', null, null, null, null, correlationId);
28
+
29
+ const validationCheckIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.idSchema, id, null, this._validationCheckKey);
30
+ if (this._hasFailed(validationCheckIdResponse))
31
+ return validationCheckIdResponse;
32
+
33
+ const respositoryResponse = await this._repository.delete(correlationId, id);
34
+ return respositoryResponse;
35
+ }
36
+
37
+ async search(correlationId, user, params) {
38
+ const validationCheckParamsResponse = this._validateSearch(correlationId, params);
39
+ if (this._hasFailed(validationCheckParamsResponse))
40
+ return validationCheckParamsResponse;
41
+
42
+ const respositoryResponse = await this._repository.search(correlationId, params);
43
+ return respositoryResponse;
44
+ }
45
+
46
+ async update(correlationId, user, id, requestedValue) {
47
+ if (!this._allowsUpdate)
48
+ return this._error('BaseAdminService', 'update', 'requestedValue', null, null, null, correlationId);
49
+
50
+ const validationResponse = this._validateUser(correlationId, user);
51
+ if (this._hasFailed(validationResponse))
52
+ return validationResponse;
53
+
54
+ const validationIdResponse = this._validateId(correlationId, id, this._validationCheckKey);
55
+ if (this._hasFailed(validationIdResponse))
56
+ return validationIdResponse;
57
+
58
+ this._logger.debug('BaseAdminService', 'update', 'requestedValue', requestedValue, correlationId);
59
+ const validationCheckValueUpdateResponse = this._validateUpdate(correlationId, requestedValue);
60
+ if (this._hasFailed(validationCheckValueUpdateResponse))
61
+ return validationCheckValueUpdateResponse;
62
+
63
+ let value = this._initializeData();
64
+ const fetchRespositoryResponse = await this._repository.fetch(correlationId, id);
65
+ if (this._hasSucceeded(fetchRespositoryResponse) && fetchRespositoryResponse.results)
66
+ value = LibraryCommonUtility.map(this._initializeData(), fetchRespositoryResponse.results, true);
67
+
68
+ const validResponse = this._checkUpdatedTimestamp(correlationId, value, requestedValue, 'value');
69
+ if (this._hasFailed(validResponse))
70
+ return validResponse;
71
+
72
+ value.map(requestedValue);
73
+
74
+ const respositoryResponse = await this._repository.update(correlationId, user.id, value);
75
+ return respositoryResponse;
76
+ }
77
+
78
+ get _allowsCreate() {
79
+ return true
80
+ }
81
+
82
+ get _allowsDelete() {
83
+ return true
84
+ }
85
+
86
+ get _allowsUpdate() {
87
+ return true
88
+ }
89
+
90
+ _initializeData() {
91
+ throw new NotImplementedError()
92
+ }
93
+
94
+ get _repository() {
95
+ throw new NotImplementedError()
96
+ }
97
+
98
+ _validateCreate(correlationId, requestedValue) {
99
+ return this._serviceValidation.check(correlationId, this._validationCreateSchema, requestedValue, null, this._validationCheckKey);
100
+ }
101
+
102
+ get _validationCreateSchema() {
103
+ throw new NotImplementedError()
104
+ }
105
+
106
+ _validateSearch(correlationId, requestedValue) {
107
+ if (this._validationSearchSchema === null)
108
+ return this._success(correlationId)
109
+
110
+ return this._serviceValidation.check(correlationId, this._validationSearchSchema, requestedValue, null, this._validationCheckKey);
111
+ }
112
+
113
+ get _validationSearchSchema() {
114
+ return null
115
+ }
116
+
117
+ _validateUpdate(correlationId, requestedValue) {
118
+ return this._serviceValidation.check(correlationId, this._validationUpdateSchema, requestedValue, null, this._validationCheckKey);
119
+ }
120
+
121
+ get _validationUpdateSchema() {
122
+ throw new NotImplementedError()
123
+ }
124
+
125
+ get _validationCheckKey() {
126
+ throw new NotImplementedError()
127
+ }
128
+ }
129
+
130
+ export default BaseAdminService;
@@ -1,6 +1,6 @@
1
- import BaseNewsAdminService from './baseNews.js';
2
-
3
- class NewsAdminService extends BaseNewsAdminService {
4
- }
5
-
6
- export default NewsAdminService;
1
+ import BaseNewsAdminService from './baseNews.js';
2
+
3
+ class NewsAdminService extends BaseNewsAdminService {
4
+ }
5
+
6
+ export default NewsAdminService;
@@ -1,107 +1,107 @@
1
- import LibraryServerConstants from '../../constants.js';
2
-
3
- import BaseAdminService from './index.js';
4
-
5
- import NotImplementedError from '@thzero/library_common/errors/notImplemented.js';
6
-
7
- class BaseUsersAdminService extends BaseAdminService {
8
- constructor() {
9
- super();
10
-
11
- this._repositoryUsers = null;
12
-
13
- this._serviceAuth = null;
14
- this._serviceUser = null;
15
- }
16
-
17
- async init(injector) {
18
- await super.init(injector);
19
-
20
- this._repositoryUsers = this._injector.getService(LibraryServerConstants.InjectorKeys.REPOSITORY_ADMIN_USERS);
21
-
22
- this._serviceAuth = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_AUTH);
23
- this._serviceUser = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
24
- }
25
-
26
- async delete(correlationId, user, id) {
27
- if (!this._allowsDelete)
28
- return this._error('BaseUsersAdminService', 'delete', null, null, null, null, correlationId);
29
-
30
- const validationCheckIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.idSchema, id, null, this._validationCheckKey);
31
- if (this._hasFailed(validationCheckIdResponse))
32
- return validationCheckIdResponse;
33
-
34
- const fetchResponse = await this._serviceUser.fetch(correlationId, id);
35
- if (this._hasFailed(fetchResponse))
36
- return fetchResponse;
37
-
38
- const response = await this._serviceAuth.deleteUser(correlationId, id);
39
- if (this._hasFailed(response))
40
- return response;
41
-
42
- const respositoryResponse = await this._repository.delete(correlationId, id);
43
- return respositoryResponse;
44
- }
45
-
46
- async update(correlationId, user, id, requestedUser) {
47
- const validationResponse = this._validateUser(correlationId, user);
48
- if (this._hasFailed(validationResponse))
49
- return validationResponse;
50
-
51
- const validationIdResponse = this._validateId(correlationId, id, 'adminUsers');
52
- if (this._hasFailed(validationIdResponse))
53
- return validationIdResponse;
54
-
55
- this._logger.debug('BaseUsersAdminService', 'update', 'requestedUser', requestedUser, correlationId);
56
- const validationCheckUsersUpdateResponse = this._serviceValidation.check(correlationId, this._serviceValidation.userUpdateSchema, requestedUser, null, this._validationCheckKey);
57
- if (this._hasFailed(validationCheckUsersUpdateResponse))
58
- return validationCheckUsersUpdateResponse;
59
-
60
- let userExisting = this._initializeData();
61
- const fetchRespositoryResponse = await this._repository.fetch(correlationId, id);
62
- if (this._hasSuceeded(fetchRespositoryResponse) && fetchRespositoryResponse.results)
63
- userExisting = Utility.map(this._initializeData(), fetchRespositoryResponse.results, true);
64
-
65
- const validResponse = this._checkUpdatedTimestamp(correlationId, userExisting, requestedUser, 'users');
66
- if (this._hasFailed(validResponse))
67
- return validResponse;
68
-
69
- userExisting.map(requestedUser);
70
-
71
- const respositoryResponse = await this._repository.update(correlationId, user.id, userExisting);
72
- if (this._hasFailed(respositoryResponse))
73
- return respositoryResponse;
74
-
75
- if (!user.external && !user.external.id)
76
- return this._error('BaseUsersAdminService', 'update', null, null, null, null, correlationId);
77
-
78
- const serviceAdminResponse = await this._serviceAuth.setClaims(correlationId, userExisting.external.id, requestedUser.roles, true)
79
- return respositoryResponse;
80
- }
81
-
82
- get _allowsCreate() {
83
- return false
84
- }
85
-
86
- get _allowsDelete() {
87
- return true
88
- }
89
-
90
- get _allowsUpdate() {
91
- return false
92
- }
93
-
94
- _initializeData() {
95
- throw new NotImplementedError();
96
- }
97
-
98
- get _repository() {
99
- return this._repositoryUsers;
100
- }
101
-
102
- get _validationCheckKey() {
103
- return 'adminUsers';
104
- }
105
- }
106
-
107
- export default BaseUsersAdminService;
1
+ import LibraryServerConstants from '../../constants.js';
2
+
3
+ import BaseAdminService from './index.js';
4
+
5
+ import NotImplementedError from '@thzero/library_common/errors/notImplemented.js';
6
+
7
+ class BaseUsersAdminService extends BaseAdminService {
8
+ constructor() {
9
+ super();
10
+
11
+ this._repositoryUsers = null;
12
+
13
+ this._serviceAuth = null;
14
+ this._serviceUser = null;
15
+ }
16
+
17
+ async init(injector) {
18
+ await super.init(injector);
19
+
20
+ this._repositoryUsers = this._injector.getService(LibraryServerConstants.InjectorKeys.REPOSITORY_ADMIN_USERS);
21
+
22
+ this._serviceAuth = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_AUTH);
23
+ this._serviceUser = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_USERS);
24
+ }
25
+
26
+ async delete(correlationId, user, id) {
27
+ if (!this._allowsDelete)
28
+ return this._error('BaseUsersAdminService', 'delete', null, null, null, null, correlationId);
29
+
30
+ const validationCheckIdResponse = this._serviceValidation.check(correlationId, this._serviceValidation.idSchema, id, null, this._validationCheckKey);
31
+ if (this._hasFailed(validationCheckIdResponse))
32
+ return validationCheckIdResponse;
33
+
34
+ const fetchResponse = await this._serviceUser.fetch(correlationId, id);
35
+ if (this._hasFailed(fetchResponse))
36
+ return fetchResponse;
37
+
38
+ const response = await this._serviceAuth.deleteUser(correlationId, id);
39
+ if (this._hasFailed(response))
40
+ return response;
41
+
42
+ const respositoryResponse = await this._repository.delete(correlationId, id);
43
+ return respositoryResponse;
44
+ }
45
+
46
+ async update(correlationId, user, id, requestedUser) {
47
+ const validationResponse = this._validateUser(correlationId, user);
48
+ if (this._hasFailed(validationResponse))
49
+ return validationResponse;
50
+
51
+ const validationIdResponse = this._validateId(correlationId, id, 'adminUsers');
52
+ if (this._hasFailed(validationIdResponse))
53
+ return validationIdResponse;
54
+
55
+ this._logger.debug('BaseUsersAdminService', 'update', 'requestedUser', requestedUser, correlationId);
56
+ const validationCheckUsersUpdateResponse = this._serviceValidation.check(correlationId, this._serviceValidation.userUpdateSchema, requestedUser, null, this._validationCheckKey);
57
+ if (this._hasFailed(validationCheckUsersUpdateResponse))
58
+ return validationCheckUsersUpdateResponse;
59
+
60
+ let userExisting = this._initializeData();
61
+ const fetchRespositoryResponse = await this._repository.fetch(correlationId, id);
62
+ if (this._hasSuceeded(fetchRespositoryResponse) && fetchRespositoryResponse.results)
63
+ userExisting = Utility.map(this._initializeData(), fetchRespositoryResponse.results, true);
64
+
65
+ const validResponse = this._checkUpdatedTimestamp(correlationId, userExisting, requestedUser, 'users');
66
+ if (this._hasFailed(validResponse))
67
+ return validResponse;
68
+
69
+ userExisting.map(requestedUser);
70
+
71
+ const respositoryResponse = await this._repository.update(correlationId, user.id, userExisting);
72
+ if (this._hasFailed(respositoryResponse))
73
+ return respositoryResponse;
74
+
75
+ if (!user.external && !user.external.id)
76
+ return this._error('BaseUsersAdminService', 'update', null, null, null, null, correlationId);
77
+
78
+ const serviceAdminResponse = await this._serviceAuth.setClaims(correlationId, userExisting.external.id, requestedUser.roles, true)
79
+ return respositoryResponse;
80
+ }
81
+
82
+ get _allowsCreate() {
83
+ return false
84
+ }
85
+
86
+ get _allowsDelete() {
87
+ return true
88
+ }
89
+
90
+ get _allowsUpdate() {
91
+ return false
92
+ }
93
+
94
+ _initializeData() {
95
+ throw new NotImplementedError();
96
+ }
97
+
98
+ get _repository() {
99
+ return this._repositoryUsers;
100
+ }
101
+
102
+ get _validationCheckKey() {
103
+ return 'adminUsers';
104
+ }
105
+ }
106
+
107
+ export default BaseUsersAdminService;