@futdevpro/nts-dynamo 1.9.31 → 1.9.33

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 (29) hide show
  1. package/build/_models/control-models/endpoint-params.control-model.js +1 -1
  2. package/build/_models/control-models/endpoint-params.control-model.js.map +1 -1
  3. package/build/_models/interfaces/global-service-settings.interface.d.ts +2 -1
  4. package/build/_models/interfaces/global-service-settings.interface.d.ts.map +1 -1
  5. package/build/_modules/socket/_services/app-extended.server.d.ts +1 -0
  6. package/build/_modules/socket/_services/app-extended.server.d.ts.map +1 -1
  7. package/build/_modules/socket/_services/app-extended.server.js +125 -96
  8. package/build/_modules/socket/_services/app-extended.server.js.map +1 -1
  9. package/build/_modules/socket/_services/app-extended.server.spec.js +2 -0
  10. package/build/_modules/socket/_services/app-extended.server.spec.js.map +1 -1
  11. package/build/_services/core/email.service.d.ts +3 -1
  12. package/build/_services/core/email.service.d.ts.map +1 -1
  13. package/build/_services/core/email.service.js +48 -27
  14. package/build/_services/core/email.service.js.map +1 -1
  15. package/build/_services/core/global.service.d.ts +4 -0
  16. package/build/_services/core/global.service.d.ts.map +1 -1
  17. package/build/_services/core/global.service.js +67 -14
  18. package/build/_services/core/global.service.js.map +1 -1
  19. package/build/_services/server/app.server.d.ts.map +1 -1
  20. package/build/_services/server/app.server.js +352 -291
  21. package/build/_services/server/app.server.js.map +1 -1
  22. package/package.json +2 -2
  23. package/src/_models/control-models/endpoint-params.control-model.ts +1 -1
  24. package/src/_models/interfaces/global-service-settings.interface.ts +3 -1
  25. package/src/_modules/socket/_services/app-extended.server.spec.ts +5 -0
  26. package/src/_modules/socket/_services/app-extended.server.ts +165 -124
  27. package/src/_services/core/email.service.ts +71 -40
  28. package/src/_services/core/global.service.ts +82 -24
  29. package/src/_services/server/app.server.ts +479 -402
