@futdevpro/nts-dynamo 1.7.2 → 1.7.5

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 (72) hide show
  1. package/.copilot/patterns.json +8 -0
  2. package/lib/_constants/mocks/app-extended-server.mock.d.ts +1 -1
  3. package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -1
  4. package/lib/_constants/mocks/app-server.mock.d.ts +1 -1
  5. package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
  6. package/lib/_constants/mocks/socket-server.mock.d.ts.map +1 -1
  7. package/lib/_constants/mocks/socket-server.mock.js +4 -1
  8. package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
  9. package/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
  10. package/lib/_models/control-models/endpoint-params.control-model.js +3 -22
  11. package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
  12. package/lib/_models/control-models/port-settings.control-model.d.ts +11 -0
  13. package/lib/_models/control-models/port-settings.control-model.d.ts.map +1 -0
  14. package/lib/_models/control-models/port-settings.control-model.js +26 -0
  15. package/lib/_models/control-models/port-settings.control-model.js.map +1 -0
  16. package/lib/_models/control-models/socket-presence.control-model.d.ts +5 -3
  17. package/lib/_models/control-models/socket-presence.control-model.d.ts.map +1 -1
  18. package/lib/_models/control-models/socket-presence.control-model.js +34 -20
  19. package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
  20. package/lib/_models/interfaces/index.d.ts +1 -1
  21. package/lib/_models/interfaces/index.d.ts.map +1 -1
  22. package/lib/_models/interfaces/index.js +1 -1
  23. package/lib/_models/interfaces/index.js.map +1 -1
  24. package/lib/_modules/app-extended.index.d.ts +1 -1
  25. package/lib/_modules/app-extended.index.d.ts.map +1 -1
  26. package/lib/_modules/app-extended.index.js +1 -1
  27. package/lib/_modules/app-extended.index.js.map +1 -1
  28. package/lib/_modules/app.index.d.ts +1 -1
  29. package/lib/_modules/app.index.d.ts.map +1 -1
  30. package/lib/_modules/app.index.js +1 -1
  31. package/lib/_modules/app.index.js.map +1 -1
  32. package/lib/_services/base/data.service.d.ts +1 -1
  33. package/lib/_services/base/data.service.d.ts.map +1 -1
  34. package/lib/_services/base/data.service.js +5 -4
  35. package/lib/_services/base/data.service.js.map +1 -1
  36. package/lib/_services/core/api.service.d.ts +1 -0
  37. package/lib/_services/core/api.service.d.ts.map +1 -1
  38. package/lib/_services/core/api.service.js +19 -21
  39. package/lib/_services/core/api.service.js.map +1 -1
  40. package/lib/_services/server/app-extended.server.d.ts +2 -2
  41. package/lib/_services/server/app-extended.server.d.ts.map +1 -1
  42. package/lib/_services/server/app-extended.server.js +13 -11
  43. package/lib/_services/server/app-extended.server.js.map +1 -1
  44. package/lib/_services/server/app.server.d.ts +9 -70
  45. package/lib/_services/server/app.server.d.ts.map +1 -1
  46. package/lib/_services/server/app.server.js +83 -34
  47. package/lib/_services/server/app.server.js.map +1 -1
  48. package/lib/_services/socket/socket-server.service.d.ts +3 -3
  49. package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
  50. package/lib/_services/socket/socket-server.service.js +8 -7
  51. package/lib/_services/socket/socket-server.service.js.map +1 -1
  52. package/lib/tsconfig.tsbuildinfo +1 -1
  53. package/package.json +4 -3
  54. package/src/_constants/mocks/app-extended-server.mock.ts +1 -1
  55. package/src/_constants/mocks/app-server.mock.ts +1 -1
  56. package/src/_constants/mocks/socket-server.mock.ts +4 -1
  57. package/src/_models/control-models/endpoint-params.control-model.ts +11 -24
  58. package/src/_models/control-models/port-settings.control-model.ts +27 -0
  59. package/src/_models/control-models/socket-presence.control-model.ts +70 -21
  60. package/src/_models/interfaces/index.ts +1 -1
  61. package/src/_modules/app-extended.index.ts +1 -1
  62. package/src/_modules/app.index.ts +1 -1
  63. package/src/_services/base/data.service.ts +8 -5
  64. package/src/_services/core/api.service.ts +36 -21
  65. package/src/_services/server/app-extended.server.ts +19 -11
  66. package/src/_services/server/app.server.ts +159 -110
  67. package/src/_services/socket/socket-server.service.ts +10 -7
  68. package/lib/_models/interfaces/port-settings.interface.d.ts +0 -5
  69. package/lib/_models/interfaces/port-settings.interface.d.ts.map +0 -1
  70. package/lib/_models/interfaces/port-settings.interface.js +0 -3
  71. package/lib/_models/interfaces/port-settings.interface.js.map +0 -1
  72. package/src/_models/interfaces/port-settings.interface.ts +0 -5
