@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/usageMetrics.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import LibraryServerConstants from '../constants.js';
|
|
2
|
-
|
|
3
|
-
import LibraryCommonUtility from '@thzero/library_common/utility/index.js';
|
|
4
|
-
|
|
5
|
-
import Service from './index.js';
|
|
6
|
-
|
|
7
|
-
class UsageMetricsService extends Service {
|
|
8
|
-
constructor() {
|
|
9
|
-
super();
|
|
10
|
-
|
|
11
|
-
this._ignore = [];
|
|
12
|
-
|
|
13
|
-
this._repositoryUsageMetricsI = null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async init(injector) {
|
|
17
|
-
await super.init(injector);
|
|
18
|
-
|
|
19
|
-
this._repositoryUsageMetricsI = this._injector.getService(LibraryServerConstants.InjectorKeys.REPOSITORY_USAGE_METRIC);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async register(usageMetrics, err) {
|
|
23
|
-
try {
|
|
24
|
-
if (!usageMetrics)
|
|
25
|
-
return;
|
|
26
|
-
|
|
27
|
-
const url = usageMetrics.url;
|
|
28
|
-
if (!String.isNullOrEmpty(url)) {
|
|
29
|
-
for (const ignore of this._ignore) {
|
|
30
|
-
if (url === ignore)
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
usageMetrics.date = new Date(new Date(LibraryCommonUtility.getTimestamp()).toISOString());
|
|
36
|
-
|
|
37
|
-
await this._repositoryUsageMetrics.register(usageMetrics);
|
|
38
|
-
return this._success(usageMetrics.correlationId);
|
|
39
|
-
}
|
|
40
|
-
catch (err) {
|
|
41
|
-
this._logger.exception('UsageMetricsService', 'register', err);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
registerIgnore(url) {
|
|
46
|
-
if (this._ignore[url])
|
|
47
|
-
return;
|
|
48
|
-
|
|
49
|
-
this._ignore.push(url);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
get _repositoryUsageMetrics() {
|
|
53
|
-
return this._injector.getService(LibraryServerConstants.InjectorKeys.REPOSITORY_USAGE_METRIC)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export default UsageMetricsService;
|
|
1
|
+
import LibraryServerConstants from '../constants.js';
|
|
2
|
+
|
|
3
|
+
import LibraryCommonUtility from '@thzero/library_common/utility/index.js';
|
|
4
|
+
|
|
5
|
+
import Service from './index.js';
|
|
6
|
+
|
|
7
|
+
class UsageMetricsService extends Service {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
|
|
11
|
+
this._ignore = [];
|
|
12
|
+
|
|
13
|
+
this._repositoryUsageMetricsI = null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async init(injector) {
|
|
17
|
+
await super.init(injector);
|
|
18
|
+
|
|
19
|
+
this._repositoryUsageMetricsI = this._injector.getService(LibraryServerConstants.InjectorKeys.REPOSITORY_USAGE_METRIC);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async register(usageMetrics, err) {
|
|
23
|
+
try {
|
|
24
|
+
if (!usageMetrics)
|
|
25
|
+
return;
|
|
26
|
+
|
|
27
|
+
const url = usageMetrics.url;
|
|
28
|
+
if (!String.isNullOrEmpty(url)) {
|
|
29
|
+
for (const ignore of this._ignore) {
|
|
30
|
+
if (url === ignore)
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
usageMetrics.date = new Date(new Date(LibraryCommonUtility.getTimestamp()).toISOString());
|
|
36
|
+
|
|
37
|
+
await this._repositoryUsageMetrics.register(usageMetrics);
|
|
38
|
+
return this._success(usageMetrics.correlationId);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
this._logger.exception('UsageMetricsService', 'register', err);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
registerIgnore(url) {
|
|
46
|
+
if (this._ignore[url])
|
|
47
|
+
return;
|
|
48
|
+
|
|
49
|
+
this._ignore.push(url);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get _repositoryUsageMetrics() {
|
|
53
|
+
return this._injector.getService(LibraryServerConstants.InjectorKeys.REPOSITORY_USAGE_METRIC)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default UsageMetricsService;
|
package/service/utility.js
CHANGED
|
@@ -1,177 +1,177 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { Mutex as asyncMutex } from 'async-mutex';
|
|
4
|
-
|
|
5
|
-
import LibraryServerConstants from '@thzero/library_server/constants.js';
|
|
6
|
-
|
|
7
|
-
import LibraryCommonUtility from '@thzero/library_common/utility/index.js';
|
|
8
|
-
|
|
9
|
-
import Service from './index.js';
|
|
10
|
-
|
|
11
|
-
class UtilityService extends Service {
|
|
12
|
-
constructor() {
|
|
13
|
-
super();
|
|
14
|
-
|
|
15
|
-
this._servicePlans = null;
|
|
16
|
-
this._serviceVersion = null;
|
|
17
|
-
|
|
18
|
-
this._openSourceResponse = null;
|
|
19
|
-
|
|
20
|
-
this._initializeResponse = null;
|
|
21
|
-
this._mutexInitialize = new asyncMutex();
|
|
22
|
-
this._ttlInitialize = null;
|
|
23
|
-
this._ttlInitializeDiff = 1000 * 30;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async init(injector) {
|
|
27
|
-
await super.init(injector);
|
|
28
|
-
|
|
29
|
-
this._servicePlans = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_PLANS);
|
|
30
|
-
this._serviceVersion = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_VERSION);
|
|
31
|
-
|
|
32
|
-
await this._initializeOopenSource();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async initialize(correlationId) {
|
|
36
|
-
const now = LibraryCommonUtility.getTimestamp();
|
|
37
|
-
const ttlInitialize = this._ttlInitialize ? this._ttlInitialize : 0;
|
|
38
|
-
const delta = now - ttlInitialize;
|
|
39
|
-
if (this._initializeResponse && (delta <= this._ttlInitializeDiff))
|
|
40
|
-
return this._initializeResponse;
|
|
41
|
-
|
|
42
|
-
const release = await this._mutexInitialize.acquire();
|
|
43
|
-
try {
|
|
44
|
-
if (this._initializeResponse)
|
|
45
|
-
return this._initializeResponse;
|
|
46
|
-
|
|
47
|
-
const response = this._initResponse(correlationId);
|
|
48
|
-
response.results = {};
|
|
49
|
-
|
|
50
|
-
const responsePlans = await this._servicePlans.listing(correlationId);
|
|
51
|
-
if (this._hasFailed(responsePlans))
|
|
52
|
-
return responsePlans;
|
|
53
|
-
|
|
54
|
-
response.results.plans = responsePlans.results;
|
|
55
|
-
|
|
56
|
-
const responseVersion = await this._serviceVersion.version(correlationId);
|
|
57
|
-
if (this._hasFailed(responseVersion))
|
|
58
|
-
return responseVersion;
|
|
59
|
-
|
|
60
|
-
response.results.version = responseVersion.results;
|
|
61
|
-
|
|
62
|
-
await this._intialize(correlationId, response);
|
|
63
|
-
|
|
64
|
-
this._ttlInitialize = LibraryCommonUtility.getTimestamp();
|
|
65
|
-
this._initializeResponse = response;
|
|
66
|
-
return response;
|
|
67
|
-
}
|
|
68
|
-
finally {
|
|
69
|
-
release();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async logger(content, correlationId) {
|
|
74
|
-
if (!content)
|
|
75
|
-
return this._error('UtilityService', 'logger');
|
|
76
|
-
|
|
77
|
-
const type = content.type;
|
|
78
|
-
switch(type) {
|
|
79
|
-
case 'DEBUG':
|
|
80
|
-
this._logger.debug('UtilityService', 'logger', content.message, content.data, correlationId, true);
|
|
81
|
-
break;
|
|
82
|
-
case 'ERROR':
|
|
83
|
-
this._logger.error('UtilityService', 'logger', content.message, content.data, correlationId, true);
|
|
84
|
-
break;
|
|
85
|
-
case 'EXCEPTION':
|
|
86
|
-
this._logger.exception('UtilityService', 'logger', content.ex, correlationId, true);
|
|
87
|
-
break;
|
|
88
|
-
case 'FATAL':
|
|
89
|
-
this._logger.fatal('UtilityService', 'logger', content.message, content.data, correlationId, true);
|
|
90
|
-
break;
|
|
91
|
-
case 'INFO':
|
|
92
|
-
this._logger.info('UtilityService', 'logger', content.message, content.data, correlationId, true);
|
|
93
|
-
break;
|
|
94
|
-
case 'TRACE':
|
|
95
|
-
this._logger.trace('UtilityService', 'logger', content.message, content.data, correlationId, true);
|
|
96
|
-
break;
|
|
97
|
-
case 'WARN':
|
|
98
|
-
this._logger.warn('UtilityService', 'logger', content.message, content.data, correlationId, true);
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return this._success(correlationId);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async openSource(correlationId) {
|
|
106
|
-
return this._openSourceResponse ? this._openSourceResponse : this._error();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
_intialize(correlationId, response) {
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async _initializeOopenSource(correlationId) {
|
|
113
|
-
this._openSourceResponse = this._initResponse(correlationId);
|
|
114
|
-
this._openSourceResponse.results = [];
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
const __dirname = path.resolve();
|
|
118
|
-
const dir = path.join(path.resolve(__dirname), 'node_modules', '@thzero');
|
|
119
|
-
const dirs = await fs.promises.readdir(dir);
|
|
120
|
-
|
|
121
|
-
console.log(`\tOpenSource...`);
|
|
122
|
-
|
|
123
|
-
let file;
|
|
124
|
-
let importPath;
|
|
125
|
-
let fileI;
|
|
126
|
-
let items;
|
|
127
|
-
for (const item of dirs) {
|
|
128
|
-
try {
|
|
129
|
-
file = path.join(dir, item, 'openSource.js');
|
|
130
|
-
console.log(`\t${file}...`);
|
|
131
|
-
if (!fs.existsSync(file)){
|
|
132
|
-
console.log(`\t...not found.`);
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
importPath = ['@thzero', item, 'openSource.js'].join('/');
|
|
137
|
-
console.log(`\t${importPath}...`);
|
|
138
|
-
fileI = await import(importPath);
|
|
139
|
-
if (!fileI.default) {
|
|
140
|
-
console.log(`\t...failed to load.`);
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
items = fileI.default();
|
|
145
|
-
items.forEach(element => {
|
|
146
|
-
if (element.category !== 'server')
|
|
147
|
-
return;
|
|
148
|
-
if (this._openSourceResponse.results.filter(l => l.name === element.name).length > 0)
|
|
149
|
-
return;
|
|
150
|
-
this._openSourceResponse.results.push(element);
|
|
151
|
-
});
|
|
152
|
-
console.log(`\t...processed.`);
|
|
153
|
-
}
|
|
154
|
-
catch(err) {
|
|
155
|
-
console.log(`\t...failed.`, err);
|
|
156
|
-
this._logger.warn('UtilityService', '_initializeOopenSource', null, err, correlationId);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
catch(err) {
|
|
161
|
-
this._logger.warn('UtilityService', '_initializeOopenSource', null, err, correlationId);
|
|
162
|
-
}
|
|
163
|
-
finally {
|
|
164
|
-
console.log(`\t...OpenSource`);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// response.results = await this._openSourceServer(correlationId);
|
|
168
|
-
this._openSource(correlationId, this._openSourceResponse.results);
|
|
169
|
-
|
|
170
|
-
this._openSourceResponse.results = this._openSourceResponse.results.sort((a, b) => a.name.localeCompare(b.name));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
_openSource(correlationId, openSource) {
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export default UtilityService;
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { Mutex as asyncMutex } from 'async-mutex';
|
|
4
|
+
|
|
5
|
+
import LibraryServerConstants from '@thzero/library_server/constants.js';
|
|
6
|
+
|
|
7
|
+
import LibraryCommonUtility from '@thzero/library_common/utility/index.js';
|
|
8
|
+
|
|
9
|
+
import Service from './index.js';
|
|
10
|
+
|
|
11
|
+
class UtilityService extends Service {
|
|
12
|
+
constructor() {
|
|
13
|
+
super();
|
|
14
|
+
|
|
15
|
+
this._servicePlans = null;
|
|
16
|
+
this._serviceVersion = null;
|
|
17
|
+
|
|
18
|
+
this._openSourceResponse = null;
|
|
19
|
+
|
|
20
|
+
this._initializeResponse = null;
|
|
21
|
+
this._mutexInitialize = new asyncMutex();
|
|
22
|
+
this._ttlInitialize = null;
|
|
23
|
+
this._ttlInitializeDiff = 1000 * 30;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async init(injector) {
|
|
27
|
+
await super.init(injector);
|
|
28
|
+
|
|
29
|
+
this._servicePlans = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_PLANS);
|
|
30
|
+
this._serviceVersion = this._injector.getService(LibraryServerConstants.InjectorKeys.SERVICE_VERSION);
|
|
31
|
+
|
|
32
|
+
await this._initializeOopenSource();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async initialize(correlationId) {
|
|
36
|
+
const now = LibraryCommonUtility.getTimestamp();
|
|
37
|
+
const ttlInitialize = this._ttlInitialize ? this._ttlInitialize : 0;
|
|
38
|
+
const delta = now - ttlInitialize;
|
|
39
|
+
if (this._initializeResponse && (delta <= this._ttlInitializeDiff))
|
|
40
|
+
return this._initializeResponse;
|
|
41
|
+
|
|
42
|
+
const release = await this._mutexInitialize.acquire();
|
|
43
|
+
try {
|
|
44
|
+
if (this._initializeResponse)
|
|
45
|
+
return this._initializeResponse;
|
|
46
|
+
|
|
47
|
+
const response = this._initResponse(correlationId);
|
|
48
|
+
response.results = {};
|
|
49
|
+
|
|
50
|
+
const responsePlans = await this._servicePlans.listing(correlationId);
|
|
51
|
+
if (this._hasFailed(responsePlans))
|
|
52
|
+
return responsePlans;
|
|
53
|
+
|
|
54
|
+
response.results.plans = responsePlans.results;
|
|
55
|
+
|
|
56
|
+
const responseVersion = await this._serviceVersion.version(correlationId);
|
|
57
|
+
if (this._hasFailed(responseVersion))
|
|
58
|
+
return responseVersion;
|
|
59
|
+
|
|
60
|
+
response.results.version = responseVersion.results;
|
|
61
|
+
|
|
62
|
+
await this._intialize(correlationId, response);
|
|
63
|
+
|
|
64
|
+
this._ttlInitialize = LibraryCommonUtility.getTimestamp();
|
|
65
|
+
this._initializeResponse = response;
|
|
66
|
+
return response;
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
release();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async logger(content, correlationId) {
|
|
74
|
+
if (!content)
|
|
75
|
+
return this._error('UtilityService', 'logger');
|
|
76
|
+
|
|
77
|
+
const type = content.type;
|
|
78
|
+
switch(type) {
|
|
79
|
+
case 'DEBUG':
|
|
80
|
+
this._logger.debug('UtilityService', 'logger', content.message, content.data, correlationId, true);
|
|
81
|
+
break;
|
|
82
|
+
case 'ERROR':
|
|
83
|
+
this._logger.error('UtilityService', 'logger', content.message, content.data, correlationId, true);
|
|
84
|
+
break;
|
|
85
|
+
case 'EXCEPTION':
|
|
86
|
+
this._logger.exception('UtilityService', 'logger', content.ex, correlationId, true);
|
|
87
|
+
break;
|
|
88
|
+
case 'FATAL':
|
|
89
|
+
this._logger.fatal('UtilityService', 'logger', content.message, content.data, correlationId, true);
|
|
90
|
+
break;
|
|
91
|
+
case 'INFO':
|
|
92
|
+
this._logger.info('UtilityService', 'logger', content.message, content.data, correlationId, true);
|
|
93
|
+
break;
|
|
94
|
+
case 'TRACE':
|
|
95
|
+
this._logger.trace('UtilityService', 'logger', content.message, content.data, correlationId, true);
|
|
96
|
+
break;
|
|
97
|
+
case 'WARN':
|
|
98
|
+
this._logger.warn('UtilityService', 'logger', content.message, content.data, correlationId, true);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return this._success(correlationId);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async openSource(correlationId) {
|
|
106
|
+
return this._openSourceResponse ? this._openSourceResponse : this._error();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
_intialize(correlationId, response) {
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async _initializeOopenSource(correlationId) {
|
|
113
|
+
this._openSourceResponse = this._initResponse(correlationId);
|
|
114
|
+
this._openSourceResponse.results = [];
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
const __dirname = path.resolve();
|
|
118
|
+
const dir = path.join(path.resolve(__dirname), 'node_modules', '@thzero');
|
|
119
|
+
const dirs = await fs.promises.readdir(dir);
|
|
120
|
+
|
|
121
|
+
console.log(`\tOpenSource...`);
|
|
122
|
+
|
|
123
|
+
let file;
|
|
124
|
+
let importPath;
|
|
125
|
+
let fileI;
|
|
126
|
+
let items;
|
|
127
|
+
for (const item of dirs) {
|
|
128
|
+
try {
|
|
129
|
+
file = path.join(dir, item, 'openSource.js');
|
|
130
|
+
console.log(`\t${file}...`);
|
|
131
|
+
if (!fs.existsSync(file)){
|
|
132
|
+
console.log(`\t...not found.`);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
importPath = ['@thzero', item, 'openSource.js'].join('/');
|
|
137
|
+
console.log(`\t${importPath}...`);
|
|
138
|
+
fileI = await import(importPath);
|
|
139
|
+
if (!fileI.default) {
|
|
140
|
+
console.log(`\t...failed to load.`);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
items = fileI.default();
|
|
145
|
+
items.forEach(element => {
|
|
146
|
+
if (element.category !== 'server')
|
|
147
|
+
return;
|
|
148
|
+
if (this._openSourceResponse.results.filter(l => l.name === element.name).length > 0)
|
|
149
|
+
return;
|
|
150
|
+
this._openSourceResponse.results.push(element);
|
|
151
|
+
});
|
|
152
|
+
console.log(`\t...processed.`);
|
|
153
|
+
}
|
|
154
|
+
catch(err) {
|
|
155
|
+
console.log(`\t...failed.`, err);
|
|
156
|
+
this._logger.warn('UtilityService', '_initializeOopenSource', null, err, correlationId);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch(err) {
|
|
161
|
+
this._logger.warn('UtilityService', '_initializeOopenSource', null, err, correlationId);
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
console.log(`\t...OpenSource`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// response.results = await this._openSourceServer(correlationId);
|
|
168
|
+
this._openSource(correlationId, this._openSourceResponse.results);
|
|
169
|
+
|
|
170
|
+
this._openSourceResponse.results = this._openSourceResponse.results.sort((a, b) => a.name.localeCompare(b.name));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
_openSource(correlationId, openSource) {
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export default UtilityService;
|
package/service/version.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import Service from './index.js';
|
|
5
|
-
|
|
6
|
-
class VersionService extends Service {
|
|
7
|
-
async version(correlationId) {
|
|
8
|
-
const filePath = path.join(process.cwd(), 'package.json');
|
|
9
|
-
const file = fs.readFileSync(filePath, 'utf8');
|
|
10
|
-
if (String.isNullOrEmpty(file))
|
|
11
|
-
throw Error('Invalid package.json file for versioning; expected in the <app root> folder.');
|
|
12
|
-
|
|
13
|
-
const packageObj = JSON.parse(file);
|
|
14
|
-
if (!packageObj)
|
|
15
|
-
throw Error('Invalid package.json file for versioning.');
|
|
16
|
-
|
|
17
|
-
return this._generate(correlationId, packageObj.version_major, packageObj.version_minor, packageObj.version_patch, packageObj.version_date);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
_generate(correlationId, version_major, version_minor, version_patch, version_date) {
|
|
21
|
-
const response = this._success(correlationId);
|
|
22
|
-
response.results = {
|
|
23
|
-
major: version_major,
|
|
24
|
-
minor: version_minor,
|
|
25
|
-
patch: version_patch,
|
|
26
|
-
date: version_date
|
|
27
|
-
};
|
|
28
|
-
return response;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default VersionService;
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
import Service from './index.js';
|
|
5
|
+
|
|
6
|
+
class VersionService extends Service {
|
|
7
|
+
async version(correlationId) {
|
|
8
|
+
const filePath = path.join(process.cwd(), 'package.json');
|
|
9
|
+
const file = fs.readFileSync(filePath, 'utf8');
|
|
10
|
+
if (String.isNullOrEmpty(file))
|
|
11
|
+
throw Error('Invalid package.json file for versioning; expected in the <app root> folder.');
|
|
12
|
+
|
|
13
|
+
const packageObj = JSON.parse(file);
|
|
14
|
+
if (!packageObj)
|
|
15
|
+
throw Error('Invalid package.json file for versioning.');
|
|
16
|
+
|
|
17
|
+
return this._generate(correlationId, packageObj.version_major, packageObj.version_minor, packageObj.version_patch, packageObj.version_date);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
_generate(correlationId, version_major, version_minor, version_patch, version_date) {
|
|
21
|
+
const response = this._success(correlationId);
|
|
22
|
+
response.results = {
|
|
23
|
+
major: version_major,
|
|
24
|
+
minor: version_minor,
|
|
25
|
+
patch: version_patch,
|
|
26
|
+
date: version_date
|
|
27
|
+
};
|
|
28
|
+
return response;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default VersionService;
|
package/utility/injector.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
class Injector {
|
|
2
|
-
constructor() {
|
|
3
|
-
this._di = {};
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
addService(key, dependency) {
|
|
7
|
-
if (String.isNullOrEmpty(key))
|
|
8
|
-
throw Error(`Invalid injector key '${key}'.`);
|
|
9
|
-
if (!dependency)
|
|
10
|
-
throw Error('Invalid injector dependency.');
|
|
11
|
-
|
|
12
|
-
if (this._di[key])
|
|
13
|
-
return;
|
|
14
|
-
|
|
15
|
-
this._di[key] = { dependency: dependency };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
addSingleton(key, dependency) {
|
|
19
|
-
if (String.isNullOrEmpty(key))
|
|
20
|
-
throw Error(`Invalid injector key '${key}'.`);
|
|
21
|
-
if (!dependency)
|
|
22
|
-
throw Error('Invalid injector dependency.');
|
|
23
|
-
|
|
24
|
-
if (this._di[key])
|
|
25
|
-
return;
|
|
26
|
-
|
|
27
|
-
this._di[key] = { key: key, singleton: true, dependency: dependency };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getInjector() {
|
|
31
|
-
return this._di;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getService(key, args) {
|
|
35
|
-
if (String.isNullOrEmpty(key))
|
|
36
|
-
throw Error(`Invalid injector key '${key}'.`);
|
|
37
|
-
|
|
38
|
-
const result = this._di[key];
|
|
39
|
-
if (!result)
|
|
40
|
-
return null;
|
|
41
|
-
|
|
42
|
-
if (result.singleton)
|
|
43
|
-
return result.dependency;
|
|
44
|
-
|
|
45
|
-
return new result.dependency.prototype.constructor(args);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getServices() {
|
|
49
|
-
return Object.values(this._di);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getSingletons() {
|
|
53
|
-
return Object.values(this._di).filter(l => l.singleton).map(l => l.dependency);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const singletonInstance = new Injector();
|
|
58
|
-
Object.freeze(singletonInstance);
|
|
59
|
-
export default singletonInstance;
|
|
1
|
+
class Injector {
|
|
2
|
+
constructor() {
|
|
3
|
+
this._di = {};
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
addService(key, dependency) {
|
|
7
|
+
if (String.isNullOrEmpty(key))
|
|
8
|
+
throw Error(`Invalid injector key '${key}'.`);
|
|
9
|
+
if (!dependency)
|
|
10
|
+
throw Error('Invalid injector dependency.');
|
|
11
|
+
|
|
12
|
+
if (this._di[key])
|
|
13
|
+
return;
|
|
14
|
+
|
|
15
|
+
this._di[key] = { dependency: dependency };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
addSingleton(key, dependency) {
|
|
19
|
+
if (String.isNullOrEmpty(key))
|
|
20
|
+
throw Error(`Invalid injector key '${key}'.`);
|
|
21
|
+
if (!dependency)
|
|
22
|
+
throw Error('Invalid injector dependency.');
|
|
23
|
+
|
|
24
|
+
if (this._di[key])
|
|
25
|
+
return;
|
|
26
|
+
|
|
27
|
+
this._di[key] = { key: key, singleton: true, dependency: dependency };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getInjector() {
|
|
31
|
+
return this._di;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getService(key, args) {
|
|
35
|
+
if (String.isNullOrEmpty(key))
|
|
36
|
+
throw Error(`Invalid injector key '${key}'.`);
|
|
37
|
+
|
|
38
|
+
const result = this._di[key];
|
|
39
|
+
if (!result)
|
|
40
|
+
return null;
|
|
41
|
+
|
|
42
|
+
if (result.singleton)
|
|
43
|
+
return result.dependency;
|
|
44
|
+
|
|
45
|
+
return new result.dependency.prototype.constructor(args);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getServices() {
|
|
49
|
+
return Object.values(this._di);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getSingletons() {
|
|
53
|
+
return Object.values(this._di).filter(l => l.singleton).map(l => l.dependency);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const singletonInstance = new Injector();
|
|
58
|
+
Object.freeze(singletonInstance);
|
|
59
|
+
export default singletonInstance;
|