@@ -228,7 +228,7 @@ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
228
228
  constructor(extended) {
229
229
  super();
230
230
  process.on('unhandledRejection', (reason, p_passWhatIsThis) => {
231
- fsm_dynamo_1.DyFM_Log.H_error('Unhandled Rejection: ', p_passWhatIsThis.toString().split('at')[0], '\n Rejection reason:', reason.toString().split('at')[0], '\n\n Stack:', reason.stack.replaceAll?.('\n at', '\n at'));
231
+ fsm_dynamo_1.DyFM_Log.H_error('Unhandled Rejection: ', p_passWhatIsThis?.toString()?.split('at')?.[0], '\n Rejection reason:', reason?.toString()?.split('at')?.[0], '\n\n Stack:', reason?.stack?.replaceAll?.('\n at', '\n at'));
232
232
  try {
233
233
  global_service_1.DyNTS_GlobalService.globalErrorHandler?.(new fsm_dynamo_1.DyFM_Error({
234
234
  errorCode: 'NTS-AS0-BASE-UR',
@@ -337,193 +337,212 @@ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
337
337
  });
338
338
  }
339
339
  }
340
+ // eslint-disable-next-line max-lines-per-function
340
341
  async ready(timeout = 4 * fsm_dynamo_1.second) {
341
- if (this.fnLogs)
342
- fsm_dynamo_1.DyFM_Log.log('\nfn:. ready');
343
- let ready = false;
344
- const start = +new Date();
345
- if (this.constructErrors.length) {
346
- if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
347
- fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 1)`, `\n construct ERRORS:`, this.constructErrors);
342
+ try {
343
+ if (this.fnLogs)
344
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. ready');
345
+ await (0, fsm_dynamo_1.DyFM_delay)(100);
346
+ let ready = false;
347
+ const start = +new Date();
348
+ if (this.constructErrors.length) {
349
+ if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
350
+ fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 1)`, `\n construct ERRORS:`, this.constructErrors);
351
+ }
352
+ else {
353
+ fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 1)`, `\n construct ERRORS:`, this.constructErrors.map((error) => {
354
+ if (error instanceof fsm_dynamo_1.DyFM_Error) {
355
+ return error.getErrorSimplified();
356
+ }
357
+ else {
358
+ return error;
359
+ }
360
+ }));
361
+ }
362
+ throw new fsm_dynamo_1.DyFM_Error({
363
+ ...this._getDefaultErrorSettings('ready', new Error(`${this._params.name} start failed.`)),
364
+ errorCode: 'NTS-AS0-R01',
365
+ additionalContent: this.constructErrors.length === 1 ?
366
+ this.constructErrors[0] :
367
+ { errors: this.constructErrors },
368
+ });
348
369
  }
349
- else {
350
- fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 1)`, `\n construct ERRORS:`, this.constructErrors.map((error) => {
351
- if (error instanceof fsm_dynamo_1.DyFM_Error) {
352
- return error.getErrorSimplified();
353
- }
354
- else {
355
- return error;
356
- }
357
- }));
370
+ while (!ready && +new Date() - start < timeout) {
371
+ if (this.systemControls.app.init) {
372
+ ready = (this.systemControls.mongoose.getReady() &&
373
+ this.systemControls.httpServer.getReady() &&
374
+ this.systemControls.httpsServer.getReady());
375
+ }
376
+ else {
377
+ fsm_dynamo_1.DyFM_Log.error(`${this.params.name} APP NOT INITIALIZED while trying to get ready.`);
378
+ }
379
+ if (!ready) {
380
+ await (0, fsm_dynamo_1.DyFM_wait)(100);
381
+ }
358
382
  }
359
- throw new fsm_dynamo_1.DyFM_Error({
360
- ...this._getDefaultErrorSettings('ready', new Error(`${this._params.name} start failed.`)),
361
- errorCode: 'NTS-AS0-R01',
362
- additionalContent: this.constructErrors.length === 1 ?
363
- this.constructErrors[0] :
364
- { errors: this.constructErrors },
365
- });
366
- }
367
- while (!ready && +new Date() - start < timeout) {
368
- if (this.systemControls.app.init) {
369
- ready = (this.systemControls.mongoose.getReady() &&
370
- this.systemControls.httpServer.getReady() &&
371
- this.systemControls.httpsServer.getReady());
383
+ if (timeout < +new Date() - start) {
384
+ if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
385
+ fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. TIMEOUT`, `\n construct ERRORS:`, this.constructErrors);
386
+ }
387
+ else {
388
+ fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. TIMEOUT`, `\n construct ERRORS:`, this.constructErrors.map((error) => {
389
+ if (error instanceof fsm_dynamo_1.DyFM_Error) {
390
+ return error.getErrorSimplified();
391
+ }
392
+ else {
393
+ return error;
394
+ }
395
+ }));
396
+ }
397
+ throw new fsm_dynamo_1.DyFM_Error({
398
+ ...this._getDefaultErrorSettings('ready', new Error(`${this._params.name} start failed. TIMEOUT`)),
399
+ errorCode: 'NTS-AS0-R02',
400
+ additionalContent: {
401
+ constructErrors: this.constructErrors,
402
+ systemControls: this.systemControls,
403
+ systemReadies: {
404
+ mongoose: this.systemControls.mongoose.getReady(),
405
+ httpServer: this.systemControls.httpServer.getReady(),
406
+ httpsServer: this.systemControls.httpsServer.getReady(),
407
+ },
408
+ },
409
+ });
372
410
  }
373
- else {
374
- fsm_dynamo_1.DyFM_Log.error(`${this.params.name} APP NOT INITIALIZED while trying to get ready.`);
411
+ if (this.constructErrors.length) {
412
+ if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
413
+ fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 2)`, `\n construct ERRORS:`, this.constructErrors);
414
+ }
415
+ else {
416
+ fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 2)`, `\n construct ERRORS:`, this.constructErrors.map((error) => {
417
+ if (error instanceof fsm_dynamo_1.DyFM_Error) {
418
+ return error.getErrorSimplified();
419
+ }
420
+ else {
421
+ return error;
422
+ }
423
+ }));
424
+ }
425
+ throw new fsm_dynamo_1.DyFM_Error({
426
+ ...this._getDefaultErrorSettings('ready', new Error(`${this._params.name} start failed.`)),
427
+ errorCode: 'NTS-AS0-R03',
428
+ additionalContent: this.constructErrors,
429
+ });
375
430
  }