@@ -7,15 +7,13 @@ import * as Https from 'https';
7
7
  import * as FileSystem from 'fs';
8
8
  import * as BodyParser from 'body-parser';
9
9
 
10
- import { Request, Response } from 'express';
11
-
12
10
  import { Dynamo_Array, Dynamo_Error, dynamo_error_default, Dynamo_Log, second, wait } from '@futdevpro/fsm-dynamo';
13
11
 
14
12
  import { DynamoNTS_SingletonService } from '../base/singleton.service';
15
13
  import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
16
14
  import { DynamoNTS_RoutingModule } from '../route/routing-module.service';
17
15
  import { DynamoNTS_GlobalService } from '../core/global.service';
18
- import { DynamoNTS_PortSettings } from '../../_models/interfaces/port-settings.interface';
16
+ import { DynamoNTS_PortSettings } from '../../_models/control-models/port-settings.control-model';
19
17
  import { DynamoNTS_CertificationSettings } from '../../_models/interfaces/certification-settings.interface';
20
18
  import { DynamoNTS_GlobalServiceSettings } from '../../_models/interfaces/global-service-settings.interface';
21
19
  import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
@@ -24,7 +22,6 @@ import { DynamoNTS_EndpointParams } from '../../_models/control-models/endpoint-
24
22
  import { DynamoNTS_AppSystemControls } from '../../_models/control-models/app-system-controls.control-model';
25
23
 
26
24
 
27
-
28
25
  /**
29
26
  * This will be the MAIN service of our server project,
30
27
  * follow the types and type instructions while setting up your project
@@ -198,8 +195,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
198
195
  private _security: DynamoNTS_RouteSecurity;
199
196
  protected get security(): DynamoNTS_RouteSecurity { return this._security; }
200
197
 
201
- protected _ports: DynamoNTS_PortSettings;
202
- protected get ports(): DynamoNTS_PortSettings { return this._ports; }
198
+ protected _portSettings: DynamoNTS_PortSettings;
199
+ protected get portSettings(): DynamoNTS_PortSettings { return this._portSettings; }
203
200
 
204
201
  private _cert?: DynamoNTS_CertificationSettings;
205
202
  protected get cert(): DynamoNTS_CertificationSettings { return this._cert; }
@@ -214,6 +211,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
214
211
 
215
212
  private _routingModules: DynamoNTS_RoutingModule[] = [];
216
213
 
214
+ defaultErrorUserMsg =
215
+ `We encountered a Server Error, ` +
216
+ `\nplease contact the responsible development team.\n` +
217
+ `\n(Internal Server error)`;
218
+
217
219
  /**
218
220
  * setting this value to true, enables this service debug logs
219
221
  */
@@ -245,7 +247,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
245
247
  });
246
248
 
247
249
  this.asyncConstruct(extended).catch((error: any) => {
248
- Dynamo_Log.error(`\nApplication: ${this._params.name} start failed.\n`, error);
250
+ Dynamo_Log.error(
251
+ `\nApplication: ${this._params.name} start failed.` +
252
+ `\n`, error
253
+ );
249
254
  });
250
255
  }
251
256
 
@@ -253,11 +258,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
253
258
  if (this.logFn && this.deepLog) console.log('\nfn:. asyncConstruct');
