@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
@@ -16,7 +16,8 @@ import {
16
16
  DyFM_Array, DyFM_Error, DyFM_error_defaults,
17
17
  DyFM_Error_Settings,
18
18
  DyFM_ErrorLevel, DyFM_Log, second, DyFM_wait,
19
- DyFM_errorFlag
19
+ DyFM_errorFlag,
20
+ DyFM_delay
20
21
  } from '@futdevpro/fsm-dynamo';
21
22
 
22
23
  import { DyNTS_SingletonService } from '../base/singleton.service';
@@ -270,10 +271,10 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
270
271
 
271
272
  process.on('unhandledRejection', (reason: object, p_passWhatIsThis: any): void => {
272
273
  DyFM_Log.H_error(
273
- 'Unhandled Rejection: ', p_passWhatIsThis.toString().split('at')[0],
274
- '\n Rejection reason:', reason.toString().split('at')[0],
274
+ 'Unhandled Rejection: ', p_passWhatIsThis?.toString()?.split('at')?.[0],
275
+ '\n Rejection reason:', reason?.toString()?.split('at')?.[0],
275
276
  '\n\n Stack:',
276
- (reason as any).stack.replaceAll?.('\n at', '\n at')
277
+ (reason as any)?.stack?.replaceAll?.('\n at', '\n at'),
277
278
  );
278
279
 
279
280
  try {
@@ -314,6 +315,7 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
314
315
 
315
316
  private async asyncConstruct(extended?: boolean): Promise<void> {
316
317
  if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. asyncConstruct');
318
+
317
319
  try {
318
320
  this.systemControls.app.init = true;
319
321
  this._params = this.getAppParams();
@@ -409,10 +411,7 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
409
411
  );
410
412
 
411
413
  throw new DyFM_Error({
412
- ...this._getDefaultErrorSettings(
413
- 'asyncConstruct',
414
- error
415
- ),
414
+ ...this._getDefaultErrorSettings('asyncConstruct', error),
416
415
 
417
416
  errorCode: 'NTS-AS0-001',
418
417
  additionalContent: {
@@ -429,260 +428,282 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
429
428
  }
430
429
  }
431
430
 
431
+ // eslint-disable-next-line max-lines-per-function
432
432
  async ready(timeout: number = 4 * second): Promise<void> {
433
- if (this.fnLogs) DyFM_Log.log('\nfn:. ready');
434
- let ready: boolean = false;
435
- const start: number = +new Date();
433
+ try {
434
+ if (this.fnLogs) DyFM_Log.log('\nfn:. ready');
435
+
436
+ await DyFM_delay(100);
436
437
 
437
- if (this.constructErrors.length) {
438
- if (DyNTS_global_settings.log_settings.highDetailedLogs) {
439
- DyFM_Log.H_error(
440
- `${this._params.name} start failed. (ready check 1)`,
441
- `\n construct ERRORS:`, this.constructErrors
442
- );
443
- } else {
444
- DyFM_Log.H_error(
445
- `${this._params.name} start failed. (ready check 1)`,
446
- `\n construct ERRORS:`,
447
- this.constructErrors.map((error: any): any => {
448
- if (error instanceof DyFM_Error) {
449
- return error.getErrorSimplified();
450
- } else {
451
- return error;
452
- }
453
- }),
454
- );
438
+ let ready: boolean = false;
439
+ const start: number = +new Date();
440
+
441
+ if (this.constructErrors.length) {
442
+ if (DyNTS_global_settings.log_settings.highDetailedLogs) {
443
+ DyFM_Log.H_error(
444
+ `${this._params.name} start failed. (ready check 1)`,
445
+ `\n construct ERRORS:`, this.constructErrors
446
+ );
447
+ } else {
448
+ DyFM_Log.H_error(
449
+ `${this._params.name} start failed. (ready check 1)`,
450
+ `\n construct ERRORS:`,
451
+ this.constructErrors.map((error: any): any => {
452
+ if (error instanceof DyFM_Error) {
453
+ return error.getErrorSimplified();
454
+ } else {
455
+ return error;
456
+ }
457
+ }),
458
+ );
459
+ }
460
+
461
+ throw new DyFM_Error({
462
+ ...this._getDefaultErrorSettings(
463
+ 'ready',
464
+ new Error(`${this._params.name} start failed.`)
465
+ ),
466
+
467
+ errorCode: 'NTS-AS0-R01',
468
+ additionalContent:
469
+ this.constructErrors.length === 1 ?
470
+ this.constructErrors[0] :
471
+ { errors: this.constructErrors },
472
+ });
455
473
  }
456
474
 
457
- throw new DyFM_Error({
458
- ...this._getDefaultErrorSettings(
459
- 'ready',
460
- new Error(`${this._params.name} start failed.`)
461
- ),
475
+ while (!ready && +new Date() - start < timeout) {
476
+ if (this.systemControls.app.init) {
477
+ ready = (
478
+ this.systemControls.mongoose.getReady() &&
479
+ this.systemControls.httpServer.getReady() &&
480
+ this.systemControls.httpsServer.getReady()
481
+ );
482
+ } else {
483
+ DyFM_Log.error(`${this.params.name} APP NOT INITIALIZED while trying to get ready.`);
484
+ }
462
485
 
463
- errorCode: 'NTS-AS0-R01',
464
- additionalContent:
465
- this.constructErrors.length === 1 ?
466
- this.constructErrors[0] :
467
- { errors: this.constructErrors },
468
- });
469
- }
486
+ if (!ready) {
487
+ await DyFM_wait(100);
488
+ }
489
+ }
470
490
 
471
- while (!ready && +new Date() - start < timeout) {
472
- if (this.systemControls.app.init) {
473
- ready = (
474
- this.systemControls.mongoose.getReady() &&
475
- this.systemControls.httpServer.getReady() &&
476
- this.systemControls.httpsServer.getReady()
477
- );
478
- } else {
479
- DyFM_Log.error(`${this.params.name} APP NOT INITIALIZED while trying to get ready.`);
491
+ if (timeout < +new Date() - start) {
492
+ if (DyNTS_global_settings.log_settings.highDetailedLogs) {
493
+ DyFM_Log.H_error(
494
+ `${this._params.name} start failed. TIMEOUT`,
495
+ `\n construct ERRORS:`, this.constructErrors
496
+ );
497
+ } else {
498
+ DyFM_Log.H_error(
499
+ `${this._params.name} start failed. TIMEOUT`,
500
+ `\n construct ERRORS:`,
501
+ this.constructErrors.map((error: any): any => {
502
+ if (error instanceof DyFM_Error) {
503
+ return error.getErrorSimplified();
504
+ } else {
505
+ return error;
506
+ }
507
+ }),
508
+ );
509
+ }
510
+
511
+ throw new DyFM_Error({
512
+ ...this._getDefaultErrorSettings(
513
+ 'ready',
514
+ new Error(`${this._params.name} start failed. TIMEOUT`)
515
+ ),
516
+
517
+ errorCode: 'NTS-AS0-R02',
518
+ additionalContent: {
519
+ constructErrors: this.constructErrors,
520
+ systemControls: this.systemControls,
521
+ systemReadies: {
522
+ mongoose: this.systemControls.mongoose.getReady(),
523
+ httpServer: this.systemControls.httpServer.getReady(),
524
+ httpsServer: this.systemControls.httpsServer.getReady(),
525
+ },
526
+ },
527
+ });
480
528
  }
481
529
 
482
- if (!ready) {
483
- await DyFM_wait(100);
530
+ if (this.constructErrors.length) {
531
+ if (DyNTS_global_settings.log_settings.highDetailedLogs) {
532
+ DyFM_Log.H_error(
533
+ `${this._params.name} start failed. (ready check 2)`,
534
+ `\n construct ERRORS:`, this.constructErrors
535
+ );
536
+ } else {
537
+ DyFM_Log.H_error(
538
+ `${this._params.name} start failed. (ready check 2)`,
539
+ `\n construct ERRORS:`,
540
+ this.constructErrors.map((error: any): any => {
541
+ if (error instanceof DyFM_Error) {
542
+ return error.getErrorSimplified();
543
+ } else {
544
+ return error;
545
+ }
546
+ }),
547
+ );
548
+ }
549
+
550
+ throw new DyFM_Error({
551
+ ...this._getDefaultErrorSettings(
552
+ 'ready',
553
+ new Error(`${this._params.name} start failed.`)
554
+ ),
555
+
556
+ errorCode: 'NTS-AS0-R03',
557
+ additionalContent: this.constructErrors,
558
+ });
484
559
  }
485
- }
486
560
 
487
- if (timeout < +new Date() - start) {
488
- if (DyNTS_global_settings.log_settings.highDetailedLogs) {
489
- DyFM_Log.H_error(
490
- `${this._params.name} start failed. TIMEOUT`,
491
- `\n construct ERRORS:`, this.constructErrors
492
- );
493
- } else {
494
- DyFM_Log.H_error(
495
- `${this._params.name} start failed. TIMEOUT`,
496
- `\n construct ERRORS:`,
497
- this.constructErrors.map((error: any): any => {
498
- if (error instanceof DyFM_Error) {
499
- return error.getErrorSimplified();
500
- } else {
501
- return error;
502
- }
503
- }),
504
- );
561
+ if (ready) {
562
+ this.systemControls.app.started = true;
563
+
564
+ if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. ready: return');
565
+
566
+ return;
505
567
  }
506
568
 
507
- throw new DyFM_Error({
569
+ this.systemControls.app.started = false;
570
+
571
+ let msg: string = `${this._params.name} start failed. UNKNOWN`;
572
+
573
+ if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
574
+ msg += `\nMongoose start failed.`;
575
+ }
576
+
577
+ if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
578
+ msg += `\nHTTP Server start failed.`;
579
+ }
580
+
581
+ if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
582
+ msg += `\nHTTPS Server start failed.`;
583
+ }
584
+
585
+ DyFM_Log.error(msg, this.constructErrors);
586
+
587
+ throw new DyFM_Error({
508
588
  ...this._getDefaultErrorSettings(
509
589
  'ready',
510
- new Error(`${this._params.name} start failed. TIMEOUT`)
590
+ new Error(msg)
511
591
  ),
512
592
 
513
- errorCode: 'NTS-AS0-R02',
593
+ errorCode: 'NTS-AS0-R04',
514
594
  additionalContent: {
515
595
  constructErrors: this.constructErrors,
516
596
  systemControls: this.systemControls,
517
597
  systemReadies: {
598
+ app: this.systemControls.app.getReady(),
518
599
  mongoose: this.systemControls.mongoose.getReady(),
519
600
  httpServer: this.systemControls.httpServer.getReady(),
520
601
  httpsServer: this.systemControls.httpsServer.getReady(),
521
602
  },
522
603
  },
604
+ error: this.constructErrors?.[0] ?? new Error(),
523
605
  });
524
- }
525
-
526
- if (this.constructErrors.length) {
527
- if (DyNTS_global_settings.log_settings.highDetailedLogs) {
528
- DyFM_Log.H_error(
529
- `${this._params.name} start failed. (ready check 2)`,
530
- `\n construct ERRORS:`, this.constructErrors
531
- );
532
- } else {
533
- DyFM_Log.H_error(
534
- `${this._params.name} start failed. (ready check 2)`,
535
- `\n construct ERRORS:`,
536
- this.constructErrors.map((error: any): any => {
537
- if (error instanceof DyFM_Error) {
538
- return error.getErrorSimplified();
539
- } else {
540
- return error;
541
- }
542
- }),
543
- );
544
- }
545
-
606
+ } catch (error) {
546
607
  throw new DyFM_Error({
547
- ...this._getDefaultErrorSettings(
548
- 'ready',
549
- new Error(`${this._params.name} start failed.`)
550
- ),
551
-
552
- errorCode: 'NTS-AS0-R03',
553
- additionalContent: this.constructErrors,
608
+ ...this._getDefaultErrorSettings('ready', error),
609
+
610
+ errorCode: 'NTS-AS0-READY0',
554
611
  });
555
612
  }
556
-
557
- if (ready) {
558
- this.systemControls.app.started = true;
559
-
560
- if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. ready: return');
561
-
562
- return;
563
- }
564
-
565
- this.systemControls.app.started = false;
566
-
567
- let msg: string = `${this._params.name} start failed. UNKNOWN`;
568
-
569
- if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
570
- msg += `\nMongoose start failed.`;
571
- }
572
-
573
- if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
574
- msg += `\nHTTP Server start failed.`;
575
- }
576
-
577
- if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
578
- msg += `\nHTTPS Server start failed.`;
579
- }
580
-
581
- DyFM_Log.error(msg, this.constructErrors);
582
-
583
- throw new DyFM_Error({
584
- ...this._getDefaultErrorSettings(
585
- 'ready',
586
- new Error(msg)
587
- ),
588
-
589
- errorCode: 'NTS-AS0-R04',
590
- additionalContent: {
591
- constructErrors: this.constructErrors,
592
- systemControls: this.systemControls,
593
- systemReadies: {
594
- app: this.systemControls.app.getReady(),
595
- mongoose: this.systemControls.mongoose.getReady(),
596
- httpServer: this.systemControls.httpServer.getReady(),
597
- httpsServer: this.systemControls.httpsServer.getReady(),
598
- },
599
- },
600
- error: this.constructErrors?.[0] ?? new Error(),
601
- });
602
613
  }
603
614
 
604
615
  async stop(dontLog?: boolean): Promise<void> {
605
- DyFM_Log.info('\nstoping server...\n');
606
-
607
- await this.ready();
608
-
609
- if (this.started) {
610
-
611
- if (this.systemControls.mongoose.init) {
612
- DyFM_Log.info(`\nstopping Mongoose....`);
616
+ try {
617
+ DyFM_Log.info('\nstopping server...\n');
613
618
 
614
- let tryCount: number = 0;
619
+ await this.ready();
615
620
 
616
- while (
617
- !this.systemControls.mongoose.started &&
618
- !this.constructErrors.length &&
619
- tryCount++ < 10
620
- ) {
621
- DyFM_Log.warn(`Mongoose not even started yet....`);
622
- await DyFM_wait(second);
623
- }
624
- this.systemControls.mongoose.started = false;
621
+ if (this.started) {
625
622
 
626
- if (this.mongoose) {
627
- await DyFM_Array.asyncForEach(
628
- Object.keys(this.mongoose.models),
629
- async (modelName): Promise<void> => {
630
- await this.mongoose.deleteModel(modelName);
631
- }
632
- );
623
+ if (this.systemControls.mongoose.init) {
624
+ DyFM_Log.info(`\nstopping Mongoose....`);
633
625
 
634
- const disconnect: Promise<void> = new Promise((resolve): void => {
635
- this.mongoose.connection.on('disconnecting', (): void => {
636
- resolve();
637
- });
638
- });
639
-
640
- await this.mongoose.disconnect();
641
- await this.mongoose.connection.close();
642
- await disconnect;
626
+ let tryCount: number = 0;
643
627
 
644
628
  while (
645
- this.mongoose.connection.readyState !== 0 &&
646
- !this.constructErrors.length
629
+ !this.systemControls.mongoose.started &&
630
+ !this.constructErrors.length &&
631
+ tryCount++ < 10
647
632
  ) {
648
- DyFM_Log.warn(`\nMongoose still not disconnected....`);
633
+ DyFM_Log.warn(`Mongoose not even started yet....`);
649
634
  await DyFM_wait(second);
650
635
  }
651
- } else {
652
- DyFM_Log.error(`\nMongoose not found.`);
636
+ this.systemControls.mongoose.started = false;
637
+
638
+ if (this.mongoose) {
639
+ await DyFM_Array.asyncForEach(
640
+ Object.keys(this.mongoose.models),
641
+ async (modelName): Promise<void> => {
642
+ this.mongoose.deleteModel(modelName);
643
+ }
644
+ );
645
+
646
+ const disconnect: Promise<void> = new Promise((resolve): void => {
647
+ this.mongoose.connection.on('disconnecting', (): void => {
648
+ resolve();
649
+ });
650
+ });
651
+
652
+ await this.mongoose.disconnect();
653
+ await this.mongoose.connection.close();
654
+ await disconnect;
655
+
656
+ while (
657
+ this.mongoose.connection.readyState !== 0 &&
658
+ !this.constructErrors.length
659
+ ) {
660
+ DyFM_Log.warn(`\nMongoose still not disconnected....`);
661
+ await DyFM_wait(second);
662
+ }
663
+ } else {
664
+ DyFM_Log.error(`\nMongoose not found.`);
665
+ }
666
+ this.systemControls.mongoose.init = false;
653
667
  }
654
- this.systemControls.mongoose.init = false;
655
- }
656
668
 
657
- if (this.systemControls.httpServer.init) {
658
- this.systemControls.httpServer.started = false;
669
+ if (this.systemControls.httpServer.init) {
670
+ this.systemControls.httpServer.started = false;
659
671
 
660
- if (this.httpServer) {
661
- await new Promise((resolve): void => {
662
- this.httpServer.close(resolve);
663
- });
664
- } else {
665
- DyFM_Log.error(`\nHTTP Server not found.`);
672
+ if (this.httpServer) {
673
+ await new Promise((resolve): void => {
674
+ this.httpServer.close(resolve);
675
+ });
676
+ } else {
677
+ DyFM_Log.error(`\nHTTP Server not found.`);
678
+ }
679
+ this.systemControls.httpServer.init = false;
666
680
  }
667
- this.systemControls.httpServer.init = false;
668
- }
669
681
 
670
- if (this.systemControls.httpsServer.init) {
671
- this.systemControls.httpsServer.started = false;
682
+ if (this.systemControls.httpsServer.init) {
683
+ this.systemControls.httpsServer.started = false;
672
684
 
673
- if (this.httpsServer) {
674
- await new Promise((resolve): void => {
675
- this.httpsServer.close(resolve);
676
- });
677
- } else {
678
- DyFM_Log.error(`\nHTTPS Server not found.`);
685
+ if (this.httpsServer) {
686
+ await new Promise((resolve): void => {
687
+ this.httpsServer.close(resolve);
688
+ });
689
+ } else {
690
+ DyFM_Log.error(`\nHTTPS Server not found.`);
691
+ }
692
+ this.systemControls.httpsServer.init = false;
679
693
  }
680
- this.systemControls.httpsServer.init = false;
681
- }
682
694
 
683
- if (!dontLog) {
684
- DyFM_Log.H_log(`${this._params.name} stopped successfully.`);
695
+ await DyFM_wait(second);
696
+
697
+ if (!dontLog) {
698
+ DyFM_Log.H_log(`${this._params.name} stopped successfully.`);
699
+ }
685
700
  }
701
+ } catch (error) {
702
+ throw new DyFM_Error({
703
+ ...this._getDefaultErrorSettings('stop', error),
704
+
705
+ errorCode: 'NTS-AS0-STOP0',
706
+ });
686
707
  }
687
708
  }
688
709
 
@@ -692,66 +713,83 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
692
713
  private async startDB(): Promise<void> {
693
714
  if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. startDB');
694
715
 
695
- await new Promise<void>(
696
- (resolve, reject): void => {
697
- this.systemControls.mongoose.init = true;
716
+ try {
717
+ await new Promise<void>(
718
+ (resolve, reject): void => {
719
+ this.systemControls.mongoose.init = true;
698
720
 
699
- this.mongoose.connection
700
- .once('open', (): void => {
701
- this.systemControls.mongoose.started = true;
702
- DyFM_Log.success('\nConnected to MongoDB\n');
721
+ this.mongoose.connection
722
+ .once('open', (): void => {
723
+ this.systemControls.mongoose.started = true;
724
+ DyFM_Log.success('\nConnected to MongoDB\n');
703
725
 
704
- resolve();
705
- })
706
- .on('error', (error): void => {
707
- if (!this.systemControls.mongoose.started) {
708
- this.constructErrors.push(error);
709
-
710
- if (this.debugLog) DyFM_Log.error(
711
- '\nUnable to connect to MongoDB server, ERROR: ',
712
- error
713
- );
726
+ resolve();
727
+ })
728
+ .on('error', (error): void => {
729
+ if (!this.systemControls.mongoose.started) {
730
+ this.constructErrors.push(error);
714
731
 
715
- const d_error: DyFM_Error = new DyFM_Error({
716
- ...this._getDefaultErrorSettings(
717
- 'startDB',
732
+ if (this.debugLog) DyFM_Log.error(
733
+ '\nUnable to connect to MongoDB server, ERROR: ',
718
734
  error
719
- ),
720
-
721
- errorCode: 'NTS-AS0-SDB1',
722
- message: `Unable to start connection to MongoDB server, ERROR: ${error}`,
723
- });
735
+ );
724
736
 
725
- DyNTS_GlobalService.globalErrorHandler?.(d_error);
726
- reject(d_error);
737
+ const d_error: DyFM_Error = new DyFM_Error({
738
+ ...this._getDefaultErrorSettings(
739
+ 'startDB',
740
+ error
741
+ ),
742
+
743
+ errorCode: 'NTS-AS0-SDB1',
744
+ message: `Unable to start connection to MongoDB server, ERROR: ${error}`,
745
+ });
727
746
 
728
- } else {
729
- if (this.debugLog) DyFM_Log.error('\nMongoDB ERROR: ', error);
747
+ DyNTS_GlobalService.globalErrorHandler?.(d_error);
730
748
 
731
- const d_error: DyFM_Error = new DyFM_Error({
732
- ...this._getDefaultErrorSettings(
733
- 'mongoose.connection.on(error)',
734
- error
735
- ),
736
-
737
- errorCode: 'NTS-AS0-SDB2',
738
- message: `MongoDB ERROR: ${error}`,
739
- level: DyFM_ErrorLevel.critical,
740
- });
749
+ reject(d_error);
741
750
 
742
- DyNTS_GlobalService.globalErrorHandler?.(d_error);
743
- }
744
- });
751
+ } else {
752
+ if (this.debugLog) DyFM_Log.error('\nMongoDB ERROR: ', error);
745
753
 
746
- this.mongoose.connect(
747
- this._params.dbUri,
748
- {
749
- useNewUrlParser: true,
750
- useUnifiedTopology: true,
754
+ const d_error: DyFM_Error = new DyFM_Error({
755
+ ...this._getDefaultErrorSettings(
756
+ 'mongoose.connection.on(error)',
757
+ error
758
+ ),
759
+
760
+ errorCode: 'NTS-AS0-SDB2',
761
+ message: `MongoDB ERROR: ${error}`,
762
+ level: DyFM_ErrorLevel.critical,
763
+ });
764
+
765
+ DyNTS_GlobalService.globalErrorHandler?.(d_error);
766
+ }
767
+ });
768
+
769
+ try {
770
+ this.mongoose.connect(
771
+ this._params.dbUri,
772
+ {
773
+ useNewUrlParser: true,
774
+ useUnifiedTopology: true,
775
+ }
776
+ );
777
+ } catch (error) {
778
+ throw new DyFM_Error({
779
+ ...this._getDefaultErrorSettings('startDB', error),
780
+
781
+ errorCode: 'NTS-AS0-SDB3',
782
+ });
751
783
  }
752
- );
753
- }
754
- );
784
+ }
785
+ );
786
+ } catch (error) {
787
+ throw new DyFM_Error({
788
+ ...this._getDefaultErrorSettings('startDB', error),
789
+
790
+ errorCode: 'NTS-AS0-SDB0',
791
+ });
792
+ }
755
793
  }
756
794
 
757
795
  /**
@@ -760,79 +798,90 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
760
798
  private async initExpresses(): Promise<void> {
761
799
  if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. initExpresses');
762
800
 
763
- if (this._security && this._security !== DyNTS_RouteSecurity.secure) {
764
- if (!this._portSettings.httpPort) {
765
- let errorMsg: string =
766
- `\nYou have open routes, but httpPort is not set!` +
767
- `\nsecurity: ${this._security}` +
768
- `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
769
-
770
- errorMsg += '\n\nThe routes setted to use open server:';
771
- this._routingModules.forEach((module: DyNTS_RoutingModule): void => {
772
- if (module.security != DyNTS_RouteSecurity.secure) {
773
- errorMsg += `\n ${module.route} (security: ${module.security})`;
774
- errorMsg += `\n subroutes using open sever:`;
775
- module.endpoints.forEach((endpoint: DyNTS_Endpoint_Params): void => {
776
- if (endpoint.security != DyNTS_RouteSecurity.secure) {
777
- errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
778
- }
779
- });
780
- }
781
- });
801
+ try {
802
+ if (this._security && this._security !== DyNTS_RouteSecurity.secure) {
803
+ if (!this._portSettings.httpPort) {
804
+ let errorMsg: string =
805
+ `\nYou have open routes, but httpPort is not set!` +
806
+ `\nsecurity: ${this._security}` +
807
+ `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
808
+
809
+ errorMsg += '\n\nThe routes setted to use open server:';
810
+ this._routingModules.forEach((module: DyNTS_RoutingModule): void => {
811
+ if (module.security != DyNTS_RouteSecurity.secure) {
812
+ errorMsg += `\n ${module.route} (security: ${module.security})`;
813
+ errorMsg += `\n subroutes using open sever:`;
814
+ module.endpoints.forEach((endpoint: DyNTS_Endpoint_Params): void => {
815
+ if (endpoint.security != DyNTS_RouteSecurity.secure) {
816
+ errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
817
+ }
818
+ });
819
+ }
820
+ });
821
+
822
+ const error = new Error('Open routes cannot be established!');
823
+ const errorStack: string[] = error.stack.split('\n');
782
824
 
783
- const error = new Error('Open routes cannot be established!');
784
- const errorStack: string[] = error.stack.split('\n');
825
+ errorStack.splice(1, 2);
826
+ error.stack = errorStack.join('\n');
785
827
 
786
- errorStack.splice(1, 2);
787
- error.stack = errorStack.join('\n');
828
+ DyFM_Log.error(errorMsg);
788
829
 
789
- DyFM_Log.error(errorMsg);
830
+ throw error;
831
+ }
790
832
 
791
- throw error;
833
+ await this.initOpenExpress();
792
834
  }
793
835
 
794
- await this.initOpenExpress();
795
- }
836
+ if (this._security && this._security !== DyNTS_RouteSecurity.open) {
837
+ if (!this._cert || !this._portSettings.httpsPort) {
838
+ let errorMsg: string =
839
+ `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
840
+ `\nsecurity: ${this._security}` +
841
+ `\nset...` +
842
+ `\n(missing exact howto...)` +
843
+ /* `\n httpsPort and` +
844
+ `\n cert: {` +
845
+ `\n keyPath: FileSystem.PathLike,` +
846
+ `\n certPath: FileSystem.PathLike,` +
847
+ `\n }` + */
848
+ `\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
849
+
850
+ errorMsg += '\n\nThe routes setted to use secure server:';
851
+ this._routingModules.forEach((module: DyNTS_RoutingModule): void => {
852
+ if (module.security && module.security !== DyNTS_RouteSecurity.open) {
853
+ errorMsg += `\n ${module.route} (security: ${module.security})`;
854
+ errorMsg += `\n subroutes using secure sever:`;
855
+ module.endpoints.forEach((endpoint: DyNTS_Endpoint_Params): void => {
856
+ if (endpoint.security && endpoint.security !== DyNTS_RouteSecurity.open) {
857
+ errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
858
+ }
859
+ });
860
+ }
861
+ });
796
862
 
797
- if (this._security && this._security !== DyNTS_RouteSecurity.open) {
798
- if (!this._cert || !this._portSettings.httpsPort) {
799
- let errorMsg: string =
800
- `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
801
- `\nsecurity: ${this._security}` +
802
- `\nset...` +
803
- `\n(missing exact howto...)` +
804
- /* `\n httpsPort and` +
805
- `\n cert: {` +
806
- `\n keyPath: FileSystem.PathLike,` +
807
- `\n certPath: FileSystem.PathLike,` +
808
- `\n }` + */
809
- `\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
810
-
811
- errorMsg += '\n\nThe routes setted to use secure server:';
812
- this._routingModules.forEach((module: DyNTS_RoutingModule): void => {
813
- if (module.security && module.security !== DyNTS_RouteSecurity.open) {
814
- errorMsg += `\n ${module.route} (security: ${module.security})`;
815
- errorMsg += `\n subroutes using secure sever:`;
816
- module.endpoints.forEach((endpoint: DyNTS_Endpoint_Params): void => {
817
- if (endpoint.security && endpoint.security !== DyNTS_RouteSecurity.open) {
818
- errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
819
- }
820
- });
821
- }
822
- });
863
+ const error = new Error('Secure routes cannot be established!');
864
+ const errorStack: string[] = error.stack.split('\n');
823
865
 
824
- const error = new Error('Secure routes cannot be established!');
825
- const errorStack: string[] = error.stack.split('\n');
866
+ errorStack.splice(1, 2);
867
+ error.stack = errorStack.join('\n');
826
868
 
827
- errorStack.splice(1, 2);
828
- error.stack = errorStack.join('\n');
869
+ DyFM_Log.error(errorMsg);
829
870
 
830
- DyFM_Log.error(errorMsg);
871
+ throw error;
872
+ }
831
873
 
832
- throw error;
874
+ await this.initSecureExpress();
833
875
  }
834
-
835
- await this.initSecureExpress();
876
+ } catch (error) {
877
+ throw new DyFM_Error({
878
+ ...this._getDefaultErrorSettings(
879
+ 'initExpresses',
880
+ error
881
+ ),
882
+
883
+ errorCode: 'NTS-AS0-IE0',
884
+ });
836
885
  }
837
886
  }
838
887
 
@@ -868,6 +917,7 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
868
917
  */
869
918
  private async startExpresses(): Promise<void> {
870
919
  if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. startExpresses');
920
+
871
921
  try {
872
922
  if (this._security && this._security !== DyNTS_RouteSecurity.open) {
873
923
  await new Promise<void>((resolve, reject): void => {
@@ -1004,9 +1054,14 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
1004
1054
  });
1005
1055
  }
1006
1056
  } catch (error) {
1007
- DyFM_Log.error(`startExpresses failed...`, error);
1008
-
1009
- throw error;
1057
+ throw new DyFM_Error({
1058
+ ...this._getDefaultErrorSettings(
1059
+ 'startExpresses',
1060
+ error
1061
+ ),
1062
+
1063
+ errorCode: 'NTS-AS0-SE0',
1064
+ });
1010
1065
  }
1011
1066
  }
1012
1067
 
@@ -1053,96 +1108,118 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
1053
1108
  *
1054
1109
  */
1055
1110
  private async mountSecureRoutes (): Promise<void> {
1056
- if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. mountSecureRoutes');
1057
-
1058
- this.openExpress.use(
1059
- (error, req, res, next): Promise<void> => this.expressErrorHandling(error, req, res, next)
1060
- );
1061
-
1062
- await DyFM_Array.asyncForEach(
1063
- this._routingModules,
1064
- async (module: DyNTS_RoutingModule): Promise<void> => {
1065
- if (module.security !== DyNTS_RouteSecurity.open) {
1066
- if (this.logSetup) {
1067
- DyFM_Log.log(`route mount (secure): ${module.route}`);
1068
- }
1069
-
1070
- const existingRoutes: DyNTS_RoutingModule[] = this._routingModules.filter(
1071
- (mod: DyNTS_RoutingModule): boolean => mod.route === module.route
1072
- );
1111
+ try {
1112
+ if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. mountSecureRoutes');
1113
+
1114
+ this.openExpress.use(
1115
+ (error, req, res, next): Promise<void> => this.expressErrorHandling(error, req, res, next)
1116
+ );
1073
1117
 
1074
- if (1 < existingRoutes.length) {
1075
- const error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
1076
- const errorStack: string[] = error.stack.split('\n');
1118
+ await DyFM_Array.asyncForEach(
1119
+ this._routingModules,
1120
+ async (module: DyNTS_RoutingModule): Promise<void> => {
1121
+ if (module.security !== DyNTS_RouteSecurity.open) {
1122
+ if (this.logSetup) {
1123
+ DyFM_Log.log(`route mount (secure): ${module.route}`);
1124
+ }
1125
+
1126
+ const existingRoutes: DyNTS_RoutingModule[] = this._routingModules.filter(
1127
+ (mod: DyNTS_RoutingModule): boolean => mod.route === module.route
1128
+ );
1077
1129
 
1078
- errorStack.splice(1, 4);
1079
- error.stack = errorStack.join('\n');
1080
-
1081
- DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
1130
+ if (1 < existingRoutes.length) {
1131
+ const error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
1132
+ const errorStack: string[] = error.stack.split('\n');
1082
1133
 
1083
- throw new DyFM_Error({
1084
- ...this._getDefaultErrorSettings(
1085
- 'mountSecureRoutes',
1086
- error
1087
- ),
1134
+ errorStack.splice(1, 4);
1135
+ error.stack = errorStack.join('\n');
1136
+
1137
+ DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
1088
1138
 
1089
- errorCode: 'NTS-AS0-MSR1',
1090
- message: `ROUTE DUPLICATION: ${module.route}`,
1091
- });
1092
- }
1139
+ throw new DyFM_Error({
1140
+ ...this._getDefaultErrorSettings(
1141
+ 'mountSecureRoutes',
1142
+ error
1143
+ ),
1093
1144
 
1094
- this.secureExpress.use(module.route, module.secureRouter);
1145
+ errorCode: 'NTS-AS0-MSR1',
1146
+ message: `ROUTE DUPLICATION: ${module.route}`,
1147
+ });
1148
+ }
1149
+
1150
+ this.secureExpress.use(module.route, module.secureRouter);
1151
+ }
1095
1152
  }
1096
- }
1097
- );
1153
+ );
1154
+ } catch (error) {
1155
+ throw new DyFM_Error({
1156
+ ...this._getDefaultErrorSettings(
1157
+ 'mountSecureRoutes',
1158
+ error
1159
+ ),
1160
+
1161
+ errorCode: 'NTS-AS0-MSR0',
1162
+ });
1163
+ }
1098
1164
  }
1099
1165
 
1100
1166
  /**
1101
1167
  *
1102
1168
  */
1103
1169
  private async mountOpenRoutes(): Promise<void> {
1104
- if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. mountOpenRoutes');
1105
-
1106
- this.openExpress.use(
1107
- (error, req, res, next): Promise<void> => this.expressErrorHandling(error, req, res, next)
1108
- );
1109
-
1110
- await DyFM_Array.asyncForEach(
1111
- this._routingModules,
1112
- async (module: DyNTS_RoutingModule): Promise<void> => {
1113
- if (module.security !== DyNTS_RouteSecurity.secure) {
1114
- if (this.logSetup) {
1115
- DyFM_Log.log(`route mount (open): ${module.route}`);
1116
- }
1117
-
1118
- const existingRoutes: DyNTS_RoutingModule[] = this._routingModules.filter(
1119
- (mod: DyNTS_RoutingModule): boolean => mod.route === module.route
1120
- );
1121
-
1122
- if (1 < existingRoutes.length) {
1123
- const error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
1124
- const errorStack: string[] = error.stack.split('\n');
1125
-
1126
- errorStack.splice(1, 4);
1127
- error.stack = errorStack.join('\n');
1128
-
1129
- DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
1130
-
1131
- throw new DyFM_Error({
1132
- ...this._getDefaultErrorSettings(
1133
- 'mountOpenRoutes',
1134
- error
1135
- ),
1136
-
1137
- errorCode: 'NTS-AS0-MOR1',
1138
- message: `ROUTE DUPLICATION: ${module.route}`,
1139
- });
1170
+ try {
1171
+ if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. mountOpenRoutes');
1172
+
1173
+ this.openExpress.use(
1174
+ (error, req, res, next): Promise<void> => this.expressErrorHandling(error, req, res, next)
1175
+ );
1176
+
1177
+ await DyFM_Array.asyncForEach(
1178
+ this._routingModules,
1179
+ async (module: DyNTS_RoutingModule): Promise<void> => {
1180
+ if (module.security !== DyNTS_RouteSecurity.secure) {
1181
+ if (this.logSetup) {
1182
+ DyFM_Log.log(`route mount (open): ${module.route}`);
1183
+ }
1184
+
1185
+ const existingRoutes: DyNTS_RoutingModule[] = this._routingModules.filter(
1186
+ (mod: DyNTS_RoutingModule): boolean => mod.route === module.route
1187
+ );
1188
+
1189
+ if (1 < existingRoutes.length) {
1190
+ const error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
1191
+ const errorStack: string[] = error.stack.split('\n');
1192
+
1193
+ errorStack.splice(1, 4);
1194
+ error.stack = errorStack.join('\n');
1195
+
1196
+ DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
1197
+
1198
+ throw new DyFM_Error({
1199
+ ...this._getDefaultErrorSettings(
1200
+ 'mountOpenRoutes',
1201
+ error
1202
+ ),
1203
+
1204
+ errorCode: 'NTS-AS0-MOR1',
1205
+ message: `ROUTE DUPLICATION: ${module.route}`,
1206
+ });
1207
+ }
1208
+
1209
+ this.openExpress.use(module.route, module.openRouter);
1140
1210
  }
1141
-
1142
- this.openExpress.use(module.route, module.openRouter);
1143
1211
  }
1144
- }
1145
- );
1212
+ );
1213
+ } catch (error) {
1214
+ throw new DyFM_Error({
1215
+ ...this._getDefaultErrorSettings(
1216
+ 'mountOpenRoutes',
1217
+ error
1218
+ ),
1219
+
1220
+ errorCode: 'NTS-AS0-MOR0',
1221
+ });
1222
+ }
1146
1223
  }
1147
1224
 
1148
1225
  /**