376
- if (!ready) {
377
- await (0, fsm_dynamo_1.DyFM_wait)(100);
431
+ if (ready) {
432
+ this.systemControls.app.started = true;
433
+ if (this.fnLogs && this.deepLog)
434
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. ready: return');
435
+ return;
378
436
  }
379
- }
380
- if (timeout < +new Date() - start) {
381
- if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
382
- fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. TIMEOUT`, `\n construct ERRORS:`, this.constructErrors);
437
+ this.systemControls.app.started = false;
438
+ let msg = `${this._params.name} start failed. UNKNOWN`;
439
+ if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
440
+ msg += `\nMongoose start failed.`;
383
441
  }
384
- else {
385
- fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. TIMEOUT`, `\n construct ERRORS:`, this.constructErrors.map((error) => {
386
- if (error instanceof fsm_dynamo_1.DyFM_Error) {
387
- return error.getErrorSimplified();
388
- }
389
- else {
390
- return error;
391
- }
392
- }));
442
+ if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
443
+ msg += `\nHTTP Server start failed.`;
444
+ }
445
+ if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
446
+ msg += `\nHTTPS Server start failed.`;
393
447
  }
448
+ fsm_dynamo_1.DyFM_Log.error(msg, this.constructErrors);
394
449
  throw new fsm_dynamo_1.DyFM_Error({
395
- ...this._getDefaultErrorSettings('ready', new Error(`${this._params.name} start failed. TIMEOUT`)),
396
- errorCode: 'NTS-AS0-R02',
450
+ ...this._getDefaultErrorSettings('ready', new Error(msg)),
451
+ errorCode: 'NTS-AS0-R04',
397
452
  additionalContent: {
398
453
  constructErrors: this.constructErrors,
399
454
  systemControls: this.systemControls,
400
455
  systemReadies: {
456
+ app: this.systemControls.app.getReady(),
401
457
  mongoose: this.systemControls.mongoose.getReady(),
402
458
  httpServer: this.systemControls.httpServer.getReady(),
403
459
  httpsServer: this.systemControls.httpsServer.getReady(),
404
460
  },
405
461
  },
462
+ error: this.constructErrors?.[0] ?? new Error(),
406
463
  });
407
464
  }
408
- if (this.constructErrors.length) {
409
- if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
410
- fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 2)`, `\n construct ERRORS:`, this.constructErrors);
411
- }
412
- else {
413
- fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 2)`, `\n construct ERRORS:`, this.constructErrors.map((error) => {
414
- if (error instanceof fsm_dynamo_1.DyFM_Error) {
415
- return error.getErrorSimplified();
416
- }
417
- else {
418
- return error;
419
- }
420
- }));
421
- }
465
+ catch (error) {
422
466
  throw new fsm_dynamo_1.DyFM_Error({
423
- ...this._getDefaultErrorSettings('ready', new Error(`${this._params.name} start failed.`)),
424
- errorCode: 'NTS-AS0-R03',
425
- additionalContent: this.constructErrors,
467
+ ...this._getDefaultErrorSettings('ready', error),
468
+ errorCode: 'NTS-AS0-READY0',
426
469
  });
427
470
  }
428
- if (ready) {
429
- this.systemControls.app.started = true;
430
- if (this.fnLogs && this.deepLog)
431
- fsm_dynamo_1.DyFM_Log.log('\nfn:. ready: return');
432
- return;
433
- }
434
- this.systemControls.app.started = false;
435
- let msg = `${this._params.name} start failed. UNKNOWN`;
436
- if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
437
- msg += `\nMongoose start failed.`;
438
- }
439
- if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
440
- msg += `\nHTTP Server start failed.`;
441
- }
442
- if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
443
- msg += `\nHTTPS Server start failed.`;
444
- }
445
- fsm_dynamo_1.DyFM_Log.error(msg, this.constructErrors);
446
- throw new fsm_dynamo_1.DyFM_Error({
447
- ...this._getDefaultErrorSettings('ready', new Error(msg)),
448
- errorCode: 'NTS-AS0-R04',
449
- additionalContent: {
450
- constructErrors: this.constructErrors,
451
- systemControls: this.systemControls,
452
- systemReadies: {
453
- app: this.systemControls.app.getReady(),
454
- mongoose: this.systemControls.mongoose.getReady(),
455
- httpServer: this.systemControls.httpServer.getReady(),
456
- httpsServer: this.systemControls.httpsServer.getReady(),
457
- },
458
- },
459
- error: this.constructErrors?.[0] ?? new Error(),
460
- });
461
471
  }