254
259
  try {
255
260
  this.systemControls.app.init = true;
256
- this._params = this.getAppParams();
261
+ this._params = this.getAppParams();
257
262
 
258
- dynamo_error_default.issuerSystem = this._params.systemName;
263
+ dynamo_error_default.issuerSystem = this._params.systemName;
259
264
 
260
- this.overrideDynamoNTSGlobalSettings?.();
265
+ this.overrideDynamoNTSGlobalSettings?.();
261
266
 
262
267
  this.logSetup = dynamoNTS_globalSettings.logSetup;
263
268
 
@@ -266,7 +271,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
266
271
  DynamoNTS_GlobalService.setParams(this.params);
267
272
 
268
273
  if (this.getPortSettings) {
269
- this._ports = this.getPortSettings();
274
+ this._portSettings = this.getPortSettings();
270
275
  }
271
276
 
272
277
  if (this.getCertificationSettings) {
@@ -321,8 +326,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
321
326
  this.constructErrors.push(error);
322
327
  Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
323
328
  throw new Dynamo_Error({
329
+ ...this._getDefaultErrorSettings(
330
+ 'asyncConstruct',
331
+ error
332
+ ),
333
+
324
334
  errorCode: 'NTS-AS0-001',
325
- error: error,
326
335
  additionalContent: {
327
336
  constructErrors: this.constructErrors,
328
337
  systemControls: this.systemControls,
@@ -345,7 +354,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
345
354
  if (this.constructErrors.length) {
346
355
  Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
347
356
  throw new Dynamo_Error({
348
- message: `${this._params.name} start failed. ERRORS`,
357
+ ...this._getDefaultErrorSettings(
358
+ 'ready',
359
+ new Error(`${this._params.name} start failed. ERRORS`)
360
+ ),
361
+
362
+ errorCode: 'NTS-AS0-R1',
349
363
  additionalContent: this.constructErrors.length === 1 ? this.constructErrors[0] : { errors: this.constructErrors },
350
364
  });
351
365
  }
@@ -369,7 +383,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
369
383
  if (timeout < +new Date() - start) {
370
384
  Dynamo_Log.error(`${this._params.name} start failed. TIMEOUT`, this.constructErrors);
371
385
  throw new Dynamo_Error({
372
- message: `${this._params.name} start failed. TIMEOUT`,
386
+ ...this._getDefaultErrorSettings(
387
+ 'ready',
388
+ new Error(`${this._params.name} start failed. TIMEOUT`)
389
+ ),
390
+
391
+ errorCode: 'NTS-AS0-R2',
373
392
  additionalContent: {
374
393
  constructErrors: this.constructErrors,
375
394
  systemControls: this.systemControls,
@@ -385,7 +404,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
385
404
  if (this.constructErrors.length) {
386
405
  Dynamo_Log.error(`${this._params.name} start failed. ERROR`, this.constructErrors);
387
406
  throw new Dynamo_Error({
388
- message: `${this._params.name} start failed. ERROR`,
407
+ ...this._getDefaultErrorSettings(
408
+ 'ready',
409
+ new Error(`${this._params.name} start failed. ERROR`)
410
+ ),
411
+
412
+ errorCode: 'NTS-AS0-R3',
389
413
  additionalContent: this.constructErrors,
390
414
  });
391
415
  }
@@ -411,8 +435,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
411
435
 
412
436
  Dynamo_Log.error(msg, this.constructErrors);
413
437
  throw new Dynamo_Error({
414
- errorCode: 'NTS-AS0-110',
415
- message: msg,
438
+ ...this._getDefaultErrorSettings(
439
+ 'ready',
440
+ new Error(msg)
441
+ ),
442
+
443
+ errorCode: 'NTS-AS0-R4',
416
444
  additionalContent: {
417
445
  constructErrors: this.constructErrors,
418
446
  systemControls: this.systemControls,
@@ -434,11 +462,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
434
462
 
435
463
  if (this.systemControls.mongoose.init) {
436
464
  this.systemControls.mongoose.started = false;
465
+
437
466
  if (this.mongoose) {
438
467
  await Dynamo_Array.asyncForEach(Object.keys(this.mongoose.models), async (modelName) => {
439
468
  await this.mongoose.deleteModel(modelName);
440
469
  });
441
470
  await this.mongoose.disconnect();
471
+
442
472
  } else {
443
473
  Dynamo_Log.error(`\nMongoose not found.`);
444
474
  }
@@ -490,9 +520,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
490
520
  Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
491
521
  reject(
492
522
  new Dynamo_Error({
493
- errorCode: 'NTS-AS0-100',
523
+ ...this._getDefaultErrorSettings(
524
+ 'startDB',
525
+ error
526
+ ),
527
+
528
+ errorCode: 'NTS-AS0-SDB1',
494
529
  message: `Unable to connect to MongoDB server, ERROR: ${error}`,
495
- error: error,
496
530
  })
497
531
  );
498
532
  })
@@ -519,7 +553,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
519
553
  private async initExpresses(): Promise<void> {
520
554
  if (this.logFn && this.deepLog) console.log('\nfn:. initExpresses');
521
555
  if (this._security && this._security !== DynamoNTS_RouteSecurity.secure) {
522
- if (!this._ports.httpPort) {
556
+ if (!this._portSettings.httpPort) {
523
557
  let errorMsg: string =
524
558
  `\nYou have open routes, but httpPort is not set!` +
525
559
  `\nsecurity: ${this._security}` +
@@ -550,7 +584,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
550
584
  }
551
585
 
552
586
  if (this._security && this._security !== DynamoNTS_RouteSecurity.open) {
553
- if (!this._cert || !this._ports.httpsPort) {
587
+ if (!this._cert || !this._portSettings.httpsPort) {
554
588
  let errorMsg: string =
555
589
  `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
556
590
  `\nsecurity: ${this._security}` +
@@ -593,8 +627,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
593
627
  protected async initOpenExpress(): Promise<void> {
594
628
  if (this.logFn) console.log('\nfn:. initOpenExpress');
595
629
  this.openExpress = Express();
596
- this.openExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
597
- this.openExpress.use(BodyParser.json({ limit: '50mb' }));
630
+ this.openExpress.use(BodyParser.urlencoded(this._portSettings.httpEncodeSettings));
631
+ this.openExpress.use(BodyParser.json(this._portSettings.httpJsonSettings));
598
632
  }
599
633
 
600
634
  /**
@@ -603,8 +637,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
603
637
  protected async initSecureExpress(): Promise<void> {
604
638
  if (this.logFn) console.log('\nfn:. initSecureExpress');
605
639
  this.secureExpress = Express();
606
- this.secureExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
607
- this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
640
+ this.secureExpress.use(BodyParser.urlencoded(this._portSettings.httpsEncodeSettings));
641
+ this.secureExpress.use(BodyParser.json(this._portSettings.httpsJsonSettings));
608
642
 
609
643
  const options = {
610
644
  key: FileSystem.readFileSync(this._cert.keyPath),
@@ -623,9 +657,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
623
657
  await new Promise<void>((resolve, reject) => {
624
658
  this.systemControls.httpsServer.init = true;
625
659
  this.httpsServer
626
- .listen(this._ports.httpsPort, 'localhost', 0, () => {
660
+ .listen(this._portSettings.httpsPort, 'localhost', 0, () => {
627
661
  this.systemControls.httpsServer.started = true;
628
- Dynamo_Log.success(`\nHTTPS (secure) server is listening on port: ${this._ports.httpsPort}`);
662
+ Dynamo_Log.success(`\nHTTPS (secure) server is listening on port: ${this._portSettings.httpsPort}`);
629
663
  resolve();
630
664
  })
631
665
  .on('error', (error) => {
@@ -634,9 +668,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
634
668
  Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
635
669
  reject(
636
670
  new Dynamo_Error({
637
- errorCode: 'NTS-AS0-001',
671
+ ...this._getDefaultErrorSettings(
672
+ 'startExpresses',
673
+ error
674
+ ),
675
+
676
+ errorCode: 'NTS-AS0-SE1',
638
677
  message: `HTTPS (secure) server ERROR`,
639
- error: error,
640
678
  })
641
679
  );
642
680
  })
@@ -644,9 +682,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
644
682
  Dynamo_Log.warn(
645
683
  `\nHTTPS (secure) server uncaughtException`,
646
684
  new Dynamo_Error({
647
- errorCode: 'NTS-AS0-002',
685
+ ...this._getDefaultErrorSettings(
686
+ 'startExpresses',
687
+ ex
688
+ ),
689
+
690
+ errorCode: 'NTS-AS0-SE2',
648
691
  message: `HTTPS (secure) server uncaughtException`,
649
- error: ex,
650
692
  })
651
693
  );
652
694
  });
@@ -657,9 +699,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
657
699
  this.systemControls.httpServer.init = true;
658
700
  await new Promise<void>((resolve, reject) => {
659
701
  this.httpServer = this.openExpress
660
- .listen(this._ports.httpPort, () => {
702
+ .listen(this._portSettings.httpPort, () => {
661
703
  this.systemControls.httpServer.started = true;
662
- Dynamo_Log.success(`\nHTTP (open) server is listening on port: ${this._ports.httpPort}`);
704
+ Dynamo_Log.success(`\nHTTP (open) server is listening on port: ${this._portSettings.httpPort}`);
663
705
  resolve();
664
706
  })
665
707
  .on('error', (error) => {
@@ -669,9 +711,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
669
711
  Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
670
712
  reject(
671
713
  new Dynamo_Error({
672
- errorCode: 'NTS-AS0-003',
714
+ ...this._getDefaultErrorSettings(
715
+ 'startExpresses',
716
+ error
717
+ ),
718
+
719
+ errorCode: 'NTS-AS0-SE3',
673
720
  message: `HTTP (open) server ERROR`,
674
- error: error,
675
721
  })
676
722
  );
677
723
  })
@@ -679,9 +725,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
679
725
  Dynamo_Log.warn(
680
726
  `\nHTTP (open) server uncaughtException`,
681
727
  new Dynamo_Error({
682
- errorCode: 'NTS-AS0-004',
728
+ ...this._getDefaultErrorSettings(
729
+ 'startExpresses',
730
+ ex
731
+ ),
732
+
733
+ errorCode: 'NTS-AS0-SE4',
683
734
  message: `HTTP (open) server uncaughtException`,
684
- error: ex
685
735
  })
686
736
  );
687
737
  });
@@ -693,11 +743,50 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
693
743
  }
694
744
  }
695
745
 
746
+ private async expressErrorHandling(err, req, res, next): Promise<void> {
747
+ try {
748
+ if (err) {
749
+ if (DynamoNTS_GlobalService.globalErrorHandler) {
750
+ Dynamo_Log.error('unhandled express ERROR (must be a parsing error...)');
751
+ await DynamoNTS_GlobalService.globalErrorHandler?.(err, req, res);
752
+ } else {
753
+ Dynamo_Log.error('unhandled express ERROR (must be a parsing error...)', err);
754
+ }
755
+ } else {
756
+ Dynamo_Log.H_error(
757
+ 'WTF??? express error; without error?...' +
758
+ '\nerr:', err,
759
+ '\nreq:', req,
760
+ '\nres:', res
761
+ );
762
+ }
763
+
764
+ res.status(err?.status || 500);
765
+ res.render('error', {
766
+ message: err?.message,
767
+ });
768
+ res.send(err);
769
+ } catch (error) {
770
+ Dynamo_Log.H_error(
771
+ 'MULTILEVEL ERROR (expressErrorHandling)....', error
772
+ );
773
+
774
+ res.status(err?.status || 500);
775
+ res.render('error', {
776
+ message: err?.message,
777
+ });
778
+ res.send(err);
779
+ }
780
+ }
781
+
696
782
  /**
697
783
  *
698
784
  */
699
785
  private async mountSecureRoutes (): Promise<void> {
700
786
  if (this.logFn && this.deepLog) console.log('\nfn:. mountSecureRoutes');
787
+
788
+ this.openExpress.use(this.expressErrorHandling);
789
+
701
790
  await Dynamo_Array.asyncForEach(this._routingModules, async (module: DynamoNTS_RoutingModule) => {
702
791
  if (module.security !== DynamoNTS_RouteSecurity.open) {
703
792
  if (this.logSetup) {
@@ -709,16 +798,20 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
709
798
  );
710
799
 
711
800
  if (1 < existingRoutes.length) {
712
- let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
801
+ let error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
713
802
  let errorStack: string[] = error.stack.split('\n');
714
803
  errorStack.splice(1, 4);
715
804
  error.stack = errorStack.join('\n');
716
805
 
717
806
  Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
718
807
  throw new Dynamo_Error({
719
- errorCode: 'NTS-AS0-005',
808
+ ...this._getDefaultErrorSettings(
809
+ 'mountSecureRoutes',
810
+ error
811
+ ),
812
+
813
+ errorCode: 'NTS-AS0-MSR1',
720
814
  message: `ROUTE DUPLICATION: ${module.route}`,
721
- error: error,
722
815
  });
723
816
  }
724
817
 
@@ -732,6 +825,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
732
825
  */
733
826
  private async mountOpenRoutes(): Promise<void> {
734
827
  if (this.logFn && this.deepLog) console.log('\nfn:. mountOpenRoutes');
828
+
829
+ this.openExpress.use(this.expressErrorHandling);
830
+
735
831
  await Dynamo_Array.asyncForEach(this._routingModules, async (module: DynamoNTS_RoutingModule) => {
736
832
  if (module.security !== DynamoNTS_RouteSecurity.secure) {
737
833
  if (this.logSetup) {
@@ -743,16 +839,20 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
743
839
  );
744
840
 
745
841
  if (1 < existingRoutes.length) {
746
- let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
842
+ let error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
747
843
  let errorStack: string[] = error.stack.split('\n');
748
844
  errorStack.splice(1, 4);
749
845
  error.stack = errorStack.join('\n');
750
846
 
751
847
  Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
752
848
  throw new Dynamo_Error({
753
- errorCode: 'NTS-AS0-006',
849
+ ...this._getDefaultErrorSettings(
850
+ 'mountOpenRoutes',
851
+ error
852
+ ),
853
+
854
+ errorCode: 'NTS-AS0-MOR1',
754
855
  message: `ROUTE DUPLICATION: ${module.route}`,
755
- error: error,
756
856
  });
757
857
  }
758
858
 
@@ -769,8 +869,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
769
869
  this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
770
870
  if (!module.security) {
771
871
  Dynamo_Log.warn(`RoutingModule security is not set for ${module.route}\n`);
872
+
772
873
  } else if (!this._security) {
773
874
  this._security = module.security;
875
+
774
876
  } else if (this._security !== module.security) {
775
877
  this._security = DynamoNTS_RouteSecurity.both;
776
878
  }
@@ -788,46 +890,25 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
788
890
  Dynamo_Log.warn(msg);
789
891
  }
790
892
  }
893
+
894
+ private _getDefaultErrorSettings(fnName: string, error: Error | Dynamo_Error) {
895
+ return {
896
+ status: (error as Dynamo_Error)?.___status ?? 500,
897
+ message: (error as Error)?.message ?? `${fnName} was UNSUCCESFUL (NTS)`,
898
+ addECToUserMsg: true,
899
+ userMessage: this.defaultErrorUserMsg,
900
+ issuerService: `${this?.constructor?.name}-DynamoNTS_App`,
901
+ error: error,
902
+ }
903
+ }
791
904
 
792
905
  /**
793
- * #OUTDATED
794
- * Setting up App params, and preparing project global settings
795
- * You must setup app params in this function like this:
796
- *
797
- * @example
798
- * setupAppParams(): void {
799
- * this.params = new DynamoBEAppParams({
800
- * name: 'Sample Server',
801
- * title: 'A BIG nice header that will be logged on start',
802
- * version: version,
803
- * dbName: 'sampleapp',
804
- * });
805
- *
806
- * DBE_Global_S.setGlobalSettings({
807
- * defaultRouteSecurity: DynamoBERouteSecurity.secure,
808
- * logSetup: true,
809
- * });
810
- * }
906
+ * MISSING Description (TODO)
811
907
  */
812
908
  abstract getAppParams(): DynamoNTS_AppParams;
813
909
 
814
910
  /**
815
- * #OUTDATED
816
- * Setting up DBServices
817
- * You must setup globalServiceCollection and dbServices in this function
818
- *
819
- * @example
820
- * setGlobalServiceCollection(): void {
821
- * DBE_Global_S.setServices({
822
- * authService: AuthService.getInstance(),
823
- * emailServiceCollection: EmailServiceCollectionService.getInstance(),
824
- * dbModels: [
825
- * accountModelParams,
826
- * projectModelParams,
827
- * ...
828
- * ]
829
- * });
830
- * }
911
+ * MISSING Description (TODO)
831
912
  */
832
913
  abstract getGlobalServiceCollection(): DynamoNTS_GlobalServiceSettings;
833
914
 
@@ -842,39 +923,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
842
923
  overrideDynamoNTSGlobalSettings?(): void;
843
924
 
844
925
  /**
845
- * #OUTDATED
846
- * You must setup endpoints and required services in this function
847
- *
848
- * @example
849
- * // Setting up Routes
850
- * setupRoutingModules(): void {
851
- * this.httpPort = env.httpPort;
852
- * this.httpsPort = env.httpsPort;
853
- *
854
- * this.cert = {
855
- * keyPath: Path.join(__dirname, './_assets/cert/ucc.key'),
856
- * certPath: Path.join(__dirname, './_assets/cert/ucc.crt'),
857
- * };
858
- *
859
- * this.routingModules = [
860
- * new DynamoBERountingModule({
861
- * route: '/api/account',
862
- * controllers: [
863
- * AccountController.getInstance(),
864
- * PersonalInformationController.getInstance(),
865
- * ...
866
- * ]
867
- * }),
868
- * new DynamoBERountingModule({
869
- * route: '/api/project',
870
- * controllers: [
871
- * ProjectController.getInstance(),
872
- * ProjectExtensionController.getInstance(),
873
- * ]
874
- * }),
875
- * ...
876
- * ];
877
- * }
926
+ * MISSING Description (TODO)
878
927
  */
879
928
  getRoutingModules?(): DynamoNTS_RoutingModule[];
880
929
 
@@ -201,7 +201,10 @@ export abstract class DynamoNTS_SocketServerService<
201
201
  await this.subscriptionEvent.executeEventTasks(content, issuer);
202
202
 
203
203
  socket.emit(DynamoNTS_SocketEventKey.subscriptionSuccessful, 'subscribe was successful', error => {
204
- Dynamo_Log.error(`Emitting subscriptionSuccessful event failed!\nerror:`, error);
204
+ Dynamo_Log.error(
205
+ `Emitting subscriptionSuccessful event failed!` +
206
+ `\nerror:`, error
207
+ );
205
208
  });
206
209
 
207
210
  Dynamo_Log.success(`<-==> socket(${this.params.name}) subscription successfull (${issuer})`);
@@ -394,9 +397,9 @@ export abstract class DynamoNTS_SocketServerService<
394
397
  }
395
398
  }
396
399
 
397
- async emitError(presenceIssuerId: string, error: any): Promise<void> {
400
+ async emitError(presenceIssuerId: string, error: any, issuer: string): Promise<void> {
398
401
  try {
399
- await this.sendEventForId(presenceIssuerId, DynamoNTS_SocketEventKey.error, error);
402
+ await this.sendEventForId(presenceIssuerId, DynamoNTS_SocketEventKey.error, error, issuer);
400
403
  } catch (error) {
401
404
  throw new Dynamo_Error({
402
405
  ...this._getDefaultErrorSettings(
@@ -411,7 +414,7 @@ export abstract class DynamoNTS_SocketServerService<
411
414
  }
412
415
  }
413
416
 
414
- async sendEventForId(id: string, event: string, content: any/* , error?: (err: any) => void */): Promise<void> {
417
+ async sendEventForId(id: string, event: string, content: any, issuer: string): Promise<void> {
415
418
  try {
416
419
  const presence: DynamoNTS_SocketPresence = this.presences.find((pres: DynamoNTS_SocketPresence) => pres.issuerId === id);
417
420
 
@@ -428,7 +431,7 @@ export abstract class DynamoNTS_SocketServerService<
428
431
  });
429
432
  }
430
433
 
431
- presence.emitEvent(event, content);
434
+ presence.emitEvent(event, content, issuer);
432
435
 
433
436
  if (dynamoNTS_globalSettings.logSocketEventContent) {
434
437
  Dynamo_Log.success(` <--= emitted socket(${this.params.name}) event for presence: ${event}, presenceId: ${id}) \ncontent:`, content);
@@ -478,12 +481,12 @@ export abstract class DynamoNTS_SocketServerService<
478
481
  }
479
482
  }
480
483
 
481
- broadcastEvent(event: string, content: any): void {
484
+ broadcastEvent(event: string, content: any, issuer: string): void {
482
485
  try {
483
486
  Dynamo_Log.log(` <=-== broadcasting socket(${this.params.name}) event: ${event}`);
484
487
 
485
488
  this.presences.forEach((presence: DynamoNTS_SocketPresence) => {
486
- presence.emitEvent(event, content);
489
+ presence.emitEvent(event, content, issuer);
487
490
  });
488
491
  } catch (error) {
489
492
  Dynamo_Log.error(`socket(${this.params.name}) Event Broadcast (${event}) failed`, error);
@@ -1,5 +0,0 @@
1
- export interface DynamoNTS_PortSettings {
2
- httpPort?: number;
3
- httpsPort?: number;
4
- }
5
- //# sourceMappingURL=port-settings.interface.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"port-settings.interface.d.ts","sourceRoot":"","sources":["../../../src/_models/interfaces/port-settings.interface.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=port-settings.interface.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"port-settings.interface.js","sourceRoot":"","sources":["../../../src/_models/interfaces/port-settings.interface.ts"],"names":[],"mappings":""}
@@ -1,5 +0,0 @@
1
-
2
- export interface DynamoNTS_PortSettings {
3
- httpPort?: number,
4
- httpsPort?: number,
5
- }