@futdevpro/nts-dynamo 1.6.19 → 1.6.21

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