462
472
  async stop(dontLog) {
463
- fsm_dynamo_1.DyFM_Log.info('\nstoping server...\n');
464
- await this.ready();
465
- if (this.started) {
466
- if (this.systemControls.mongoose.init) {
467
- fsm_dynamo_1.DyFM_Log.info(`\nstopping Mongoose....`);
468
- let tryCount = 0;
469
- while (!this.systemControls.mongoose.started &&
470
- !this.constructErrors.length &&
471
- tryCount++ < 10) {
472
- fsm_dynamo_1.DyFM_Log.warn(`Mongoose not even started yet....`);
473
- await (0, fsm_dynamo_1.DyFM_wait)(fsm_dynamo_1.second);
474
- }
475
- this.systemControls.mongoose.started = false;
476
- if (this.mongoose) {
477
- await fsm_dynamo_1.DyFM_Array.asyncForEach(Object.keys(this.mongoose.models), async (modelName) => {
478
- await this.mongoose.deleteModel(modelName);
479
- });
480
- const disconnect = new Promise((resolve) => {
481
- this.mongoose.connection.on('disconnecting', () => {
482
- resolve();
483
- });
484
- });
485
- await this.mongoose.disconnect();
486
- await this.mongoose.connection.close();
487
- await disconnect;
488
- while (this.mongoose.connection.readyState !== 0 &&
489
- !this.constructErrors.length) {
490
- fsm_dynamo_1.DyFM_Log.warn(`\nMongoose still not disconnected....`);
473
+ try {
474
+ fsm_dynamo_1.DyFM_Log.info('\nstopping server...\n');
475
+ await this.ready();
476
+ if (this.started) {
477
+ if (this.systemControls.mongoose.init) {
478
+ fsm_dynamo_1.DyFM_Log.info(`\nstopping Mongoose....`);
479
+ let tryCount = 0;
480
+ while (!this.systemControls.mongoose.started &&
481
+ !this.constructErrors.length &&
482
+ tryCount++ < 10) {
483
+ fsm_dynamo_1.DyFM_Log.warn(`Mongoose not even started yet....`);
491
484
  await (0, fsm_dynamo_1.DyFM_wait)(fsm_dynamo_1.second);
492
485
  }
486
+ this.systemControls.mongoose.started = false;
487
+ if (this.mongoose) {
488
+ await fsm_dynamo_1.DyFM_Array.asyncForEach(Object.keys(this.mongoose.models), async (modelName) => {
489
+ this.mongoose.deleteModel(modelName);
490
+ });
491
+ const disconnect = new Promise((resolve) => {
492
+ this.mongoose.connection.on('disconnecting', () => {
493
+ resolve();
494
+ });
495
+ });
496
+ await this.mongoose.disconnect();
497
+ await this.mongoose.connection.close();
498
+ await disconnect;
499
+ while (this.mongoose.connection.readyState !== 0 &&
500
+ !this.constructErrors.length) {
501
+ fsm_dynamo_1.DyFM_Log.warn(`\nMongoose still not disconnected....`);
502
+ await (0, fsm_dynamo_1.DyFM_wait)(fsm_dynamo_1.second);
503
+ }
504
+ }
505
+ else {
506
+ fsm_dynamo_1.DyFM_Log.error(`\nMongoose not found.`);
507
+ }
508
+ this.systemControls.mongoose.init = false;
493
509
  }
494
- else {
495
- fsm_dynamo_1.DyFM_Log.error(`\nMongoose not found.`);
496
- }
497
- this.systemControls.mongoose.init = false;
498
- }
499
- if (this.systemControls.httpServer.init) {
500
- this.systemControls.httpServer.started = false;
501
- if (this.httpServer) {
502
- await new Promise((resolve) => {
503
- this.httpServer.close(resolve);
504
- });
505
- }
506
- else {
507
- fsm_dynamo_1.DyFM_Log.error(`\nHTTP Server not found.`);
510
+ if (this.systemControls.httpServer.init) {
511
+ this.systemControls.httpServer.started = false;
512
+ if (this.httpServer) {
513
+ await new Promise((resolve) => {
514
+ this.httpServer.close(resolve);
515
+ });
516
+ }
517
+ else {
518
+ fsm_dynamo_1.DyFM_Log.error(`\nHTTP Server not found.`);
519
+ }
520
+ this.systemControls.httpServer.init = false;
508
521
  }
509
- this.systemControls.httpServer.init = false;
510
- }
511
- if (this.systemControls.httpsServer.init) {
512
- this.systemControls.httpsServer.started = false;
513
- if (this.httpsServer) {
514
- await new Promise((resolve) => {
515
- this.httpsServer.close(resolve);
516
- });
522
+ if (this.systemControls.httpsServer.init) {
523
+ this.systemControls.httpsServer.started = false;
524
+ if (this.httpsServer) {
525
+ await new Promise((resolve) => {
526
+ this.httpsServer.close(resolve);
527
+ });
528
+ }
529
+ else {
530
+ fsm_dynamo_1.DyFM_Log.error(`\nHTTPS Server not found.`);
531
+ }
532
+ this.systemControls.httpsServer.init = false;
517
533
  }
518
- else {
519
- fsm_dynamo_1.DyFM_Log.error(`\nHTTPS Server not found.`);
534
+ await (0, fsm_dynamo_1.DyFM_wait)(fsm_dynamo_1.second);
535
+ if (!dontLog) {
536
+ fsm_dynamo_1.DyFM_Log.H_log(`${this._params.name} stopped successfully.`);
520
537
  }
521
- this.systemControls.httpsServer.init = false;
522
- }
523
- if (!dontLog) {
524
- fsm_dynamo_1.DyFM_Log.H_log(`${this._params.name} stopped successfully.`);
525
538
  }
526
539
  }
540
+ catch (error) {
541
+ throw new fsm_dynamo_1.DyFM_Error({
542
+ ...this._getDefaultErrorSettings('stop', error),
543
+ errorCode: 'NTS-AS0-STOP0',
544
+ });
545
+ }
527
546
  }
528
547
  /**
529
548
  *
@@ -531,44 +550,60 @@ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
531
550
  async startDB() {
532
551
  if (this.fnLogs && this.deepLog)
533
552
  fsm_dynamo_1.DyFM_Log.log('\nfn:. startDB');
534
- await new Promise((resolve, reject) => {
535
- this.systemControls.mongoose.init = true;
536
- this.mongoose.connection
537
- .once('open', () => {
538
- this.systemControls.mongoose.started = true;
539
- fsm_dynamo_1.DyFM_Log.success('\nConnected to MongoDB\n');
540
- resolve();
541
- })
542
- .on('error', (error) => {
543
- if (!this.systemControls.mongoose.started) {
544
- this.constructErrors.push(error);
545
- if (this.debugLog)
546
- fsm_dynamo_1.DyFM_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
547
- const d_error = new fsm_dynamo_1.DyFM_Error({
548
- ...this._getDefaultErrorSettings('startDB', error),
549
- errorCode: 'NTS-AS0-SDB1',
550
- message: `Unable to start connection to MongoDB server, ERROR: ${error}`,
553
+ try {
554
+ await new Promise((resolve, reject) => {
555
+ this.systemControls.mongoose.init = true;
556
+ this.mongoose.connection
557
+ .once('open', () => {
558
+ this.systemControls.mongoose.started = true;
559
+ fsm_dynamo_1.DyFM_Log.success('\nConnected to MongoDB\n');
560
+ resolve();
561
+ })
562
+ .on('error', (error) => {
563
+ if (!this.systemControls.mongoose.started) {
564
+ this.constructErrors.push(error);
565
+ if (this.debugLog)
566
+ fsm_dynamo_1.DyFM_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
567
+ const d_error = new fsm_dynamo_1.DyFM_Error({
568
+ ...this._getDefaultErrorSettings('startDB', error),
569
+ errorCode: 'NTS-AS0-SDB1',
570
+ message: `Unable to start connection to MongoDB server, ERROR: ${error}`,
571
+ });
572
+ global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
573
+ reject(d_error);
574
+ }
575
+ else {
576
+ if (this.debugLog)
577
+ fsm_dynamo_1.DyFM_Log.error('\nMongoDB ERROR: ', error);
578
+ const d_error = new fsm_dynamo_1.DyFM_Error({
579
+ ...this._getDefaultErrorSettings('mongoose.connection.on(error)', error),
580
+ errorCode: 'NTS-AS0-SDB2',
581
+ message: `MongoDB ERROR: ${error}`,
582
+ level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
583
+ });
584
+ global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
585
+ }
586
+ });
587
+ try {
588
+ this.mongoose.connect(this._params.dbUri, {
589
+ useNewUrlParser: true,
590
+ useUnifiedTopology: true,
551
591
  });
552
- global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
553
- reject(d_error);
554
592
  }
555
- else {
556
- if (this.debugLog)
557
- fsm_dynamo_1.DyFM_Log.error('\nMongoDB ERROR: ', error);
558
- const d_error = new fsm_dynamo_1.DyFM_Error({
559
- ...this._getDefaultErrorSettings('mongoose.connection.on(error)', error),
560
- errorCode: 'NTS-AS0-SDB2',
561
- message: `MongoDB ERROR: ${error}`,
562
- level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
593
+ catch (error) {
594
+ throw new fsm_dynamo_1.DyFM_Error({
595
+ ...this._getDefaultErrorSettings('startDB', error),
596
+ errorCode: 'NTS-AS0-SDB3',
563
597
  });
564
- global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
565
598
  }
566
599
  });
567
- this.mongoose.connect(this._params.dbUri, {
568
- useNewUrlParser: true,
569
- useUnifiedTopology: true,
600
+ }
601
+ catch (error) {
602
+ throw new fsm_dynamo_1.DyFM_Error({
603
+ ...this._getDefaultErrorSettings('startDB', error),
604
+ errorCode: 'NTS-AS0-SDB0',
570
605
  });
571
- });
606
+ }
572
607
  }
573
608
  /**
574
609
  *
@@ -576,64 +611,72 @@ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
576
611
  async initExpresses() {
577
612
  if (this.fnLogs && this.deepLog)
578
613
  fsm_dynamo_1.DyFM_Log.log('\nfn:. initExpresses');
579
- if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
580
- if (!this._portSettings.httpPort) {
581
- let errorMsg = `\nYou have open routes, but httpPort is not set!` +
582
- `\nsecurity: ${this._security}` +
583
- `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
584
- errorMsg += '\n\nThe routes setted to use open server:';
585
- this._routingModules.forEach((module) => {
586
- if (module.security != route_security_enum_1.DyNTS_RouteSecurity.secure) {
587
- errorMsg += `\n ${module.route} (security: ${module.security})`;
588
- errorMsg += `\n subroutes using open sever:`;
589
- module.endpoints.forEach((endpoint) => {
590
- if (endpoint.security != route_security_enum_1.DyNTS_RouteSecurity.secure) {
591
- errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
592
- }
593
- });
594
- }
595
- });
596
- const error = new Error('Open routes cannot be established!');
597
- const errorStack = error.stack.split('\n');
598
- errorStack.splice(1, 2);
599
- error.stack = errorStack.join('\n');
600
- fsm_dynamo_1.DyFM_Log.error(errorMsg);
601
- throw error;
614
+ try {
615
+ if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
616
+ if (!this._portSettings.httpPort) {
617
+ let errorMsg = `\nYou have open routes, but httpPort is not set!` +
618
+ `\nsecurity: ${this._security}` +
619
+ `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
620
+ errorMsg += '\n\nThe routes setted to use open server:';
621
+ this._routingModules.forEach((module) => {
622
+ if (module.security != route_security_enum_1.DyNTS_RouteSecurity.secure) {
623
+ errorMsg += `\n ${module.route} (security: ${module.security})`;
624
+ errorMsg += `\n subroutes using open sever:`;
625
+ module.endpoints.forEach((endpoint) => {
626
+ if (endpoint.security != route_security_enum_1.DyNTS_RouteSecurity.secure) {
627
+ errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
628
+ }
629
+ });
630
+ }
631
+ });
632
+ const error = new Error('Open routes cannot be established!');
633
+ const errorStack = error.stack.split('\n');
634
+ errorStack.splice(1, 2);
635
+ error.stack = errorStack.join('\n');
636
+ fsm_dynamo_1.DyFM_Log.error(errorMsg);
637
+ throw error;
638
+ }
639
+ await this.initOpenExpress();
602
640
  }
603
- await this.initOpenExpress();
604
- }
605
- if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
606
- if (!this._cert || !this._portSettings.httpsPort) {
607
- let errorMsg = `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
608
- `\nsecurity: ${this._security}` +
609
- `\nset...` +
610
- `\n(missing exact howto...)` +
611
- /* `\n httpsPort and` +
612
- `\n cert: {` +
613
- `\n keyPath: FileSystem.PathLike,` +
614
- `\n certPath: FileSystem.PathLike,` +
615
- `\n }` + */
616
- `\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
617
- errorMsg += '\n\nThe routes setted to use secure server:';
618
- this._routingModules.forEach((module) => {
619
- if (module.security && module.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
620
- errorMsg += `\n ${module.route} (security: ${module.security})`;
621
- errorMsg += `\n subroutes using secure sever:`;
622
- module.endpoints.forEach((endpoint) => {
623
- if (endpoint.security && endpoint.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
624
- errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
625
- }
626
- });
627
- }
628
- });
629
- const error = new Error('Secure routes cannot be established!');
630
- const errorStack = error.stack.split('\n');
631
- errorStack.splice(1, 2);
632
- error.stack = errorStack.join('\n');
633
- fsm_dynamo_1.DyFM_Log.error(errorMsg);
634
- throw error;
641
+ if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
642
+ if (!this._cert || !this._portSettings.httpsPort) {
643
+ let errorMsg = `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
644
+ `\nsecurity: ${this._security}` +
645
+ `\nset...` +
646
+ `\n(missing exact howto...)` +
647
+ /* `\n httpsPort and` +
648
+ `\n cert: {` +
649
+ `\n keyPath: FileSystem.PathLike,` +
650
+ `\n certPath: FileSystem.PathLike,` +
651
+ `\n }` + */
652
+ `\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
653
+ errorMsg += '\n\nThe routes setted to use secure server:';
654
+ this._routingModules.forEach((module) => {
655
+ if (module.security && module.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
656
+ errorMsg += `\n ${module.route} (security: ${module.security})`;
657
+ errorMsg += `\n subroutes using secure sever:`;
658
+ module.endpoints.forEach((endpoint) => {
659
+ if (endpoint.security && endpoint.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
660
+ errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
661
+ }
662
+ });
663
+ }
664
+ });
665
+ const error = new Error('Secure routes cannot be established!');
666
+ const errorStack = error.stack.split('\n');
667
+ errorStack.splice(1, 2);
668
+ error.stack = errorStack.join('\n');
669
+ fsm_dynamo_1.DyFM_Log.error(errorMsg);
670
+ throw error;
671
+ }
672
+ await this.initSecureExpress();
635
673
  }
636
- await this.initSecureExpress();
674
+ }
675
+ catch (error) {
676
+ throw new fsm_dynamo_1.DyFM_Error({
677
+ ...this._getDefaultErrorSettings('initExpresses', error),
678
+ errorCode: 'NTS-AS0-IE0',
679
+ });
637
680
  }
638
681
  }
639
682
  /**
@@ -761,8 +804,10 @@ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
761
804
  }
762
805
  }
763
806
  catch (error) {
764
- fsm_dynamo_1.DyFM_Log.error(`startExpresses failed...`, error);
765
- throw error;
807
+ throw new fsm_dynamo_1.DyFM_Error({
808
+ ...this._getDefaultErrorSettings('startExpresses', error),
809
+ errorCode: 'NTS-AS0-SE0',
810
+ });
766
811
  }
767
812
  }
768
813
  /**
@@ -797,59 +842,75 @@ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
797
842
  *
798
843
  */
799
844
  async mountSecureRoutes() {
800
- if (this.fnLogs && this.deepLog)
801
- fsm_dynamo_1.DyFM_Log.log('\nfn:. mountSecureRoutes');
802
- this.openExpress.use((error, req, res, next) => this.expressErrorHandling(error, req, res, next));
803
- await fsm_dynamo_1.DyFM_Array.asyncForEach(this._routingModules, async (module) => {
804
- if (module.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
805
- if (this.logSetup) {
806
- fsm_dynamo_1.DyFM_Log.log(`route mount (secure): ${module.route}`);
807
- }
808
- const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
809
- if (1 < existingRoutes.length) {
810
- const error = new Error(`ROUTE DUPLICATION: ${module.route}`);
811
- const errorStack = error.stack.split('\n');
812
- errorStack.splice(1, 4);
813
- error.stack = errorStack.join('\n');
814
- fsm_dynamo_1.DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
815
- throw new fsm_dynamo_1.DyFM_Error({
816
- ...this._getDefaultErrorSettings('mountSecureRoutes', error),
817
- errorCode: 'NTS-AS0-MSR1',
818
- message: `ROUTE DUPLICATION: ${module.route}`,
819
- });
845
+ try {
846
+ if (this.fnLogs && this.deepLog)
847
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. mountSecureRoutes');
848
+ this.openExpress.use((error, req, res, next) => this.expressErrorHandling(error, req, res, next));
849
+ await fsm_dynamo_1.DyFM_Array.asyncForEach(this._routingModules, async (module) => {
850
+ if (module.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
851
+ if (this.logSetup) {
852
+ fsm_dynamo_1.DyFM_Log.log(`route mount (secure): ${module.route}`);
853
+ }
854
+ const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
855
+ if (1 < existingRoutes.length) {
856
+ const error = new Error(`ROUTE DUPLICATION: ${module.route}`);
857
+ const errorStack = error.stack.split('\n');
858
+ errorStack.splice(1, 4);
859
+ error.stack = errorStack.join('\n');
860
+ fsm_dynamo_1.DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
861
+ throw new fsm_dynamo_1.DyFM_Error({
862
+ ...this._getDefaultErrorSettings('mountSecureRoutes', error),
863
+ errorCode: 'NTS-AS0-MSR1',
864
+ message: `ROUTE DUPLICATION: ${module.route}`,
865
+ });
866
+ }
867
+ this.secureExpress.use(module.route, module.secureRouter);
820
868
  }
821
- this.secureExpress.use(module.route, module.secureRouter);
822
- }
823
- });
869
+ });
870
+ }
871
+ catch (error) {
872
+ throw new fsm_dynamo_1.DyFM_Error({
873
+ ...this._getDefaultErrorSettings('mountSecureRoutes', error),
874
+ errorCode: 'NTS-AS0-MSR0',
875
+ });
876
+ }
824
877
  }
825
878
  /**
826
879
  *
827
880
  */
828
881
  async mountOpenRoutes() {
829
- if (this.fnLogs && this.deepLog)
830
- fsm_dynamo_1.DyFM_Log.log('\nfn:. mountOpenRoutes');
831
- this.openExpress.use((error, req, res, next) => this.expressErrorHandling(error, req, res, next));
832
- await fsm_dynamo_1.DyFM_Array.asyncForEach(this._routingModules, async (module) => {
833
- if (module.security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
834
- if (this.logSetup) {
835
- fsm_dynamo_1.DyFM_Log.log(`route mount (open): ${module.route}`);
836
- }
837
- const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
838
- if (1 < existingRoutes.length) {
839
- const error = new Error(`ROUTE DUPLICATION: ${module.route}`);
840
- const errorStack = error.stack.split('\n');
841
- errorStack.splice(1, 4);
842
- error.stack = errorStack.join('\n');
843
- fsm_dynamo_1.DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
844
- throw new fsm_dynamo_1.DyFM_Error({
845
- ...this._getDefaultErrorSettings('mountOpenRoutes', error),
846
- errorCode: 'NTS-AS0-MOR1',
847
- message: `ROUTE DUPLICATION: ${module.route}`,
848
- });
882
+ try {
883
+ if (this.fnLogs && this.deepLog)
884
+ fsm_dynamo_1.DyFM_Log.log('\nfn:. mountOpenRoutes');
885
+ this.openExpress.use((error, req, res, next) => this.expressErrorHandling(error, req, res, next));
886
+ await fsm_dynamo_1.DyFM_Array.asyncForEach(this._routingModules, async (module) => {
887
+ if (module.security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
888
+ if (this.logSetup) {
889
+ fsm_dynamo_1.DyFM_Log.log(`route mount (open): ${module.route}`);
890
+ }
891
+ const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
892
+ if (1 < existingRoutes.length) {
893
+ const error = new Error(`ROUTE DUPLICATION: ${module.route}`);
894
+ const errorStack = error.stack.split('\n');
895
+ errorStack.splice(1, 4);
896
+ error.stack = errorStack.join('\n');
897
+ fsm_dynamo_1.DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
898
+ throw new fsm_dynamo_1.DyFM_Error({
899
+ ...this._getDefaultErrorSettings('mountOpenRoutes', error),
900
+ errorCode: 'NTS-AS0-MOR1',
901
+ message: `ROUTE DUPLICATION: ${module.route}`,
902
+ });
903
+ }
904
+ this.openExpress.use(module.route, module.openRouter);
849
905
  }
850
- this.openExpress.use(module.route, module.openRouter);
851
- }
852
- });
906
+ });
907
+ }
908
+ catch (error) {
909
+ throw new fsm_dynamo_1.DyFM_Error({
910
+ ...this._getDefaultErrorSettings('mountOpenRoutes', error),
911
+ errorCode: 'NTS-AS0-MOR0',
912
+ });
913
+ }
853
914
  }
854
915
  /**
855
916
  *