@futdevpro/nts-dynamo 1.6.20 → 1.6.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/lib/_constants/mocks/app-extended-server.mock.d.ts +12 -0
  2. package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -1
  3. package/lib/_constants/mocks/app-extended-server.mock.js +71 -2
  4. package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -1
  5. package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
  6. package/lib/_constants/mocks/app-server.mock.js +3 -0
  7. package/lib/_constants/mocks/app-server.mock.js.map +1 -1
  8. package/lib/_constants/mocks/data-model.mock.d.ts +27 -0
  9. package/lib/_constants/mocks/data-model.mock.d.ts.map +1 -0
  10. package/lib/_constants/mocks/data-model.mock.js +57 -0
  11. package/lib/_constants/mocks/data-model.mock.js.map +1 -0
  12. package/lib/_constants/mocks/email-service-collection.mock.d.ts +7 -0
  13. package/lib/_constants/mocks/email-service-collection.mock.d.ts.map +1 -0
  14. package/lib/_constants/mocks/email-service-collection.mock.js +16 -0
  15. package/lib/_constants/mocks/email-service-collection.mock.js.map +1 -0
  16. package/lib/_constants/mocks/email-service.mock.d.ts +5 -0
  17. package/lib/_constants/mocks/email-service.mock.d.ts.map +1 -0
  18. package/lib/_constants/mocks/email-service.mock.js +21 -0
  19. package/lib/_constants/mocks/email-service.mock.js.map +1 -0
  20. package/lib/_constants/mocks/socket-client.mock.d.ts +9 -0
  21. package/lib/_constants/mocks/socket-client.mock.d.ts.map +1 -0
  22. package/lib/_constants/mocks/socket-client.mock.js +39 -0
  23. package/lib/_constants/mocks/socket-client.mock.js.map +1 -0
  24. package/lib/_services/core/email.service.d.ts.map +1 -1
  25. package/lib/_services/core/email.service.js +0 -1
  26. package/lib/_services/core/email.service.js.map +1 -1
  27. package/lib/_services/server/app-extended.server.d.ts.map +1 -1
  28. package/lib/_services/server/app-extended.server.js +16 -18
  29. package/lib/_services/server/app-extended.server.js.map +1 -1
  30. package/lib/_services/server/app-extended.server.spec.js +16 -0
  31. package/lib/_services/server/app-extended.server.spec.js.map +1 -1
  32. package/lib/_services/server/app.server.d.ts +1 -1
  33. package/lib/_services/server/app.server.d.ts.map +1 -1
  34. package/lib/_services/server/app.server.js +58 -60
  35. package/lib/_services/server/app.server.js.map +1 -1
  36. package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
  37. package/lib/_services/socket/socket-server.service.js.map +1 -1
  38. package/lib/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +1 -1
  40. package/src/_constants/mocks/app-extended-server.mock.ts +81 -3
  41. package/src/_constants/mocks/app-server.mock.ts +3 -0
  42. package/src/_constants/mocks/data-model.mock.ts +83 -0
  43. package/src/_constants/mocks/email-service-collection.mock.ts +12 -0
  44. package/src/_constants/mocks/email-service.mock.ts +19 -0
  45. package/src/_constants/mocks/email-template.mock.html +15 -0
  46. package/src/_constants/mocks/socket-client.mock.ts +42 -0
  47. package/src/_services/core/email.service.ts +0 -1
  48. package/src/_services/server/app-extended.server.spec.ts +22 -1
  49. package/src/_services/server/app-extended.server.ts +11 -14
  50. package/src/_services/server/app.server.ts +66 -57
  51. package/src/_services/socket/socket-server.service.ts +0 -1
@@ -221,13 +221,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
221
221
  protected deepLog: boolean;
222
222
  protected logFn: boolean;
223
223
 
