@futdevpro/nts-dynamo 1.6.59 → 1.7.1

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 (80) hide show
  1. package/lib/_constants/mocks/app-extended-server.mock.js +8 -13
  2. package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -1
  3. package/lib/_constants/mocks/app-server.mock.js +4 -9
  4. package/lib/_constants/mocks/app-server.mock.js.map +1 -1
  5. package/lib/_constants/mocks/auth-service.mock.js +3 -10
  6. package/lib/_constants/mocks/auth-service.mock.js.map +1 -1
  7. package/lib/_constants/mocks/data-model.mock.js +17 -0
  8. package/lib/_constants/mocks/data-model.mock.js.map +1 -1
  9. package/lib/_constants/mocks/email-service-collection.mock.js +1 -4
  10. package/lib/_constants/mocks/email-service-collection.mock.js.map +1 -1
  11. package/lib/_constants/mocks/endpoint.mock.js +12 -13
  12. package/lib/_constants/mocks/endpoint.mock.js.map +1 -1
  13. package/lib/_constants/mocks/socket-client.mock.js +2 -3
  14. package/lib/_constants/mocks/socket-client.mock.js.map +1 -1
  15. package/lib/_constants/mocks/socket-server.mock.js +2 -5
  16. package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
  17. package/lib/_models/control-models/api-call-params.control-model.js +32 -0
  18. package/lib/_models/control-models/api-call-params.control-model.js.map +1 -1
  19. package/lib/_models/control-models/app-params.control-model.js +31 -4
  20. package/lib/_models/control-models/app-params.control-model.js.map +1 -1
  21. package/lib/_models/control-models/app-system-controls.control-model copy.js +3 -5
  22. package/lib/_models/control-models/app-system-controls.control-model copy.js.map +1 -1
  23. package/lib/_models/control-models/app-system-controls.control-model.js +4 -6
  24. package/lib/_models/control-models/app-system-controls.control-model.js.map +1 -1
  25. package/lib/_models/control-models/endpoint-params.control-model.js +91 -88
  26. package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
  27. package/lib/_models/control-models/socket-client-service-params.control-model.js +8 -5
  28. package/lib/_models/control-models/socket-client-service-params.control-model.js.map +1 -1
  29. package/lib/_models/control-models/socket-event.control-model.js +35 -34
  30. package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
  31. package/lib/_models/control-models/socket-presence.control-model.js +10 -9
  32. package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
  33. package/lib/_models/control-models/socket-server-service-params.control-model.js +3 -0
  34. package/lib/_models/control-models/socket-server-service-params.control-model.js.map +1 -1
  35. package/lib/_models/control-models/system-control.control-model.js +3 -5
  36. package/lib/_models/control-models/system-control.control-model.js.map +1 -1
  37. package/lib/_modules/custom-data/custom-data.controller.js +6 -7
  38. package/lib/_modules/custom-data/custom-data.controller.js.map +1 -1
  39. package/lib/_modules/test/test.controller.js +12 -13
  40. package/lib/_modules/test/test.controller.js.map +1 -1
  41. package/lib/_modules/usage/usage.controller.js +15 -14
  42. package/lib/_modules/usage/usage.controller.js.map +1 -1
  43. package/lib/_modules/usage/usage.data-service.js +88 -96
  44. package/lib/_modules/usage/usage.data-service.js.map +1 -1
  45. package/lib/_services/base/data.service.js +370 -295
  46. package/lib/_services/base/data.service.js.map +1 -1
  47. package/lib/_services/base/db.service.js +315 -246
  48. package/lib/_services/base/db.service.js.map +1 -1
  49. package/lib/_services/base/singleton.service.js +2 -0
  50. package/lib/_services/base/singleton.service.js.map +1 -1
  51. package/lib/_services/core/api.service.js +185 -188
  52. package/lib/_services/core/api.service.js.map +1 -1
  53. package/lib/_services/core/auth.service.js +3 -3
  54. package/lib/_services/core/auth.service.js.map +1 -1
  55. package/lib/_services/core/email.service.js +103 -88
  56. package/lib/_services/core/email.service.js.map +1 -1
  57. package/lib/_services/core/global.service.js +38 -40
  58. package/lib/_services/core/global.service.js.map +1 -1
  59. package/lib/_services/route/controller.service.js +28 -0
  60. package/lib/_services/route/controller.service.js.map +1 -1
  61. package/lib/_services/route/routing-module.service.js +11 -8
  62. package/lib/_services/route/routing-module.service.js.map +1 -1
  63. package/lib/_services/server/app-extended.server.js +241 -247
  64. package/lib/_services/server/app-extended.server.js.map +1 -1
  65. package/lib/_services/server/app-extended.server.spec.js +18 -19
  66. package/lib/_services/server/app-extended.server.spec.js.map +1 -1
  67. package/lib/_services/server/app.server.js +404 -412
  68. package/lib/_services/server/app.server.js.map +1 -1
  69. package/lib/_services/server/app.server.spec.js +12 -13
  70. package/lib/_services/server/app.server.spec.js.map +1 -1
  71. package/lib/_services/shared.static-service.js +15 -17
  72. package/lib/_services/shared.static-service.js.map +1 -1
  73. package/lib/_services/socket/socket-client.service.js +134 -145
  74. package/lib/_services/socket/socket-client.service.js.map +1 -1
  75. package/lib/_services/socket/socket-server.service.js +294 -263
  76. package/lib/_services/socket/socket-server.service.js.map +1 -1
  77. package/lib/tsconfig.tsbuildinfo +1 -1
  78. package/nodemon.json +12 -5
  79. package/package.json +24 -24
  80. package/tsconfig.json +2 -2
