@futdevpro/nts-dynamo 1.7.14 → 1.7.16

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 (26) hide show
  1. package/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
  2. package/lib/_models/control-models/endpoint-params.control-model.js +7 -1
  3. package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
  4. package/lib/_models/control-models/system-control.control-model.d.ts.map +1 -1
  5. package/lib/_models/control-models/system-control.control-model.js +0 -1
  6. package/lib/_models/control-models/system-control.control-model.js.map +1 -1
  7. package/lib/_services/base/data.service.d.ts.map +1 -1
  8. package/lib/_services/base/data.service.js +3 -1
  9. package/lib/_services/base/data.service.js.map +1 -1
  10. package/lib/_services/base/db.service.js +17 -13
  11. package/lib/_services/base/db.service.js.map +1 -1
  12. package/lib/_services/core/global.service.d.ts.map +1 -1
  13. package/lib/_services/core/global.service.js +4 -1
  14. package/lib/_services/core/global.service.js.map +1 -1
  15. package/lib/_services/server/app.server.d.ts +1 -0
  16. package/lib/_services/server/app.server.d.ts.map +1 -1
  17. package/lib/_services/server/app.server.js +95 -46
  18. package/lib/_services/server/app.server.js.map +1 -1
  19. package/lib/tsconfig.tsbuildinfo +1 -1
  20. package/package.json +2 -2
  21. package/src/_models/control-models/endpoint-params.control-model.ts +9 -1
  22. package/src/_models/control-models/system-control.control-model.ts +0 -1
  23. package/src/_services/base/data.service.ts +7 -1
  24. package/src/_services/base/db.service.ts +4 -4
  25. package/src/_services/core/global.service.ts +5 -1
  26. package/src/_services/server/app.server.ts +139 -66