224
- constructor(dontLog?: boolean){
224
+ constructor(extended?: boolean){
225
225
  super();
226
226
 
227
- this.asyncConstruct(dontLog);
227
+ this.asyncConstruct(extended);
228
228
  }
229
229
 
230
- private async asyncConstruct(dontLog?: boolean): Promise<void> {
230
+ private async asyncConstruct(extended?: boolean): Promise<void> {
231
231
  if (this.logFn && this.deepLog) console.log('\nfn:. asyncConstruct');
232
232
  try {
233
233
  this.systemControls.app.init = true;
@@ -267,9 +267,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
267
267
 
268
268
  await this.startDB();
269
269
 
270
- await this.getGlobalServiceCollection();
271
-
272
- await this.setSecurity();
270
+ this.setSecurity();
273
271
 
274
272
  if (this._routingModules?.length) {
275
273
  await this.initExpresses();
@@ -295,9 +293,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
295
293
  await this.postProcess();
296
294
  }
297
295
 
298
- await this.ready();
299
296
 
300
- if (!dontLog) {
297
+ if (!extended) {
298
+ await this.ready();
299
+
301
300
  Dynamo_Log.test(`${this._params.name} started successfully.`);
302
301
  }
303
302
  } catch (error) {
@@ -308,27 +307,18 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
308
307
 
309
308
  async ready(timeout: number = 4 * second): Promise<void> {
310
309
  if (this.logFn) console.log('\nfn:. ready');
311
- /* return new Promise<void>(async (resolve, reject) => { */
312
310
  let ready: boolean = false;
313
311
  const start: number = +new Date();
314
312
 
315
313
  if (this.constructErrors.length) {
316
- if (this.logFn && this.deepLog) console.log('\nfn:. ready: throw ERROR-0', this.constructErrors);
314
+ Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
317
315
  throw new Dynamo_Error({
318
316
  message: `${this._params.name} start failed. ERRORS`,
319
317
  additionalContent: this.constructErrors.length === 1 ? this.constructErrors[0] : { errors: this.constructErrors },
320
318
  });
321
319
  }
322
320
 
323
- if (this.logFn && this.deepLog) console.log('\nfn:. ready: bef while', this.systemControls);
324
321
  while (!ready && +new Date() - start < timeout) {
325
- // if (this.logFn && this.deepLog) console.log('\nfn:. ready: while', this.systemControls);
326
- /* if (this.logFn && this.deepLog) console.log('\nfn:. ready: while', this.systemControls,
327
- {
328
- mongoose: this.systemControls.mongoose.getReady(),
329
- httpServer: this.systemControls.httpServer.getReady(),
330
- httpsServer: this.systemControls.httpsServer.getReady(),
331
- }); */
332
322
  if (this.systemControls.app.init) {
333
323
  ready = (
334
324
  this.systemControls.mongoose.getReady() &&
@@ -341,13 +331,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
341
331
  }
342
332
 
343
333
  if (timeout < +new Date() - start) {
344
- //if (this.logFn && this.deepLog) console.log('\nfn:. ready: throw TIMEOUT', this.constructErrors, this.systemControls);
345
- if (this.logFn && this.deepLog) console.log('\nfn:. ready: throw TIMEOUT', this.constructErrors, this.systemControls,
346
- {
347
- mongoose: this.systemControls.mongoose.getReady(),
348
- httpServer: this.systemControls.httpServer.getReady(),
349
- httpsServer: this.systemControls.httpsServer.getReady(),
350
- });
334
+ Dynamo_Log.error(`${this._params.name} start failed. TIMEOUT`, this.constructErrors);
351
335
  throw new Dynamo_Error({
352
336
  message: `${this._params.name} start failed. TIMEOUT`,
353
337
  additionalContent: {
@@ -363,7 +347,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
363
347
  }
364
348
 
365
349
  if (this.constructErrors.length) {
366
- if (this.logFn && this.deepLog) console.log('\nfn:. ready: throw ERROR');
350
+ Dynamo_Log.error(`${this._params.name} start failed. ERROR`, this.constructErrors);
367
351
  throw new Dynamo_Error({
368
352
  message: `${this._params.name} start failed. ERROR`,
369
353
  additionalContent: this.constructErrors,
@@ -389,14 +373,23 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
389
373
  msg += `\nHTTPS Server start failed.`;
390
374
  }
391
375
 
392
- if (this.logFn && this.deepLog) console.log('\nfn:. ready: throw UNKNOWN');
376
+ Dynamo_Log.error(msg, this.constructErrors);
393
377
  throw new Dynamo_Error({
378
+ errorCode: 'NTS-AS0-110',
394
379
  message: msg,
395
- additionalContent: this.constructErrors,
380
+ additionalContent: {
381
+ constructErrors: this.constructErrors,
382
+ systemControls: this.systemControls,
383
+ systemReadies: {
384
+ app: this.systemControls.app.getReady(),
385
+ mongoose: this.systemControls.mongoose.getReady(),
386
+ httpServer: this.systemControls.httpServer.getReady(),
387
+ httpsServer: this.systemControls.httpsServer.getReady(),
388
+ },
389
+ },
396
390
  error: this.constructErrors?.[0] ?? new Error(),
397
391
  });
398
392
  }
399
- /* }); */
400
393
  }
401
394
 
402
395
  async stop(dontLog?: boolean): Promise<void> {
@@ -451,29 +444,37 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
451
444
  */
452
445
  private async startDB(): Promise<void> {
453
446
  if (this.logFn && this.deepLog) console.log('\nfn:. startDB');
454
- await new Promise<void>(async (resolve, reject) => {
455
- this.systemControls.mongoose.init = true;
456
- this.mongoose.connection
457
- .on('error', (error) => {
458
- this.systemControls.mongoose.started = false;
459
- this.constructErrors.push(error);
460
- Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
461
- reject(error);
462
- })
463
- .once('open', () => {
464
- this.systemControls.mongoose.started = true;
465
- Dynamo_Log.success('\nConnected to MongoDB\n');
466
- resolve();
467
- });
447
+ await new Promise<void>(
448
+ async (resolve, reject) => {
449
+ this.systemControls.mongoose.init = true;
450
+ this.mongoose.connection
451
+ .on('error', (error) => {
452
+ this.systemControls.mongoose.started = false;
453
+ this.constructErrors.push(error);
454
+ Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
455
+ reject(
456
+ new Dynamo_Error({
457
+ errorCode: 'NTS-AS0-100',
458
+ message: `Unable to connect to MongoDB server, ERROR: ${error}`,
459
+ error: error,
460
+ })
461
+ );
462
+ })
463
+ .once('open', () => {
464
+ this.systemControls.mongoose.started = true;
465
+ Dynamo_Log.success('\nConnected to MongoDB\n');
466
+ resolve();
467
+ });
468
468
 
469
- this.mongoose.connect(
470
- this._params.dbUri,
471
- {
472
- useNewUrlParser: true,
473
- useUnifiedTopology: true
474
- }
475
- );
476
- });
469
+ this.mongoose.connect(
470
+ this._params.dbUri,
471
+ {
472
+ useNewUrlParser: true,
473
+ useUnifiedTopology: true
474
+ }
475
+ );
476
+ }
477
+ );
477
478
  }
478
479
 
479
480
  /**
@@ -594,18 +595,20 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
594
595
  .on('error', (error) => {
595
596
  this.systemControls.httpsServer.started = false;
596
597
  this.constructErrors.push(error);
597
- /* Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error); */
598
+ Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
598
599
  reject(
599
600
  new Dynamo_Error({
601
+ errorCode: 'NTS-AS0-001',
600
602
  message: `HTTPS (secure) server ERROR`,
601
603
  error: error,
602
604
  })
603
605
  );
604
606
  })
605
607
  .on('uncaughtException', (ex) => {
606
- Dynamo_Log.warn(`\nHTTPS (secure) server uncaughtException`, ex);
607
- reject(
608
+ Dynamo_Log.warn(
609
+ `\nHTTPS (secure) server uncaughtException`,
608
610
  new Dynamo_Error({
611
+ errorCode: 'NTS-AS0-002',
609
612
  message: `HTTPS (secure) server uncaughtException`,
610
613
  error: ex,
611
614
  })
@@ -630,15 +633,17 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
630
633
  Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
631
634
  reject(
632
635
  new Dynamo_Error({
636
+ errorCode: 'NTS-AS0-003',
633
637
  message: `HTTP (open) server ERROR`,
634
638
  error: error,
635
639
  })
636
640
  );
637
641
  })
638
642
  .on('uncaughtException', (ex) => {
639
- Dynamo_Log.warn(`\nHTTP (open) server uncaughtException`, ex);
640
- reject(
643
+ Dynamo_Log.warn(
644
+ `\nHTTP (open) server uncaughtException`,
641
645
  new Dynamo_Error({
646
+ errorCode: 'NTS-AS0-004',
642
647
  message: `HTTP (open) server uncaughtException`,
643
648
  error: ex
644
649
  })
@@ -672,7 +677,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
672
677
  errorStack.splice(1, 4);
673
678
  error.stack = errorStack.join('\n');
674
679
 
680
+ Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
675
681
  throw new Dynamo_Error({
682
+ errorCode: 'NTS-AS0-005',
676
683
  message: `ROUTE DUPLICATION: ${module.route}`,
677
684
  error: error,
678
685
  });
@@ -704,7 +711,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
704
711
  errorStack.splice(1, 4);
705
712
  error.stack = errorStack.join('\n');
706
713
 
714
+ Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
707
715
  throw new Dynamo_Error({
716
+ errorCode: 'NTS-AS0-006',
708
717
  message: `ROUTE DUPLICATION: ${module.route}`,
709
718
  error: error,
710
719
  });
@@ -718,7 +727,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
718
727
  /**
719
728
  *
720
729
  */
721
- private async setSecurity(): Promise<void> {
730
+ private setSecurity(): void {
722
731
  if (this.logFn && this.deepLog) console.log('\nfn:. setSecurity');
723
732
  this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
724
733
  if (!module.security) {
@@ -303,7 +303,6 @@ export abstract class DynamoNTS_SocketServerService<
303
303
  presence.emitEvent(event, content);
304
304
  } else {
305
305
  if (error) {
306
-
307
306
  throw new Dynamo_Error({
308
307
  status: 404,
309
308
  errorCode: 'NTS-S99-001',