@@ -169,25 +169,39 @@ const app_system_controls_control_model_1 = require("../../_models/control-model
169
169
  *
170
170
  */
171
171
  class DynamoNTS_App extends singleton_service_1.DynamoNTS_SingletonService {
172
+ systemControls = new app_system_controls_control_model_1.DynamoNTS_AppSystemControls();
172
173
  get started() { return this.systemControls.app.started; }
173
174
  get superStarted() { return this.systemControls.app.started; }
175
+ constructErrors = [];
174
176
  get serverName() { return this.params.name; }
177
+ _params;
175
178
  get params() { return this._params; }
179
+ mongoose = Mongoose;
180
+ _security;
176
181
  get security() { return this._security; }
182
+ _ports;
177
183
  get ports() { return this._ports; }
184
+ _cert;
178
185
  get cert() { return this._cert; }
186
+ openExpress;
187
+ secureExpress;
188
+ httpsServer;
189
+ httpServer;
190
+ globalService;
191
+ _rootServices = [];
192
+ _routingModules = [];
193
+ /**
194
+ * setting this value to true, enables this service debug logs
195
+ */
196
+ logSetup;
197
+ deepLog;
198
+ logFn;
179
199
  constructor(extended) {
180
200
  super();
181
- this.systemControls = new app_system_controls_control_model_1.DynamoNTS_AppSystemControls();
182
- this.constructErrors = [];
183
- this.mongoose = Mongoose;
184
- this._rootServices = [];
185
- this._routingModules = [];
186
201
  process.on('unhandledRejection', (reason, p) => {
187
- var _a;
188
202
  fsm_dynamo_1.Dynamo_Log.highlightedError('Unhandled Rejection at: ', p, '\nRejection reason:', reason);
189
203
  try {
190
- (_a = global_service_1.DynamoNTS_GlobalService.globalErrorHandler) === null || _a === void 0 ? void 0 : _a.call(global_service_1.DynamoNTS_GlobalService, new fsm_dynamo_1.Dynamo_Error({
204
+ global_service_1.DynamoNTS_GlobalService.globalErrorHandler?.(new fsm_dynamo_1.Dynamo_Error({
191
205
  errorCode: 'NTS-AS0-BASE-UR',
192
206
  message: 'Unhandled Rejection!',
193
207
  error: new Error(p),
@@ -201,469 +215,447 @@ class DynamoNTS_App extends singleton_service_1.DynamoNTS_SingletonService {
201
215
  fsm_dynamo_1.Dynamo_Log.error(`\nApplication: ${this._params.name} start failed.\n`, error);
202
216
  });
203
217
  }
204
- asyncConstruct(extended) {
205
- var _a, _b, _c, _d, _e;
206
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
207
- if (this.logFn && this.deepLog)
208
- console.log('\nfn:. asyncConstruct');
209
- try {
210
- this.systemControls.app.init = true;
211
- this._params = this.getAppParams();
212
- fsm_dynamo_1.dynamo_error_default.issuerSystem = this._params.systemName;
213
- (_a = this.overrideDynamoNTSGlobalSettings) === null || _a === void 0 ? void 0 : _a.call(this);
214
- this.logSetup = global_settings_const_1.dynamoNTS_globalSettings.logSetup;
215
- this.globalService = global_service_1.DynamoNTS_GlobalService.getInstance();
216
- global_service_1.DynamoNTS_GlobalService.setServices(this.getGlobalServiceCollection());
217
- global_service_1.DynamoNTS_GlobalService.setParams(this.params);
218
- global_service_1.DynamoNTS_GlobalService.setGlobalErrorHandler((_b = this.getGlobalErrorHandler) === null || _b === void 0 ? void 0 : _b.call(this));
219
- if (this.getPortSettings) {
220
- this._ports = this.getPortSettings();
221
- }
222
- if (this.getCertificationSettings) {
223
- this._cert = this.getCertificationSettings();
224
- }
225
- if (this.getRoutingModules) {
226
- this._routingModules = this.getRoutingModules();
218
+ async asyncConstruct(extended) {
219
+ if (this.logFn && this.deepLog)
220
+ console.log('\nfn:. asyncConstruct');
221
+ try {
222
+ this.systemControls.app.init = true;
223
+ this._params = this.getAppParams();
224
+ fsm_dynamo_1.dynamo_error_default.issuerSystem = this._params.systemName;
225
+ this.overrideDynamoNTSGlobalSettings?.();
226
+ this.logSetup = global_settings_const_1.dynamoNTS_globalSettings.logSetup;
227
+ this.globalService = global_service_1.DynamoNTS_GlobalService.getInstance();
228
+ global_service_1.DynamoNTS_GlobalService.setServices(this.getGlobalServiceCollection());
229
+ global_service_1.DynamoNTS_GlobalService.setParams(this.params);
230
+ global_service_1.DynamoNTS_GlobalService.setGlobalErrorHandler(this.getGlobalErrorHandler?.());
231
+ if (this.getPortSettings) {
232
+ this._ports = this.getPortSettings();
233
+ }
234
+ if (this.getCertificationSettings) {
235
+ this._cert = this.getCertificationSettings();
236
+ }
237
+ if (this.getRoutingModules) {
238
+ this._routingModules = this.getRoutingModules();
239
+ }
240
+ await this.createEntries?.();
241
+ console.log(`\n\n\nStarting ${this._params.name}... `);
242
+ await this.startDB();
243
+ this.setSecurity();
244
+ if (this._routingModules?.length) {
245
+ await this.initExpresses();
246
+ await this.startExpresses();
247
+ if (this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
248
+ await this.mountOpenRoutes();
227
249
  }
228
- yield ((_c = this.createEntries) === null || _c === void 0 ? void 0 : _c.call(this));
229
- console.log(`\n\n\nStarting ${this._params.name}... `);
230
- yield this.startDB();
231
- this.setSecurity();
232
- if ((_d = this._routingModules) === null || _d === void 0 ? void 0 : _d.length) {
233
- yield this.initExpresses();
234
- yield this.startExpresses();
235
- if (this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
236
- yield this.mountOpenRoutes();
237
- }
238
- if (this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open && this._cert) {
239
- yield this.mountSecureRoutes();
240
- }
241
- if (this.logSetup) {
242
- console.log(`\nRoutes mounted.... server using security: ${this._security}`);
243
- }
250
+ if (this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open && this._cert) {
251
+ await this.mountSecureRoutes();
244
252
  }
245
- if (this.getRootServices) {
246
- this._rootServices = yield this.getRootServices();
253
+ if (this.logSetup) {
254
+ console.log(`\nRoutes mounted.... server using security: ${this._security}`);
247
255
  }
248
- yield ((_e = this.postProcess) === null || _e === void 0 ? void 0 : _e.call(this));
249
- if (!extended) {
250
- yield this.ready();
251
- if (this.params.title) {
252
- console.log(this.params.title);
253
- console.log(`Version: ${this.params.version}`);
254
- }
255
- fsm_dynamo_1.Dynamo_Log.H_success(`${this.params.name} started successfully.`);
256
+ }
257
+ if (this.getRootServices) {
258
+ this._rootServices = await this.getRootServices();
259
+ }
260
+ await this.postProcess?.();
261
+ if (!extended) {
262
+ await this.ready();
263
+ if (this.params.title) {
264
+ console.log(this.params.title);
265
+ console.log(`Version: ${this.params.version}`);
256
266
  }
267
+ fsm_dynamo_1.Dynamo_Log.H_success(`${this.params.name} started successfully.`);
257
268
  }
258
- catch (error) {
259
- this.constructErrors.push(error);
260
- fsm_dynamo_1.Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
261
- throw new fsm_dynamo_1.Dynamo_Error({
262
- errorCode: 'NTS-AS0-001',
263
- error: error,
264
- additionalContent: {
265
- constructErrors: this.constructErrors,
266
- systemControls: this.systemControls,
267
- systemReadies: {
268
- app: this.systemControls.app.getReady(),
269
- mongoose: this.systemControls.mongoose.getReady(),
270
- httpServer: this.systemControls.httpServer.getReady(),
271
- httpsServer: this.systemControls.httpsServer.getReady(),
272
- },
269
+ }
270
+ catch (error) {
271
+ this.constructErrors.push(error);
272
+ fsm_dynamo_1.Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
273
+ throw new fsm_dynamo_1.Dynamo_Error({
274
+ errorCode: 'NTS-AS0-001',
275
+ error: error,
276
+ additionalContent: {
277
+ constructErrors: this.constructErrors,
278
+ systemControls: this.systemControls,
279
+ systemReadies: {
280
+ app: this.systemControls.app.getReady(),
281
+ mongoose: this.systemControls.mongoose.getReady(),
282
+ httpServer: this.systemControls.httpServer.getReady(),
283
+ httpsServer: this.systemControls.httpsServer.getReady(),
273
284
  },
274
- });
275
- }
276
- });
285
+ },
286
+ });
287
+ }
277
288
  }
278
- ready(timeout = 4 * fsm_dynamo_1.second) {
279
- var _a, _b;
280
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
281
- if (this.logFn)
282
- console.log('\nfn:. ready');
283
- let ready = false;
284
- const start = +new Date();
285
- if (this.constructErrors.length) {
286
- fsm_dynamo_1.Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
287
- throw new fsm_dynamo_1.Dynamo_Error({
288
- message: `${this._params.name} start failed. ERRORS`,
289
- additionalContent: this.constructErrors.length === 1 ? this.constructErrors[0] : { errors: this.constructErrors },
290
- });
289
+ async ready(timeout = 4 * fsm_dynamo_1.second) {
290
+ if (this.logFn)
291
+ console.log('\nfn:. ready');
292
+ let ready = false;
293
+ const start = +new Date();
294
+ if (this.constructErrors.length) {
295
+ fsm_dynamo_1.Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
296
+ throw new fsm_dynamo_1.Dynamo_Error({
297
+ message: `${this._params.name} start failed. ERRORS`,
298
+ additionalContent: this.constructErrors.length === 1 ? this.constructErrors[0] : { errors: this.constructErrors },
299
+ });
300
+ }
301
+ while (!ready && +new Date() - start < timeout) {
302
+ if (this.systemControls.app.init) {
303
+ ready = (this.systemControls.mongoose.getReady() &&
304
+ this.systemControls.httpServer.getReady() &&
305
+ this.systemControls.httpsServer.getReady());
291
306
  }
292
- while (!ready && +new Date() - start < timeout) {
293
- if (this.systemControls.app.init) {
294
- ready = (this.systemControls.mongoose.getReady() &&
295
- this.systemControls.httpServer.getReady() &&
296
- this.systemControls.httpsServer.getReady());
297
- }
298
- else {
299
- fsm_dynamo_1.Dynamo_Log.error(`${this.params.name} APP NOT INITIALIZED while trying to get ready.`);
300
- }
301
- if (!ready) {
302
- yield (0, fsm_dynamo_1.wait)(100);
303
- }
307
+ else {
308
+ fsm_dynamo_1.Dynamo_Log.error(`${this.params.name} APP NOT INITIALIZED while trying to get ready.`);
304
309
  }
305
- if (timeout < +new Date() - start) {
306
- fsm_dynamo_1.Dynamo_Log.error(`${this._params.name} start failed. TIMEOUT`, this.constructErrors);
307
- throw new fsm_dynamo_1.Dynamo_Error({
308
- message: `${this._params.name} start failed. TIMEOUT`,
309
- additionalContent: {
310
- constructErrors: this.constructErrors,
311
- systemControls: this.systemControls,
312
- systemReadies: {
313
- mongoose: this.systemControls.mongoose.getReady(),
314
- httpServer: this.systemControls.httpServer.getReady(),
315
- httpsServer: this.systemControls.httpsServer.getReady(),
316
- },
310
+ if (!ready) {
311
+ await (0, fsm_dynamo_1.wait)(100);
312
+ }
313
+ }
314
+ if (timeout < +new Date() - start) {
315
+ fsm_dynamo_1.Dynamo_Log.error(`${this._params.name} start failed. TIMEOUT`, this.constructErrors);
316
+ throw new fsm_dynamo_1.Dynamo_Error({
317
+ message: `${this._params.name} start failed. TIMEOUT`,
318
+ additionalContent: {
319
+ constructErrors: this.constructErrors,
320
+ systemControls: this.systemControls,
321
+ systemReadies: {
322
+ mongoose: this.systemControls.mongoose.getReady(),
323
+ httpServer: this.systemControls.httpServer.getReady(),
324
+ httpsServer: this.systemControls.httpsServer.getReady(),
317
325
  },
318
- });
326
+ },
327
+ });
328
+ }
329
+ if (this.constructErrors.length) {
330
+ fsm_dynamo_1.Dynamo_Log.error(`${this._params.name} start failed. ERROR`, this.constructErrors);
331
+ throw new fsm_dynamo_1.Dynamo_Error({
332
+ message: `${this._params.name} start failed. ERROR`,
333
+ additionalContent: this.constructErrors,
334
+ });
335
+ }
336
+ if (ready) {
337
+ this.systemControls.app.started = true;
338
+ if (this.logFn && this.deepLog)
339
+ console.log('\nfn:. ready: return');
340
+ return;
341
+ }
342
+ else {
343
+ this.systemControls.app.started = false;
344
+ let msg = `${this._params.name} start failed. UNKNOWN`;
345
+ if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
346
+ msg += `\nMongoose start failed.`;
319
347
  }
320
- if (this.constructErrors.length) {
321
- fsm_dynamo_1.Dynamo_Log.error(`${this._params.name} start failed. ERROR`, this.constructErrors);
322
- throw new fsm_dynamo_1.Dynamo_Error({
323
- message: `${this._params.name} start failed. ERROR`,
324
- additionalContent: this.constructErrors,
325
- });
348
+ if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
349
+ msg += `\nHTTP Server start failed.`;
326
350
  }
327
- if (ready) {
328
- this.systemControls.app.started = true;
329
- if (this.logFn && this.deepLog)
330
- console.log('\nfn:. ready: return');
331
- return;
351
+ if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
352
+ msg += `\nHTTPS Server start failed.`;
332
353
  }
333
- else {
334
- this.systemControls.app.started = false;
335
- let msg = `${this._params.name} start failed. UNKNOWN`;
336
- if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
337
- msg += `\nMongoose start failed.`;
338
- }
339
- if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
340
- msg += `\nHTTP Server start failed.`;
354
+ fsm_dynamo_1.Dynamo_Log.error(msg, this.constructErrors);
355
+ throw new fsm_dynamo_1.Dynamo_Error({
356
+ errorCode: 'NTS-AS0-110',
357
+ message: msg,
358
+ additionalContent: {
359
+ constructErrors: this.constructErrors,
360
+ systemControls: this.systemControls,
361
+ systemReadies: {
362
+ app: this.systemControls.app.getReady(),
363
+ mongoose: this.systemControls.mongoose.getReady(),
364
+ httpServer: this.systemControls.httpServer.getReady(),
365
+ httpsServer: this.systemControls.httpsServer.getReady(),
366
+ },
367
+ },
368
+ error: this.constructErrors?.[0] ?? new Error(),
369
+ });
370
+ }
371
+ }
372
+ async stop(dontLog) {
373
+ if (this.logFn)
374
+ console.log('\nfn:. stop');
375
+ if (this.started) {
376
+ if (this.systemControls.mongoose.init) {
377
+ this.systemControls.mongoose.started = false;
378
+ if (this.mongoose) {
379
+ await fsm_dynamo_1.Dynamo_Array.asyncForEach(Object.keys(this.mongoose.models), async (modelName) => {
380
+ await this.mongoose.deleteModel(modelName);
381
+ });
382
+ await this.mongoose.disconnect();
341
383
  }
342
- if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
343
- msg += `\nHTTPS Server start failed.`;
384
+ else {
385
+ fsm_dynamo_1.Dynamo_Log.error(`\nMongoose not found.`);
344
386
  }
345
- fsm_dynamo_1.Dynamo_Log.error(msg, this.constructErrors);
346
- throw new fsm_dynamo_1.Dynamo_Error({
347
- errorCode: 'NTS-AS0-110',
348
- message: msg,
349
- additionalContent: {
350
- constructErrors: this.constructErrors,
351
- systemControls: this.systemControls,
352
- systemReadies: {
353
- app: this.systemControls.app.getReady(),
354
- mongoose: this.systemControls.mongoose.getReady(),
355
- httpServer: this.systemControls.httpServer.getReady(),
356
- httpsServer: this.systemControls.httpsServer.getReady(),
357
- },
358
- },
359
- error: (_b = (_a = this.constructErrors) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : new Error(),
360
- });
387
+ this.systemControls.mongoose.init = false;
361
388
  }
362
- });
363
- }
364
- stop(dontLog) {
365
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
366
- if (this.logFn)
367
- console.log('\nfn:. stop');
368
- if (this.started) {
369
- if (this.systemControls.mongoose.init) {
370
- this.systemControls.mongoose.started = false;
371
- if (this.mongoose) {
372
- yield fsm_dynamo_1.Dynamo_Array.asyncForEach(Object.keys(this.mongoose.models), (modelName) => tslib_1.__awaiter(this, void 0, void 0, function* () {
373
- yield this.mongoose.deleteModel(modelName);
374
- }));
375
- yield this.mongoose.disconnect();
376
- }
377
- else {
378
- fsm_dynamo_1.Dynamo_Log.error(`\nMongoose not found.`);
379
- }
380
- this.systemControls.mongoose.init = false;
389
+ if (this.systemControls.httpServer.init) {
390
+ this.systemControls.httpServer.started = false;
391
+ if (this.httpServer) {
392
+ await new Promise((resolve) => {
393
+ this.httpServer.close(resolve);
394
+ });
381
395
  }
382
- if (this.systemControls.httpServer.init) {
383
- this.systemControls.httpServer.started = false;
384
- if (this.httpServer) {
385
- yield new Promise((resolve) => {
386
- this.httpServer.close(resolve);
387
- });
388
- }
389
- else {
390
- fsm_dynamo_1.Dynamo_Log.error(`\nHTTP Server not found.`);
391
- }
392
- this.systemControls.httpServer.init = false;
396
+ else {
397
+ fsm_dynamo_1.Dynamo_Log.error(`\nHTTP Server not found.`);
393
398
  }
394
- if (this.systemControls.httpsServer.init) {
395
- this.systemControls.httpsServer.started = false;
396
- if (this.httpsServer) {
397
- yield new Promise((resolve) => {
398
- this.httpsServer.close(resolve);
399
- });
400
- }
401
- else {
402
- fsm_dynamo_1.Dynamo_Log.error(`\nHTTPS Server not found.`);
403
- }
404
- this.systemControls.httpsServer.init = false;
399
+ this.systemControls.httpServer.init = false;
400
+ }
401
+ if (this.systemControls.httpsServer.init) {
402
+ this.systemControls.httpsServer.started = false;
403
+ if (this.httpsServer) {
404
+ await new Promise((resolve) => {
405
+ this.httpsServer.close(resolve);
406
+ });
405
407
  }
406
- if (!dontLog) {
407
- fsm_dynamo_1.Dynamo_Log.H_log(`${this._params.name} stopped successfully.`);
408
+ else {
409
+ fsm_dynamo_1.Dynamo_Log.error(`\nHTTPS Server not found.`);
408
410
  }
411
+ this.systemControls.httpsServer.init = false;
409
412
  }
410
- });
413
+ if (!dontLog) {
414
+ fsm_dynamo_1.Dynamo_Log.H_log(`${this._params.name} stopped successfully.`);
415
+ }
416
+ }
411
417
  }
412
418
  /**
413
419
  *
414
420
  */
415
- startDB() {
416
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
417
- if (this.logFn && this.deepLog)
418
- console.log('\nfn:. startDB');
419
- yield new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
420
- this.systemControls.mongoose.init = true;
421
- this.mongoose.connection
422
- .on('error', (error) => {
423
- this.systemControls.mongoose.started = false;
424
- this.constructErrors.push(error);
425
- fsm_dynamo_1.Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
426
- reject(new fsm_dynamo_1.Dynamo_Error({
427
- errorCode: 'NTS-AS0-100',
428
- message: `Unable to connect to MongoDB server, ERROR: ${error}`,
429
- error: error,
430
- }));
431
- })
432
- .once('open', () => {
433
- this.systemControls.mongoose.started = true;
434
- fsm_dynamo_1.Dynamo_Log.success('\nConnected to MongoDB\n');
435
- resolve();
436
- });
437
- this.mongoose.connect(this._params.dbUri, {
438
- useNewUrlParser: true,
439
- useUnifiedTopology: true
440
- });
441
- }));
421
+ async startDB() {
422
+ if (this.logFn && this.deepLog)
423
+ console.log('\nfn:. startDB');
424
+ await new Promise(async (resolve, reject) => {
425
+ this.systemControls.mongoose.init = true;
426
+ this.mongoose.connection
427
+ .on('error', (error) => {
428
+ this.systemControls.mongoose.started = false;
429
+ this.constructErrors.push(error);
430
+ fsm_dynamo_1.Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
431
+ reject(new fsm_dynamo_1.Dynamo_Error({
432
+ errorCode: 'NTS-AS0-100',
433
+ message: `Unable to connect to MongoDB server, ERROR: ${error}`,
434
+ error: error,
435
+ }));
436
+ })
437
+ .once('open', () => {
438
+ this.systemControls.mongoose.started = true;
439
+ fsm_dynamo_1.Dynamo_Log.success('\nConnected to MongoDB\n');
440
+ resolve();
441
+ });
442
+ this.mongoose.connect(this._params.dbUri, {
443
+ useNewUrlParser: true,
444
+ useUnifiedTopology: true
445
+ });
442
446
  });
443
447
  }
444
448
  /**
445
449
  *
446
450
  */
447
- initExpresses() {
448
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
449
- if (this.logFn && this.deepLog)
450
- console.log('\nfn:. initExpresses');
451
- if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
452
- if (!this._ports.httpPort) {
453
- let errorMsg = `\nYou have open routes, but httpPort is not set!` +
454
- `\nsecurity: ${this._security}` +
455
- `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
456
- errorMsg += '\n\nThe routes setted to use open server:';
457
- this._routingModules.forEach((module) => {
458
- if (module.security != route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
459
- errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using open sever:`;
460
- module.endpoints.forEach((endpoint) => {
461
- if (endpoint.security != route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
462
- errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
463
- }
464
- });
465
- }
466
- });
467
- let error = new Error('Open routes cannot be established!');
468
- let errorStack = error.stack.split('\n');
469
- errorStack.splice(1, 2);
470
- error.stack = errorStack.join('\n');
471
- fsm_dynamo_1.Dynamo_Log.error(errorMsg);
472
- throw error;
473
- }
474
- yield this.initOpenExpress();
451
+ async initExpresses() {
452
+ if (this.logFn && this.deepLog)
453
+ console.log('\nfn:. initExpresses');
454
+ if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
455
+ if (!this._ports.httpPort) {
456
+ let errorMsg = `\nYou have open routes, but httpPort is not set!` +
457
+ `\nsecurity: ${this._security}` +
458
+ `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
459
+ errorMsg += '\n\nThe routes setted to use open server:';
460
+ this._routingModules.forEach((module) => {
461
+ if (module.security != route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
462
+ errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using open sever:`;
463
+ module.endpoints.forEach((endpoint) => {
464
+ if (endpoint.security != route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
465
+ errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
466
+ }
467
+ });
468
+ }
469
+ });
470
+ let error = new Error('Open routes cannot be established!');
471
+ let errorStack = error.stack.split('\n');
472
+ errorStack.splice(1, 2);
473
+ error.stack = errorStack.join('\n');
474
+ fsm_dynamo_1.Dynamo_Log.error(errorMsg);
475
+ throw error;
475
476
  }
476
- if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
477
- if (!this._cert || !this._ports.httpsPort) {
478
- let errorMsg = `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
479
- `\nsecurity: ${this._security}` +
480
- `\nset...` +
481
- `\n httpsPort and` +
482
- `\n cert: {` +
483
- `\n keyPath: FileSystem.PathLike,` +
484
- `\n certPath: FileSystem.PathLike,` +
485
- `\n }` +
486
- `\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
487
- errorMsg += '\n\nThe routes setted to use secure server:';
488
- this._routingModules.forEach((module) => {
489
- if (module.security && module.security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
490
- errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using secure sever:`;
491
- module.endpoints.forEach((endpoint) => {
492
- if (endpoint.security && endpoint.security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
493
- errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
494
- }
495
- });
496
- }
497
- });
498
- let error = new Error('Secure routes cannot be established!');
499
- let errorStack = error.stack.split('\n');
500
- errorStack.splice(1, 2);
501
- error.stack = errorStack.join('\n');
502
- fsm_dynamo_1.Dynamo_Log.error(errorMsg);
503
- throw error;
504
- }
505
- yield this.initSecureExpress();
477
+ await this.initOpenExpress();
478
+ }
479
+ if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
480
+ if (!this._cert || !this._ports.httpsPort) {
481
+ let errorMsg = `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
482
+ `\nsecurity: ${this._security}` +
483
+ `\nset...` +
484
+ `\n httpsPort and` +
485
+ `\n cert: {` +
486
+ `\n keyPath: FileSystem.PathLike,` +
487
+ `\n certPath: FileSystem.PathLike,` +
488
+ `\n }` +
489
+ `\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
490
+ errorMsg += '\n\nThe routes setted to use secure server:';
491
+ this._routingModules.forEach((module) => {
492
+ if (module.security && module.security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
493
+ errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using secure sever:`;
494
+ module.endpoints.forEach((endpoint) => {
495
+ if (endpoint.security && endpoint.security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
496
+ errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
497
+ }
498
+ });
499
+ }
500
+ });
501
+ let error = new Error('Secure routes cannot be established!');
502
+ let errorStack = error.stack.split('\n');
503
+ errorStack.splice(1, 2);
504
+ error.stack = errorStack.join('\n');
505
+ fsm_dynamo_1.Dynamo_Log.error(errorMsg);
506
+ throw error;
506
507
  }
507
- });
508
+ await this.initSecureExpress();
509
+ }
508
510
  }
509
511
  /**
510
512
  *
511
513
  */
512
- initOpenExpress() {
513
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
514
- if (this.logFn)
515
- console.log('\nfn:. initOpenExpress');
516
- this.openExpress = Express();
517
- this.openExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
518
- this.openExpress.use(BodyParser.json({ limit: '50mb' }));
519
- });
514
+ async initOpenExpress() {
515
+ if (this.logFn)
516
+ console.log('\nfn:. initOpenExpress');
517
+ this.openExpress = Express();
518
+ this.openExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
519
+ this.openExpress.use(BodyParser.json({ limit: '50mb' }));
520
520
  }
521
521
  /**
522
522
  *
523
523
  */
524
- initSecureExpress() {
525
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
526
- if (this.logFn)
527
- console.log('\nfn:. initSecureExpress');
528
- this.secureExpress = Express();
529
- this.secureExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
530
- this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
531
- const options = {
532
- key: FileSystem.readFileSync(this._cert.keyPath),
533
- cert: FileSystem.readFileSync(this._cert.certPath),
534
- };
535
- this.httpsServer = Https.createServer(options, this.secureExpress);
536
- });
524
+ async initSecureExpress() {
525
+ if (this.logFn)
526
+ console.log('\nfn:. initSecureExpress');
527
+ this.secureExpress = Express();
528
+ this.secureExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
529
+ this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
530
+ const options = {
531
+ key: FileSystem.readFileSync(this._cert.keyPath),
532
+ cert: FileSystem.readFileSync(this._cert.certPath),
533
+ };
534
+ this.httpsServer = Https.createServer(options, this.secureExpress);
537
535
  }
538
536
  /**
539
537
  *
540
538
  */
541
- startExpresses() {
542
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
543
- if (this.logFn && this.deepLog)
544
- console.log('\nfn:. startExpresses');
545
- try {
546
- if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
547
- yield new Promise((resolve, reject) => {
548
- this.systemControls.httpsServer.init = true;
549
- this.httpsServer
550
- .listen(this._ports.httpsPort, 'localhost', 0, () => {
551
- this.systemControls.httpsServer.started = true;
552
- fsm_dynamo_1.Dynamo_Log.success(`\nHTTPS (secure) server is listening on port: ${this._ports.httpsPort}`);
553
- resolve();
554
- })
555
- .on('error', (error) => {
556
- this.systemControls.httpsServer.started = false;
557
- this.constructErrors.push(error);
558
- fsm_dynamo_1.Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
559
- reject(new fsm_dynamo_1.Dynamo_Error({
560
- errorCode: 'NTS-AS0-001',
561
- message: `HTTPS (secure) server ERROR`,
562
- error: error,
563
- }));
564
- })
565
- .on('uncaughtException', (ex) => {
566
- fsm_dynamo_1.Dynamo_Log.warn(`\nHTTPS (secure) server uncaughtException`, new fsm_dynamo_1.Dynamo_Error({
567
- errorCode: 'NTS-AS0-002',
568
- message: `HTTPS (secure) server uncaughtException`,
569
- error: ex,
570
- }));
571
- });
572
- });
573
- }
574
- if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
575
- this.systemControls.httpServer.init = true;
576
- yield new Promise((resolve, reject) => {
577
- this.httpServer = this.openExpress
578
- .listen(this._ports.httpPort, () => {
579
- this.systemControls.httpServer.started = true;
580
- fsm_dynamo_1.Dynamo_Log.success(`\nHTTP (open) server is listening on port: ${this._ports.httpPort}`);
581
- resolve();
582
- })
583
- .on('error', (error) => {
584
- this.systemControls.httpServer.started = false;
585
- this.constructErrors.push(error);
586
- fsm_dynamo_1.Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
587
- reject(new fsm_dynamo_1.Dynamo_Error({
588
- errorCode: 'NTS-AS0-003',
589
- message: `HTTP (open) server ERROR`,
590
- error: error,
591
- }));
592
- })
593
- .on('uncaughtException', (ex) => {
594
- fsm_dynamo_1.Dynamo_Log.warn(`\nHTTP (open) server uncaughtException`, new fsm_dynamo_1.Dynamo_Error({
595
- errorCode: 'NTS-AS0-004',
596
- message: `HTTP (open) server uncaughtException`,
597
- error: ex
598
- }));
599
- });
539
+ async startExpresses() {
540
+ if (this.logFn && this.deepLog)
541
+ console.log('\nfn:. startExpresses');
542
+ try {
543
+ if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
544
+ await new Promise((resolve, reject) => {
545
+ this.systemControls.httpsServer.init = true;
546
+ this.httpsServer
547
+ .listen(this._ports.httpsPort, 'localhost', 0, () => {
548
+ this.systemControls.httpsServer.started = true;
549
+ fsm_dynamo_1.Dynamo_Log.success(`\nHTTPS (secure) server is listening on port: ${this._ports.httpsPort}`);
550
+ resolve();
551
+ })
552
+ .on('error', (error) => {
553
+ this.systemControls.httpsServer.started = false;
554
+ this.constructErrors.push(error);
555
+ fsm_dynamo_1.Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
556
+ reject(new fsm_dynamo_1.Dynamo_Error({
557
+ errorCode: 'NTS-AS0-001',
558
+ message: `HTTPS (secure) server ERROR`,
559
+ error: error,
560
+ }));
561
+ })
562
+ .on('uncaughtException', (ex) => {
563
+ fsm_dynamo_1.Dynamo_Log.warn(`\nHTTPS (secure) server uncaughtException`, new fsm_dynamo_1.Dynamo_Error({
564
+ errorCode: 'NTS-AS0-002',
565
+ message: `HTTPS (secure) server uncaughtException`,
566
+ error: ex,
567
+ }));
600
568
  });
601
- }
569
+ });
602
570
  }
603
- catch (error) {
604
- fsm_dynamo_1.Dynamo_Log.error(`startExpresses failed...`, error);
605
- throw error;
571
+ if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
572
+ this.systemControls.httpServer.init = true;
573
+ await new Promise((resolve, reject) => {
574
+ this.httpServer = this.openExpress
575
+ .listen(this._ports.httpPort, () => {
576
+ this.systemControls.httpServer.started = true;
577
+ fsm_dynamo_1.Dynamo_Log.success(`\nHTTP (open) server is listening on port: ${this._ports.httpPort}`);
578
+ resolve();
579
+ })
580
+ .on('error', (error) => {
581
+ this.systemControls.httpServer.started = false;
582
+ this.constructErrors.push(error);
583
+ fsm_dynamo_1.Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
584
+ reject(new fsm_dynamo_1.Dynamo_Error({
585
+ errorCode: 'NTS-AS0-003',
586
+ message: `HTTP (open) server ERROR`,
587
+ error: error,
588
+ }));
589
+ })
590
+ .on('uncaughtException', (ex) => {
591
+ fsm_dynamo_1.Dynamo_Log.warn(`\nHTTP (open) server uncaughtException`, new fsm_dynamo_1.Dynamo_Error({
592
+ errorCode: 'NTS-AS0-004',
593
+ message: `HTTP (open) server uncaughtException`,
594
+ error: ex
595
+ }));
596
+ });
597
+ });
606
598
  }
607
- });
599
+ }
600
+ catch (error) {
601
+ fsm_dynamo_1.Dynamo_Log.error(`startExpresses failed...`, error);
602
+ throw error;
603
+ }
608
604
  }
609
605
  /**
610
606
  *
611
607
  */
612
- mountSecureRoutes() {
613
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
614
- if (this.logFn && this.deepLog)
615
- console.log('\nfn:. mountSecureRoutes');
616
- yield fsm_dynamo_1.Dynamo_Array.asyncForEach(this._routingModules, (module) => tslib_1.__awaiter(this, void 0, void 0, function* () {
617
- if (module.security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
618
- if (this.logSetup) {
619
- console.log(`route mount (secure): ${module.route}`);
620
- }
621
- const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
622
- if (1 < existingRoutes.length) {
623
- let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
624
- let errorStack = error.stack.split('\n');
625
- errorStack.splice(1, 4);
626
- error.stack = errorStack.join('\n');
627
- fsm_dynamo_1.Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
628
- throw new fsm_dynamo_1.Dynamo_Error({
629
- errorCode: 'NTS-AS0-005',
630
- message: `ROUTE DUPLICATION: ${module.route}`,
631
- error: error,
632
- });
633
- }
634
- this.secureExpress.use(module.route, module.secureRouter);
608
+ async mountSecureRoutes() {
609
+ if (this.logFn && this.deepLog)
610
+ console.log('\nfn:. mountSecureRoutes');
611
+ await fsm_dynamo_1.Dynamo_Array.asyncForEach(this._routingModules, async (module) => {
612
+ if (module.security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
613
+ if (this.logSetup) {
614
+ console.log(`route mount (secure): ${module.route}`);
615
+ }
616
+ const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
617
+ if (1 < existingRoutes.length) {
618
+ let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
619
+ let errorStack = error.stack.split('\n');
620
+ errorStack.splice(1, 4);
621
+ error.stack = errorStack.join('\n');
622
+ fsm_dynamo_1.Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
623
+ throw new fsm_dynamo_1.Dynamo_Error({
624
+ errorCode: 'NTS-AS0-005',
625
+ message: `ROUTE DUPLICATION: ${module.route}`,
626
+ error: error,
627
+ });
635
628
  }
636
- }));
629
+ this.secureExpress.use(module.route, module.secureRouter);
630
+ }
637
631
  });
638
632
  }
639
633
  /**
640
634
  *
641
635
  */
642
- mountOpenRoutes() {
643
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
644
- if (this.logFn && this.deepLog)
645
- console.log('\nfn:. mountOpenRoutes');
646
- yield fsm_dynamo_1.Dynamo_Array.asyncForEach(this._routingModules, (module) => tslib_1.__awaiter(this, void 0, void 0, function* () {
647
- if (module.security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
648
- if (this.logSetup) {
649
- console.log(`route mount (open): ${module.route}`);
650
- }
651
- const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
652
- if (1 < existingRoutes.length) {
653
- let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
654
- let errorStack = error.stack.split('\n');
655
- errorStack.splice(1, 4);
656
- error.stack = errorStack.join('\n');
657
- fsm_dynamo_1.Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
658
- throw new fsm_dynamo_1.Dynamo_Error({
659
- errorCode: 'NTS-AS0-006',
660
- message: `ROUTE DUPLICATION: ${module.route}`,
661
- error: error,
662
- });
663
- }
664
- this.openExpress.use(module.route, module.openRouter);
636
+ async mountOpenRoutes() {
637
+ if (this.logFn && this.deepLog)
638
+ console.log('\nfn:. mountOpenRoutes');
639
+ await fsm_dynamo_1.Dynamo_Array.asyncForEach(this._routingModules, async (module) => {
640
+ if (module.security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
641
+ if (this.logSetup) {
642
+ console.log(`route mount (open): ${module.route}`);
665
643
  }
666
- }));
644
+ const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
645
+ if (1 < existingRoutes.length) {
646
+ let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
647
+ let errorStack = error.stack.split('\n');
648
+ errorStack.splice(1, 4);
649
+ error.stack = errorStack.join('\n');
650
+ fsm_dynamo_1.Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
651
+ throw new fsm_dynamo_1.Dynamo_Error({
652
+ errorCode: 'NTS-AS0-006',
653
+ message: `ROUTE DUPLICATION: ${module.route}`,
654
+ error: error,
655
+ });
656
+ }
657
+ this.openExpress.use(module.route, module.openRouter);
658
+ }
667
659
  });
668
660
  }
669
661
  /**