@thzero/library_server 0.15.42 → 0.15.45

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 (52) hide show
  1. package/README.md +89 -89
  2. package/boot/index.js +392 -392
  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 +57 -57
  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/package.json +38 -38
  21. package/repository/index.js +151 -151
  22. package/repository/usageMetrics/devnull.js +11 -11
  23. package/routes/index.js +76 -76
  24. package/service/admin/baseNews.js +45 -45
  25. package/service/admin/index.js +130 -130
  26. package/service/admin/news.js +6 -6
  27. package/service/admin/users.js +107 -107
  28. package/service/baseSecurity.js +44 -44
  29. package/service/baseUser.js +122 -122
  30. package/service/communication.js +6 -6
  31. package/service/config.js +32 -32
  32. package/service/crypto.js +16 -16
  33. package/service/discovery/index.js +6 -6
  34. package/service/discovery/resources/index.js +101 -101
  35. package/service/external.js +19 -19
  36. package/service/externalRest.js +19 -19
  37. package/service/index.js +20 -20
  38. package/service/monitoring.js +12 -12
  39. package/service/news/base.js +49 -49
  40. package/service/news/index.js +6 -6
  41. package/service/news/validation/index.js +6 -6
  42. package/service/plans.js +27 -27
  43. package/service/restCommunication.js +21 -21
  44. package/service/usageMetrics.js +57 -53
  45. package/service/utility.js +37 -37
  46. package/service/version.js +32 -32
  47. package/utility/injector.js +59 -59
  48. package/utility/internalIp/index.js +48 -48
  49. package/utility/list/doubleLinked.js +88 -88
  50. package/utility/list/priorityQueue.js +109 -109
  51. package/utility/list/queue.js +72 -72
  52. package/utility/os.js +22 -22