@@ -200,13 +200,21 @@ export class DynamoNTS_EndpointParams{
200
200
  msg += this.getPathParamsLogContent(req);
201
201
 
202
202
  Dynamo_Log.error(msg);
203
- Dynamo_Log.log('ERROR:',
203
+ Dynamo_Log.error(
204
+ 'ERROR:',
204
205
  (error as Dynamo_Error)?.flag?.includes('DYNAMO') ?
205
206
  (error as Dynamo_Error).getErrorSimplified() :
206
207
  error,
207
208
  '\n'
208
209
  );
209
210
 
211
+ if ((error as Dynamo_Error)?.flag?.includes('DYNAMO')) {
212
+ if (!(error as Dynamo_Error).additionalContent) {
213
+ (error as Dynamo_Error).additionalContent = {};
214
+ }
215
+ (error as Dynamo_Error).additionalContent.endpointInfo = msg;
216
+ }
217
+
210
218
  await DynamoNTS_GlobalService.globalErrorHandler?.(error, req, res, issuer).catch(err => {
211
219
  Dynamo_Log.warn('DynamoNTS_GlobalService.globalErrorHandler failed to handle error: ', err);
212
220
  Dynamo_Log.warn('It will proceed as normal.');
@@ -3,7 +3,6 @@
3
3
 
4
4
  export class DynamoNTS_SystemControl {
5
5
  init: boolean = false;
6
- /* failed: boolean = false; */
7
6
  started: boolean = false;
8
7
 
9
8
  getReady(): boolean {
@@ -605,10 +605,15 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
605
605
  if (dataExists) {
606
606
  // if data exists do modify
607
607
  this.data = await this.dataDBService.modifyData(this.data, this.issuer);
608
+
608
609
  return this.data;
610
+
609
611
  } else {
610
612
  // if data not exists check that dependency already exists for this
611
- const dependencyExists = await this.getDependencyDataDBService().getDataById(this.data[this.depKey]);
613
+ const dependencyExists = await this.getDependencyDataDBService()
614
+ .getDataById(this.data[this.depKey])
615
+ .catch(error => null);
616
+
612
617
  if(!dependencyExists) {
613
618
  throw new Dynamo_Error({
614
619
  ...this._getDefaultErrorSettings(
@@ -630,6 +635,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
630
635
  } catch (error) {
631
636
  if (['NTS-DS0-SD1', 'NTS-DS0-SD2'].includes(error?.errorCode)) {
632
637
  throw error;
638
+
633
639
  } else {
634
640
  throw new Dynamo_Error({
635
641
  ...this._getDefaultErrorSettings('saveData', error),
@@ -116,10 +116,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
116
116
  data.__lastModified = new Date();
117
117
  data.__lastModifiedBy = issuer;
118
118
 
119
- /** EZ A SZAR TELJESEN SZAR, nem friss, a db-be mentett adatokat ad vissza, átír random value-kat */
119
+ /** EZ A SZAR TELJESEN SZAR, nem friss, nem a db-be mentett adatokat ad vissza, átír random value-kat össze vissza, WTF */
120
120
  /* let newData: T = */ await this.dataModel.findByIdAndUpdate(data._id, data).then(res => {
121
- if (res) {
122
- /* return res?.toObject() as T; */
121
+ /* if (res) {
122
+ //return res?.toObject() as T;
123
123
  } else {
124
124
  throw new Dynamo_Error({
125
125
  ...this._getDefaultErrorSettings(
@@ -133,7 +133,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
133
133
  additionalContent: { data },
134
134
  issuer,
135
135
  });
136
- }
136
+ } */
137
137
  }).catch(error => {
138
138
  throw new Dynamo_Error({
139
139
  ...this._getDefaultErrorSettings('modifyData', error, issuer),
@@ -63,7 +63,11 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
63
63
 
64
64
  this.instance.authService = set.authService;
65
65
  this.instance.emailServiceCollection = set.emailServiceCollection;
66
- DynamoNTS_GlobalService.globalErrorHandler = set.errorHandler;
66
+
67
+ DynamoNTS_GlobalService.globalErrorHandler = set.errorHandler ?? (async (error: any) => {
68
+ Dynamo_Log.warn(`globalErrorHandler not set!`);
69
+ Dynamo_Log.error(`ERROR:\n`, error)
70
+ });
67
71
  } catch (error) {
68
72
  Dynamo_Log.error(`Failed to create DynamoNTS_GlobalService.`, error);
69
73
  /* error = new Dynamo_Error({
@@ -222,6 +222,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
222
222
  protected logSetup: boolean;
223
223
  protected deepLog: boolean;
224
224
  protected logFn: boolean;
225
+ protected debugLog: boolean;
225
226
 
226
227
  constructor(extended?: boolean){
227
228
  super();
@@ -417,6 +418,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
417
418
 
418
419
  if (this.constructErrors.length) {
419
420
  Dynamo_Log.error(`${this._params.name} start failed. ERROR`, this.constructErrors);
421
+
420
422
  throw new Dynamo_Error({
421
423
  ...this._getDefaultErrorSettings(
422
424
  'ready',
@@ -524,38 +526,60 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
524
526
  */
525
527
  private async startDB(): Promise<void> {
526
528
  if (this.logFn && this.deepLog) console.log('\nfn:. startDB');
529
+
527
530
  await new Promise<void>(
528
531
  async (resolve, reject) => {
529
532
  this.systemControls.mongoose.init = true;
533
+
530
534
  this.mongoose.connection
535
+ .once('open', () => {
536
+ this.systemControls.mongoose.started = true;
537
+ Dynamo_Log.success('\nConnected to MongoDB\n');
538
+
539
+ resolve();
540
+ })
531
541
  .on('error', (error) => {
532
- this.systemControls.mongoose.started = false;
533
- this.constructErrors.push(error);
534
- Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
535
- reject(
536
- new Dynamo_Error({
542
+ if (!this.systemControls.mongoose.started) {
543
+ this.constructErrors.push(error);
544
+
545
+ if (this.debugLog) Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
546
+
547
+ const d_error: Dynamo_Error = new Dynamo_Error({
537
548
  ...this._getDefaultErrorSettings(
538
549
  'startDB',
539
550
  error
540
551
  ),
541
-
552
+
542
553
  errorCode: 'NTS-AS0-SDB1',
543
- message: `Unable to connect to MongoDB server, ERROR: ${error}`,
544
- })
545
- );
546
- })
547
- .once('open', () => {
548
- this.systemControls.mongoose.started = true;
549
- Dynamo_Log.success('\nConnected to MongoDB\n');
550
- resolve();
554
+ message: `Unable to start connection to MongoDB server, ERROR: ${error}`,
555
+ });
556
+
557
+ DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
558
+ reject(d_error);
559
+
560
+ } else {
561
+ if (this.debugLog) Dynamo_Log.error('\nMongoDB ERROR: ', error);
562
+
563
+ const d_error: Dynamo_Error = new Dynamo_Error({
564
+ ...this._getDefaultErrorSettings(
565
+ 'mongoose.connection.on(error)',
566
+ error
567
+ ),
568
+
569
+ errorCode: 'NTS-AS0-SDB2',
570
+ message: `MongoDB ERROR: ${error}`,
571
+ });
572
+
573
+ DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
574
+ }
551
575
  });
552
576
 
553
577
  this.mongoose.connect(
554
- this._params.dbUri,
555
- {
556
- useNewUrlParser: true,
557
- useUnifiedTopology: true
558
- }
578
+ this._params.dbUri,
579
+ {
580
+ useNewUrlParser: true,
581
+ useUnifiedTopology: true
582
+ }
559
583
  );
560
584
  }
561
585
  );
@@ -566,6 +590,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
566
590
  */
567
591
  private async initExpresses(): Promise<void> {
568
592
  if (this.logFn && this.deepLog) console.log('\nfn:. initExpresses');
593
+
569
594
  if (this._security && this._security !== DynamoNTS_RouteSecurity.secure) {
570
595
  if (!this._portSettings.httpPort) {
571
596
  let errorMsg: string =
@@ -603,11 +628,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
603
628
  `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
604
629
  `\nsecurity: ${this._security}` +
605
630
  `\nset...` +
606
- `\n httpsPort and` +
631
+ `\n(missing exact howto...)` +
632
+ /* `\n httpsPort and` +
607
633
  `\n cert: {` +
608
634
  `\n keyPath: FileSystem.PathLike,` +
609
635
  `\n certPath: FileSystem.PathLike,` +
610
- `\n }` +
636
+ `\n }` + */
611
637
  `\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
612
638
 
613
639
  errorMsg += '\n\nThe routes setted to use secure server:';
@@ -674,37 +700,56 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
674
700
  .listen(this._portSettings.httpsPort, 'localhost', 0, () => {
675
701
  this.systemControls.httpsServer.started = true;
676
702
  Dynamo_Log.success(`\nHTTPS (secure) server is listening on port: ${this._portSettings.httpsPort}`);
703
+
677
704
  resolve();
678
705
  })
679
706
  .on('error', (error) => {
680
- this.systemControls.httpsServer.started = false;
681
- this.constructErrors.push(error);
682
- Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
683
- reject(
684
- new Dynamo_Error({
707
+ if (this.debugLog) Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
708
+
709
+ if (!this.systemControls.httpsServer.started) {
710
+ const d_error: Dynamo_Error = new Dynamo_Error({
685
711
  ...this._getDefaultErrorSettings(
686
712
  'startExpresses',
687
713
  error
688
714
  ),
689
715
 
690
716
  errorCode: 'NTS-AS0-SE1',
691
- message: `HTTPS (secure) server ERROR`,
692
- })
693
- );
694
- })
695
- .on('uncaughtException', (ex) => {
696
- Dynamo_Log.warn(
697
- `\nHTTPS (secure) server uncaughtException`,
698
- new Dynamo_Error({
717
+ message: `HTTPS (secure) start server ERROR`,
718
+ });
719
+
720
+ this.constructErrors.push(d_error);
721
+ DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
722
+
723
+ reject(d_error);
724
+
725
+ } else {
726
+ const d_error: Dynamo_Error = new Dynamo_Error({
699
727
  ...this._getDefaultErrorSettings(
700
- 'startExpresses',
701
- ex
728
+ 'httpsServer.on(error)',
729
+ error
702
730
  ),
703
731
 
704
732
  errorCode: 'NTS-AS0-SE2',
705
- message: `HTTPS (secure) server uncaughtException`,
706
- })
707
- );
733
+ message: `HTTPS (secure) server ERROR`,
734
+ });
735
+
736
+ DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
737
+ }
738
+ })
739
+ .on('uncaughtException', (ex) => {
740
+ const d_error: Dynamo_Error = new Dynamo_Error({
741
+ ...this._getDefaultErrorSettings(
742
+ 'httpsServer.on(uncaughtException)',
743
+ ex
744
+ ),
745
+
746
+ errorCode: 'NTS-AS0-SE3',
747
+ message: `HTTPS (secure) server uncaughtException`,
748
+ });
749
+
750
+ if (this.debugLog) Dynamo_Log.warn(`\nHTTPS (secure) server uncaughtException`, d_error);
751
+
752
+ DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
708
753
  });
709
754
  });
710
755
  }
@@ -716,38 +761,56 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
716
761
  .listen(this._portSettings.httpPort, () => {
717
762
  this.systemControls.httpServer.started = true;
718
763
  Dynamo_Log.success(`\nHTTP (open) server is listening on port: ${this._portSettings.httpPort}`);
764
+
719
765
  resolve();
720
766
  })
721
767
  .on('error', (error) => {
722
- this.systemControls.httpServer.started = false;
723
- this.constructErrors.push(error);
768
+ if (this.debugLog) Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
724
769
 
725
- Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
726
- reject(
727
- new Dynamo_Error({
770
+ if (!this.systemControls.httpServer.started) {
771
+ const d_error: Dynamo_Error = new Dynamo_Error({
728
772
  ...this._getDefaultErrorSettings(
729
773
  'startExpresses',
730
774
  error
731
775
  ),
732
776
 
733
777
  errorCode: 'NTS-AS0-SE3',
734
- message: `HTTP (open) server ERROR`,
735
- })
736
- );
737
- })
738
- .on('uncaughtException', (ex) => {
739
- Dynamo_Log.warn(
740
- `\nHTTP (open) server uncaughtException`,
741
- new Dynamo_Error({
778
+ message: `HTTP (open) start server ERROR`,
779
+ });
780
+
781
+ this.constructErrors.push(d_error);
782
+ DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
783
+
784
+ reject(d_error);
785
+
786
+ } else {
787
+ const d_error: Dynamo_Error = new Dynamo_Error({
742
788
  ...this._getDefaultErrorSettings(
743
- 'startExpresses',
744
- ex
789
+ 'httpServer.on(error)',
790
+ error
745
791
  ),
746
792
 
747
793
  errorCode: 'NTS-AS0-SE4',
748
- message: `HTTP (open) server uncaughtException`,
749
- })
750
- );
794
+ message: `HTTP (open) server ERROR`,
795
+ });
796
+
797
+ DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
798
+ }
799
+ })
800
+ .on('uncaughtException', (ex) => {
801
+ const d_error: Dynamo_Error = new Dynamo_Error({
802
+ ...this._getDefaultErrorSettings(
803
+ 'httpServer.on(uncaughtException)',
804
+ ex
805
+ ),
806
+
807
+ errorCode: 'NTS-AS0-SE5',
808
+ message: `HTTP (open) server uncaughtException`,
809
+ });
810
+
811
+ if (this.debugLog) Dynamo_Log.warn(`\nHTTP (open) server uncaughtException`, d_error);
812
+
813
+ DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
751
814
  });
752
815
  });
753
816
  }
@@ -760,19 +823,29 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
760
823
  /**
761
824
  *
762
825
  */
763
- private async expressErrorHandling(err, req, res, next): Promise<void> {
826
+ private async expressErrorHandling(error, req, res, next): Promise<void> {
764
827
  try {
765
- if (err) {
766
- if (DynamoNTS_GlobalService.globalErrorHandler) {
767
- Dynamo_Log.error('unhandled express ERROR (must be a parsing error...)');
768
- await DynamoNTS_GlobalService.globalErrorHandler?.(err, req, res);
769
- } else {
770
- Dynamo_Log.error('unhandled express ERROR (must be a parsing error...)', err);
771
- }
828
+ if (error) {
829
+ const d_error: Dynamo_Error = new Dynamo_Error({
830
+ ...this._getDefaultErrorSettings(
831
+ 'expressErrorHandling',
832
+ error
833
+ ),
834
+
835
+ errorCode: 'NTS-AS0-EEH1',
836
+ message: `Express ERROR`,
837
+ additionalContent: {
838
+ req,
839
+ res,
840
+ },
841
+ });
842
+
843
+ await DynamoNTS_GlobalService.globalErrorHandler?.(d_error, req, res);
844
+
772
845
  } else {
773
846
  Dynamo_Log.H_error(
774
847
  'WTF??? express error; without error?...' +
775
- '\nerr:', err,
848
+ '\nerr:', error,
776
849
  '\nreq:', req,
777
850
  '\nres:', res
778
851
  );