package/boot/index.js CHANGED
@@ -1,392 +1,392 @@
1
- import {internalIpV6, internalIpV4} from '@thzero/library_server/utility/internalIp';
2
-
3
- import { createTerminus } from '@godaddy/terminus';
4
-
5
- import config from 'config';
6
-
7
- import LibraryConstants from '../constants';
8
- import LibraryCommonServiceConstants from '@thzero/library_common_service/constants';
9
-
10
- import Utility from '@thzero/library_common/utility';
11
-
12
- import NotImplementedError from '@thzero/library_common/errors/notImplemented';
13
-
14
- import nullMonitoringService from '../service/monitoring';
15
-
16
- // require('@thzero/library_server/utility/string.cjs');
17
- String.isNullOrEmpty = function(value) {
18
- //return !(typeof value === 'string' && value.length > 0)
19
- return !value;
20
- }
21
-
22
- String.isString = function(value) {
23
- return (typeof value === "string" || value instanceof String);
24
- }
25
-
26
- String.trim = function(value) {
27
- if (!value || !String.isString(value))
28
- return value;
29
- return value.trim();
30
- }
31
-
32
- import injector from '@thzero/library_common/utility/injector';
33
-
34
- import usageMetricsRepository from '../repository/usageMetrics/devnull';
35
-
36
- import configService from '../service/config';
37
- import loggerService from '@thzero/library_common_service/service/logger';
38
- import usageMetricsService from '../service/usageMetrics';
39
-
40
- class BootMain {
41
- async start(...args) {
42
- process.on('uncaughtException', function(err) {
43
- console.log('Caught exception', err);
44
- return process.exit(99);
45
- });
46
-
47
- this._injector = injector;
48
-
49
- // https://github.com/lorenwest/node-config/wiki
50
- this._appConfig = new configService(config.get('app'));
51
-
52
- this._servicesPost = new Map();
53
-
54
- const plugins = this._determinePlugins(args);
55
- await await this._initPlugins(plugins);
56
-
57
- this.ip = this._appConfig.get('ip', null);
58
- this.loggerServiceI.info2(`config.ip.override: ${this.ip}`);
59
- this.port = this._appConfig.get('port');
60
- this.loggerServiceI.info2(`config.port.override: ${this.port}`);
61
- this.loggerServiceI.info2(`process.env.PORT: ${process.env.PORT}`);
62
- this.port = process.env.PORT || this.port;
63
- this.loggerServiceI.info2(`selected.port: ${this.port}`);
64
-
65
- const results = await this._initApp(args, plugins);
66
-
67
- function onSignal() {
68
- this.loggerServiceI.info2(`server is starting cleanup`);
69
- const cleanupFuncs = [];
70
- this._initCleanup(cleanupFuncs);
71
- this._initCleanupDiscovery(cleanupFuncs);
72
- return Promise.all(cleanupFuncs);
73
- }
74
-
75
- function onShutdown() {
76
- this._initShutdown();
77
- this.loggerServiceI.info2(`cleanup finished, server is shutting down`);
78
- }
79
-
80
- function healthCheck() {
81
- return Promise.resolve(
82
- // optionally include a resolve value to be included as
83
- // info in the health check response
84
- )
85
- }
86
-
87
- const healthcheckPath = this._appConfig.get('healthcheck.path', LibraryConstants.HealthCheck.DefaultPath);
88
- if (!healthcheckPath.startsWith('/'))
89
- healthcheckPath = '/' + healthcheckPath;
90
-
91
- const healthCheckOptions = {
92
- verbatim: true // [optional = false] use object returned from /healthcheck verbatim in response
93
- };
94
- if (healthCheck)
95
- healthCheckOptions[healthcheckPath] = healthCheck;
96
-
97
- const terminusOptions = {
98
- // health check options
99
- // healthChecks: {
100
- // healthcheckPath: healthCheck, // a function returning a promise indicating service health,
101
- // verbatim: true // [optional = false] use object returned from /healthcheck verbatim in response
102
- // },
103
- healthChecks: healthCheckOptions,
104
-
105
- // cleanup options
106
- signals: [ 'SIGINT', 'SIGTERM' ],
107
- onSignal: onSignal.bind(this), // [optional] cleanup function, returning a promise (used to be onSigterm)
108
- onShutdown: onShutdown.bind(this) // [optional] called right before exiting
109
- };
110
-
111
- createTerminus(results.server, terminusOptions);
112
-
113
- const self = this;
114
- const listen = async (port, address) => new Promise((resolve, reject) => {
115
- self._initAppListen(results.app, results.server, address, port, (err) => {
116
- if (err) {
117
- reject(err);
118
- return;
119
- }
120
-
121
- resolve();
122
- });
123
- });
124
- await listen(this.port, this.ip);
125
- this.address = results.server.address() ? results.server.address().address : null;
126
- if (this.address === '::')
127
- this.address = await internalIpV4();
128
-
129
- await this._initServer(results.server);
130
-
131
- for (const [key, value] of this._servicesPost) {
132
- console.log(`services.init.post - ${key}`);
133
- if (value.initPost)
134
- await value.initPost();
135
- }
136
- this._initAppPost(results.app, args);
137
-
138
- await this._initServerDiscovery(results.server);
139
-
140
- this.loggerServiceI.info2(`Starting HTTP on: `, this.address);
141
- }
142
-
143
- async _initApp(args, plugins) {
144
- throw new NotImplementedError();
145
- }
146
-
147
- _initAppListen(app, server, address, port, err) {
148
- throw new NotImplementedError();
149
- }
150
-
151
- async _initAppPost(app, args) {
152
- }
153
-
154
- _determinePlugins(args) {
155
- let obj;
156
- const results = [];
157
- for (const plugin of args) {
158
- obj = plugin;
159
- if (!this._isObject(obj))
160
- obj = new plugin();
161
- obj.init(this._appConfig, injector);
162
- results.push(obj);
163
- }
164
- return results;
165
- }
166
-
167
- async _initPlugins(plugins) {
168
- try {
169
- injector.addSingleton(LibraryCommonServiceConstants.InjectorKeys.SERVICE_CONFIG, this._appConfig);
170
-
171
- this._repositories = new Map();
172
-
173
- for (const pluginRepository of plugins)
174
- await pluginRepository.initRepositories(this._repositories);
175
-
176
- await this._initRepositories();
177
- this._injectRepository(LibraryConstants.InjectorKeys.REPOSITORY_USAGE_METRIC, this._initRepositoriesUsageMetrics());
178
-
179
- this._services = new Map();
180
-
181
- this.loggerServiceI = this._initServicesLogger();
182
- this._initServicesLoggers();
183
- this._injectService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_LOGGER, this.loggerServiceI);
184
-
185
- let monitoringService = this._initServicesMonitoring();
186
- if (!monitoringService)
187
- monitoringService = new nullMonitoringService();
188
- this._injectService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_MONITORING, monitoringService);
189
-
190
- this.usageMetricsServiceI = this._initServicesUsageMetrics();
191
- this._injectService(LibraryConstants.InjectorKeys.SERVICE_USAGE_METRIC, this.usageMetricsServiceI);
192
-
193
- this.resourceDiscoveryServiceI = this._initServicesDiscoveryResources();
194
- if (this.resourceDiscoveryServiceI)
195
- this._injectService(LibraryConstants.InjectorKeys.SERVICE_DISCOVERY_RESOURCES, this.resourceDiscoveryServiceI);
196
-
197
- this.mdnsDiscoveryServiceI = this._initServicesDiscoveryMdns();
198
- if (this.mdnsDiscoveryServiceI)
199
- this._injectService(LibraryConstants.InjectorKeys.SERVICE_DISCOVERY_MDNS, this.mdnsDiscoveryServiceI);
200
-
201
- for (const pluginService of plugins)
202
- await pluginService.initServices(this._services);
203
-
204
- await this._initServices();
205
-
206
- for (const [key, value] of this._repositories) {
207
- console.log(`repositories.init - ${key}`);
208
- await value.init(injector);
209
- }
210
-
211
- for (const [key, value] of this._services) {
212
- console.log(`services.init - ${key}`);
213
- await value.init(injector);
214
-
215
- this._servicesPost.set(key, value);
216
- }
217
-
218
- this._services = new Map();
219
-
220
- await this._initServicesSecondary();
221
-
222
- for (const pluginService of plugins)
223
- await pluginService.initServicesSecondary(this._services);
224
-
225
- for (const [key, value] of this._services) {
226
- if (value.initialized)
227
- continue;
228
-
229
- console.log(`services.init.secondary - ${key}`);
230
- await value.init(injector);
231
-
232
- this._servicesPost.set(key, value);
233
- }
234
-
235
- Utility.initDateTime();
236
- }
237
- finally {
238
- this._repositories = null;
239
- this._services = null;
240
- }
241
- }
242
-
243
- _initCleanup(cleanupFuncs) {
244
- // your clean logic, like closing database connections
245
- }
246
-
247
- _initCleanupDiscovery(cleanupFuncs) {
248
- if (this.resourceDiscoveryServiceI)
249
- cleanupFuncs.push(this.resourceDiscoveryServiceI.cleanup());
250
- if (this.mdnsDiscoveryServiceI)
251
- cleanupFuncs.push(this.mdnsDiscoveryServiceI.cleanup());
252
- }
253
-
254
- _initPostAuth(app) {
255
- }
256
-
257
- _initPreAuth(app) {
258
- }
259
-
260
- _initPostRoutes(app) {
261
- }
262
-
263
- _initPreRoutes(app) {
264
- }
265
-
266
- async _initRepositories() {
267
- }
268
-
269
- _initRepositoriesUsageMetrics() {
270
- return new usageMetricsRepository();
271
- }
272
-
273
- _initRoute(route) {
274
- }
275
-
276
- async _initRoutes() {
277
- }
278
-
279
- async _initServices() {
280
- }
281
-
282
- async _initServicesSecondary() {
283
- }
284
-
285
- _initServicesDiscoveryResources() {
286
- return null;
287
- }
288
-
289
- _initServicesDiscoveryMdns() {
290
- return null;
291
- }
292
-
293
- _initServicesLogger() {
294
- return new loggerService();
295
- }
296
-
297
- _initServicesLoggers() {
298
- throw new NotImplementedError();
299
- }
300
-
301
- _initServicesMonitoring() {
302
- return null;
303
- }
304
-
305
- _initServicesUsageMetrics() {
306
- return new usageMetricsService();
307
- }
308
-
309
- async _initServer(serverHttp) {
310
- }
311
-
312
- async _initServerDiscovery(serverHttp) {
313
- if (!this.resourceDiscoveryServiceI && !this.mdnsDiscoveryServiceI)
314
- return;
315
-
316
- const opts = await this._initServerDiscoveryOpts();
317
-
318
- await this._initServerDiscoveryMdns(Utility.cloneDeep(opts));
319
- await this._initServerDiscoveryResources(Utility.cloneDeep(opts));
320
- }
321
-
322
- async _initServerDiscoveryMdns(opts) {
323
- if (!this.mdnsDiscoveryServiceI)
324
- return;
325
-
326
- await this.mdnsDiscoveryServiceI.initialize(Utility.generateId(), await this._initServerDiscoveryOptsMdns(opts));
327
- }
328
-
329
- async _initServerDiscoveryOpts() {
330
- const dns = this._appConfig.get('dns', null);
331
- const grpc = this._appConfig.get('grpc', null);
332
- const secure = this._appConfig.get('secure', false);
333
-
334
- const opts = {
335
- address: this.address,
336
- port: this.port,
337
- healthCheck: 'healthcheck',
338
- secure: secure ? secure : false,
339
- dns: dns
340
- };
341
-
342
- if (grpc) {
343
- opts.grpc = {
344
- port: grpc ? grpc.port : null,
345
- secure: grpc ? (grpc.secure ? grpc.secure : false) : false
346
- };
347
- }
348
-
349
- return opts;
350
- }
351
-
352
- async _initServerDiscoveryOptsMdns(opts) {
353
- return opts;
354
- }
355
-
356
- async _initServerDiscoveryOptsResources(opts) {
357
- return opts;
358
- }
359
-
360
- async _initServerDiscoveryResources(opts) {
361
- if (!this.resourceDiscoveryServiceI)
362
- return;
363
-
364
- await this.resourceDiscoveryServiceI.initialize(Utility.generateId(), await this._initServerDiscoveryOptsResources(opts));
365
- }
366
-
367
- _injectRepository(key, repository) {
368
- console.log(`repositories.inject - ${key}`);
369
- this._repositories.set(key, repository);
370
- injector.addSingleton(key, repository);
371
- }
372
-
373
- _injectService(key, service) {
374
- console.log(`services.inject - ${key}`);
375
- this._services.set(key, service);
376
- injector.addSingleton(key, service);
377
- }
378
-
379
- _initShutdown() {
380
- }
381
-
382
- _isObject(objValue) {
383
- return objValue && typeof objValue === 'object';
384
- }
385
-
386
- _registerServicesLogger(key, service) {
387
- this._injectService(key, service);
388
- this.loggerServiceI.register(key);
389
- }
390
- }
391
-
392
- export default BootMain;
1
+ import {internalIpV6, internalIpV4} from '@thzero/library_server/utility/internalIp';
2
+
3
+ import { createTerminus } from '@godaddy/terminus';
4
+
5
+ import config from 'config';
6
+
7
+ import LibraryConstants from '../constants';
8
+ import LibraryCommonServiceConstants from '@thzero/library_common_service/constants';
9
+
10
+ import Utility from '@thzero/library_common/utility';
11
+
12
+ import NotImplementedError from '@thzero/library_common/errors/notImplemented';
13
+
14
+ import nullMonitoringService from '../service/monitoring';
15
+
16
+ // require('@thzero/library_server/utility/string.cjs');
17
+ String.isNullOrEmpty = function(value) {
18
+ //return !(typeof value === 'string' && value.length > 0)
19
+ return !value;
20
+ }
21
+
22
+ String.isString = function(value) {
23
+ return (typeof value === "string" || value instanceof String);
24
+ }
25
+
26
+ String.trim = function(value) {
27
+ if (!value || !String.isString(value))
28
+ return value;
29
+ return value.trim();
30
+ }
31
+
32
+ import injector from '@thzero/library_common/utility/injector';
33
+
34
+ import usageMetricsRepository from '../repository/usageMetrics/devnull';
35
+
36
+ import configService from '../service/config';
37
+ import loggerService from '@thzero/library_common_service/service/logger';
38
+ import usageMetricsService from '../service/usageMetrics';
39
+
40
+ class BootMain {
41
+ async start(...args) {
42
+ process.on('uncaughtException', function(err) {
43
+ console.log('Caught exception', err);
44
+ return process.exit(99);
45
+ });
46
+
47
+ this._injector = injector;
48
+
49
+ // https://github.com/lorenwest/node-config/wiki
50
+ this._appConfig = new configService(config.get('app'));
51
+
52
+ this._servicesPost = new Map();
53
+
54
+ const plugins = this._determinePlugins(args);
55
+ await await this._initPlugins(plugins);
56
+
57
+ this.ip = this._appConfig.get('ip', null);
58
+ this.loggerServiceI.info2(`config.ip.override: ${this.ip}`);
59
+ this.port = this._appConfig.get('port');
60
+ this.loggerServiceI.info2(`config.port.override: ${this.port}`);
61
+ this.loggerServiceI.info2(`process.env.PORT: ${process.env.PORT}`);
62
+ this.port = process.env.PORT || this.port;
63
+ this.loggerServiceI.info2(`selected.port: ${this.port}`);
64
+
65
+ const results = await this._initApp(args, plugins);
66
+
67
+ function onSignal() {
68
+ this.loggerServiceI.info2(`server is starting cleanup`);
69
+ const cleanupFuncs = [];
70
+ this._initCleanup(cleanupFuncs);
71
+ this._initCleanupDiscovery(cleanupFuncs);
72
+ return Promise.all(cleanupFuncs);
73
+ }
74
+
75
+ function onShutdown() {
76
+ this._initShutdown();
77
+ this.loggerServiceI.info2(`cleanup finished, server is shutting down`);
78
+ }
79
+
80
+ function healthCheck() {
81
+ return Promise.resolve(
82
+ // optionally include a resolve value to be included as
83
+ // info in the health check response
84
+ )
85
+ }
86
+
87
+ const healthcheckPath = this._appConfig.get('healthcheck.path', LibraryConstants.HealthCheck.DefaultPath);
88
+ if (!healthcheckPath.startsWith('/'))
89
+ healthcheckPath = '/' + healthcheckPath;
90
+
91
+ const healthCheckOptions = {
92
+ verbatim: true // [optional = false] use object returned from /healthcheck verbatim in response
93
+ };
94
+ if (healthCheck)
95
+ healthCheckOptions[healthcheckPath] = healthCheck;
96
+
97
+ const terminusOptions = {
98
+ // health check options
99
+ // healthChecks: {
100
+ // healthcheckPath: healthCheck, // a function returning a promise indicating service health,
101
+ // verbatim: true // [optional = false] use object returned from /healthcheck verbatim in response
102
+ // },
103
+ healthChecks: healthCheckOptions,
104
+
105
+ // cleanup options
106
+ signals: [ 'SIGINT', 'SIGTERM' ],
107
+ onSignal: onSignal.bind(this), // [optional] cleanup function, returning a promise (used to be onSigterm)
108
+ onShutdown: onShutdown.bind(this) // [optional] called right before exiting
109
+ };
110
+
111
+ createTerminus(results.server, terminusOptions);
112
+
113
+ const self = this;
114
+ const listen = async (port, address) => new Promise((resolve, reject) => {
115
+ self._initAppListen(results.app, results.server, address, port, (err) => {
116
+ if (err) {
117
+ reject(err);
118
+ return;
119
+ }
120
+
121
+ resolve();
122
+ });
123
+ });
124
+ await listen(this.port, this.ip);
125
+ this.address = results.server.address() ? results.server.address().address : null;
126
+ if (this.address === '::')
127
+ this.address = await internalIpV4();
128
+
129
+ await this._initServer(results.server);
130
+
131
+ for (const [key, value] of this._servicesPost) {
132
+ console.log(`services.init.post - ${key}`);
133
+ if (value.initPost)
134
+ await value.initPost();
135
+ }
136
+ this._initAppPost(results.app, args);
137
+
138
+ await this._initServerDiscovery(results.server);
139
+
140
+ this.loggerServiceI.info2(`Starting HTTP on: `, this.address);
141
+ }
142
+
143
+ async _initApp(args, plugins) {
144
+ throw new NotImplementedError();
145
+ }
146
+
147
+ _initAppListen(app, server, address, port, err) {
148
+ throw new NotImplementedError();
149
+ }
150
+
151
+ async _initAppPost(app, args) {
152
+ }
153
+
154
+ _determinePlugins(args) {
155
+ let obj;
156
+ const results = [];
157
+ for (const plugin of args) {
158
+ obj = plugin;
159
+ if (!this._isObject(obj))
160
+ obj = new plugin();
161
+ obj.init(this._appConfig, injector);
162
+ results.push(obj);
163
+ }
164
+ return results;
165
+ }
166
+
167
+ async _initPlugins(plugins) {
168
+ try {
169
+ injector.addSingleton(LibraryCommonServiceConstants.InjectorKeys.SERVICE_CONFIG, this._appConfig);
170
+
171
+ this._repositories = new Map();
172
+
173
+ for (const pluginRepository of plugins)
174
+ await pluginRepository.initRepositories(this._repositories);
175
+
176
+ await this._initRepositories();
177
+ this._injectRepository(LibraryConstants.InjectorKeys.REPOSITORY_USAGE_METRIC, this._initRepositoriesUsageMetrics());
178
+
179
+ this._services = new Map();
180
+
181
+ this.loggerServiceI = this._initServicesLogger();
182
+ this._initServicesLoggers();
183
+ this._injectService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_LOGGER, this.loggerServiceI);
184
+
185
+ let monitoringService = this._initServicesMonitoring();
186
+ if (!monitoringService)
187
+ monitoringService = new nullMonitoringService();
188
+ this._injectService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_MONITORING, monitoringService);
189
+
190
+ this.usageMetricsServiceI = this._initServicesUsageMetrics();
191
+ this._injectService(LibraryConstants.InjectorKeys.SERVICE_USAGE_METRIC, this.usageMetricsServiceI);
192
+
193
+ this.resourceDiscoveryServiceI = this._initServicesDiscoveryResources();
194
+ if (this.resourceDiscoveryServiceI)
195
+ this._injectService(LibraryConstants.InjectorKeys.SERVICE_DISCOVERY_RESOURCES, this.resourceDiscoveryServiceI);
196
+
197
+ this.mdnsDiscoveryServiceI = this._initServicesDiscoveryMdns();
198
+ if (this.mdnsDiscoveryServiceI)
199
+ this._injectService(LibraryConstants.InjectorKeys.SERVICE_DISCOVERY_MDNS, this.mdnsDiscoveryServiceI);
200
+
201
+ for (const pluginService of plugins)
202
+ await pluginService.initServices(this._services);
203
+
204
+ await this._initServices();
205
+
206
+ for (const [key, value] of this._repositories) {
207
+ console.log(`repositories.init - ${key}`);
208
+ await value.init(injector);
209
+ }
210
+
211
+ for (const [key, value] of this._services) {
212
+ console.log(`services.init - ${key}`);
213
+ await value.init(injector);
214
+
215
+ this._servicesPost.set(key, value);
216
+ }
217
+
218
+ this._services = new Map();
219
+
220
+ await this._initServicesSecondary();
221
+
222
+ for (const pluginService of plugins)
223
+ await pluginService.initServicesSecondary(this._services);
224
+
225
+ for (const [key, value] of this._services) {
226
+ if (value.initialized)
227
+ continue;
228
+
229
+ console.log(`services.init.secondary - ${key}`);
230
+ await value.init(injector);
231
+
232
+ this._servicesPost.set(key, value);
233
+ }
234
+
235
+ Utility.initDateTime();
236
+ }
237
+ finally {
238
+ this._repositories = null;
239
+ this._services = null;
240
+ }
241
+ }
242
+
243
+ _initCleanup(cleanupFuncs) {
244
+ // your clean logic, like closing database connections
245
+ }
246
+
247
+ _initCleanupDiscovery(cleanupFuncs) {
248
+ if (this.resourceDiscoveryServiceI)
249
+ cleanupFuncs.push(this.resourceDiscoveryServiceI.cleanup());
250
+ if (this.mdnsDiscoveryServiceI)
251
+ cleanupFuncs.push(this.mdnsDiscoveryServiceI.cleanup());
252
+ }
253
+
254
+ _initPostAuth(app) {
255
+ }
256
+
257
+ _initPreAuth(app) {
258
+ }
259
+
260
+ _initPostRoutes(app) {
261
+ }
262
+
263
+ _initPreRoutes(app) {
264
+ }
265
+
266
+ async _initRepositories() {
267
+ }
268
+
269
+ _initRepositoriesUsageMetrics() {
270
+ return new usageMetricsRepository();
271
+ }
272
+
273
+ _initRoute(route) {
274
+ }
275
+
276
+ async _initRoutes() {
277
+ }
278
+
279
+ async _initServices() {
280
+ }
281
+
282
+ async _initServicesSecondary() {
283
+ }
284
+
285
+ _initServicesDiscoveryResources() {
286
+ return null;
287
+ }
288
+
289
+ _initServicesDiscoveryMdns() {
290
+ return null;
291
+ }
292
+
293
+ _initServicesLogger() {
294
+ return new loggerService();
295
+ }
296
+
297
+ _initServicesLoggers() {
298
+ throw new NotImplementedError();
299
+ }
300
+
301
+ _initServicesMonitoring() {
302
+ return null;
303
+ }
304
+
305
+ _initServicesUsageMetrics() {
306
+ return new usageMetricsService();
307
+ }
308
+
309
+ async _initServer(serverHttp) {
310
+ }
311
+
312
+ async _initServerDiscovery(serverHttp) {
313
+ if (!this.resourceDiscoveryServiceI && !this.mdnsDiscoveryServiceI)
314
+ return;
315
+
316
+ const opts = await this._initServerDiscoveryOpts();
317
+
318
+ await this._initServerDiscoveryMdns(Utility.cloneDeep(opts));
319
+ await this._initServerDiscoveryResources(Utility.cloneDeep(opts));
320
+ }
321
+
322
+ async _initServerDiscoveryMdns(opts) {
323
+ if (!this.mdnsDiscoveryServiceI)
324
+ return;
325
+
326
+ await this.mdnsDiscoveryServiceI.initialize(Utility.generateId(), await this._initServerDiscoveryOptsMdns(opts));
327
+ }
328
+
329
+ async _initServerDiscoveryOpts() {
330
+ const dns = this._appConfig.get('dns', null);
331
+ const grpc = this._appConfig.get('grpc', null);
332
+ const secure = this._appConfig.get('secure', false);
333
+
334
+ const opts = {
335
+ address: this.address,
336
+ port: this.port,
337
+ healthCheck: 'healthcheck',
338
+ secure: secure ? secure : false,
339
+ dns: dns
340
+ };
341
+
342
+ if (grpc) {
343
+ opts.grpc = {
344
+ port: grpc ? grpc.port : null,
345
+ secure: grpc ? (grpc.secure ? grpc.secure : false) : false
346
+ };
347
+ }
348
+
349
+ return opts;
350
+ }
351
+
352
+ async _initServerDiscoveryOptsMdns(opts) {
353
+ return opts;
354
+ }
355
+
356
+ async _initServerDiscoveryOptsResources(opts) {
357
+ return opts;
358
+ }
359
+
360
+ async _initServerDiscoveryResources(opts) {
361
+ if (!this.resourceDiscoveryServiceI)
362
+ return;
363
+
364
+ await this.resourceDiscoveryServiceI.initialize(Utility.generateId(), await this._initServerDiscoveryOptsResources(opts));
365
+ }
366
+
367
+ _injectRepository(key, repository) {
368
+ console.log(`repositories.inject - ${key}`);
369
+ this._repositories.set(key, repository);
370
+ injector.addSingleton(key, repository);
371
+ }
372
+
373
+ _injectService(key, service) {
374
+ console.log(`services.inject - ${key}`);
375
+ this._services.set(key, service);
376
+ injector.addSingleton(key, service);
377
+ }
378
+
379
+ _initShutdown() {
380
+ }
381
+
382
+ _isObject(objValue) {
383
+ return objValue && typeof objValue === 'object';
384
+ }
385
+
386
+ _registerServicesLogger(key, service) {
387
+ this._injectService(key, service);
388
+ this.loggerServiceI.register(key);
389
+ }
390
+ }
391
+
392
+ export default BootMain;