@futdevpro/nts-dynamo 1.6.54 → 1.6.58

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 (47) hide show
  1. package/lib/_constants/global-settings.const.d.ts.map +1 -1
  2. package/lib/_constants/global-settings.const.js +4 -1
  3. package/lib/_constants/global-settings.const.js.map +1 -1
  4. package/lib/_models/control-models/app-params.control-model.d.ts +12 -27
  5. package/lib/_models/control-models/app-params.control-model.d.ts.map +1 -1
  6. package/lib/_models/control-models/app-params.control-model.js +2 -1
  7. package/lib/_models/control-models/app-params.control-model.js.map +1 -1
  8. package/lib/_models/control-models/endpoint-params.control-model.d.ts +5 -0
  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 +38 -18
  11. package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
  12. package/lib/_models/control-models/socket-event.control-model.d.ts.map +1 -1
  13. package/lib/_models/control-models/socket-event.control-model.js +2 -1
  14. package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
  15. package/lib/_models/interfaces/global-settings.interface.d.ts +17 -1
  16. package/lib/_models/interfaces/global-settings.interface.d.ts.map +1 -1
  17. package/lib/_services/base/data.service.js.map +1 -1
  18. package/lib/_services/base/db.service.d.ts.map +1 -1
  19. package/lib/_services/base/db.service.js +16 -59
  20. package/lib/_services/base/db.service.js.map +1 -1
  21. package/lib/_services/core/api.service.d.ts.map +1 -1
  22. package/lib/_services/core/api.service.js +42 -20
  23. package/lib/_services/core/api.service.js.map +1 -1
  24. package/lib/_services/core/email.service.d.ts +2 -1
  25. package/lib/_services/core/email.service.d.ts.map +1 -1
  26. package/lib/_services/core/email.service.js +24 -31
  27. package/lib/_services/core/email.service.js.map +1 -1
  28. package/lib/_services/server/app.server.d.ts.map +1 -1
  29. package/lib/_services/server/app.server.js +10 -13
  30. package/lib/_services/server/app.server.js.map +1 -1
  31. package/lib/_services/socket/socket-server.service.d.ts +1 -1
  32. package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
  33. package/lib/_services/socket/socket-server.service.js +11 -8
  34. package/lib/_services/socket/socket-server.service.js.map +1 -1
  35. package/lib/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +2 -2
  37. package/src/_constants/global-settings.const.ts +4 -1
  38. package/src/_models/control-models/app-params.control-model.ts +13 -27
  39. package/src/_models/control-models/endpoint-params.control-model.ts +37 -8
  40. package/src/_models/control-models/socket-event.control-model.ts +4 -1
  41. package/src/_models/interfaces/global-settings.interface.ts +17 -1
  42. package/src/_services/base/data.service.ts +1 -1
  43. package/src/_services/base/db.service.ts +32 -67
  44. package/src/_services/core/api.service.ts +38 -14
  45. package/src/_services/core/email.service.ts +59 -31
  46. package/src/_services/server/app.server.ts +13 -10
  47. package/src/_services/socket/socket-server.service.ts +7 -4
@@ -18,5 +18,8 @@ export const dynamoNTS_globalSettings: DynamoNTS_GlobalSettings = {
18
18
  logMainSocketEvents: true,
19
19
  logSocketEventContent: false,
20
20
 
21
- logDetailedApiEvents: true,
21
+ logApiEvents: true,
22
+ logApiRequestContents: false,
23
+ logApiRequestSettings: false,
24
+ logApiResponseContents: false,
22
25
  };
@@ -10,50 +10,36 @@ export class DynamoNTS_AppParams {
10
10
  /**
11
11
  * title will be shown on the start of the application
12
12
  */
13
- title: string;
13
+ title?: string;
14
14
  /**
15
15
  * version of the application
16
+ * you should set the version,
17
+ * probably, you should set from the package.json as follows:
18
+ * import { version } from '../package.json';
16
19
  */
17
20
  version: string;
18
21
  /**
19
22
  * name of your MongoDB table
23
+ * by default, its: `mongodb://localhost:27017/${this.dbName}`
20
24
  */
21
- dbUri: string;
25
+ dbUri?: string;
22
26
  /**
23
- * mongoDB uri, by default, its: `mongodb://localhost:27017/${this.dbName}`
27
+ * name of your MongoDB table
24
28
  */
25
29
  dbName: string;
30
+ /**
31
+ * name of the system, by default, its: this.name.replace(' ', '-')
32
+ */
33
+ systemName?: string;
26
34
 
27
35
  constructor(
28
- set: {
29
- /**
30
- * name the application
31
- */
32
- name: string,
33
- /**
34
- * you can set a big f*in title to show on the start of the application
35
- */
36
- title?: string,
37
- /**
38
- * you should set the version,
39
- * probably, you should set from the package.json as follows:
40
- * import { version } from '../package.json';
41
- */
42
- version: string,
43
- /**
44
- * You need to name your MongoDB table
45
- */
46
- dbName: string,
47
- /**
48
- * you can change the mongoDB uri here. by default, its: `mongodb://localhost:27017/${this.dbName}`
49
- */
50
- dbUri?: string,
51
- }
36
+ set: DynamoNTS_AppParams
52
37
  ) {
53
38
  this.name = set.name;
54
39
  this.title = set.title ?? '';
55
40
  this.version = set.version;
56
41
  this.dbName = set.dbName;
57
42
  this.dbUri = set.dbUri ?? `mongodb://localhost:27017/${this.dbName}`;
43
+ this.systemName = set.systemName ?? this.name.replace(' ', '-');
58
44
  }
59
45
  }
@@ -26,6 +26,7 @@ export class DynamoNTS_EndpointParams{
26
26
  private tasks: ((req: Request, res: Response, issuer?: string) => Promise<void>)[];
27
27
 
28
28
  private logRequest: boolean;
29
+ private logRequestsParams: boolean;
29
30
  private logRequestsContent: boolean;
30
31
  private logResponseContent: boolean;
31
32
 
@@ -68,6 +69,10 @@ export class DynamoNTS_EndpointParams{
68
69
  * this flag will enable the debug logs on this endpoint
69
70
  */
70
71
  logRequest?: boolean,
72
+ /**
73
+ * this flag will enable the debug logs on this endpoint's requests
74
+ */
75
+ logRequestsParams?: boolean,
71
76
  /**
72
77
  * this flag will enable the debug logs on this endpoint's requests
73
78
  */
@@ -104,11 +109,15 @@ export class DynamoNTS_EndpointParams{
104
109
  this.tasks = set.tasks;
105
110
 
106
111
  this.logRequest = set.logRequest ?? dynamoNTS_globalSettings.logRequest;
112
+ this.logRequestsParams = set.logRequestsParams ?? dynamoNTS_globalSettings.logRequestsParams;
107
113
  this.logRequestsContent = set.logRequestsContent ?? dynamoNTS_globalSettings.logRequestsContent;
108
- /* this.logResponseContent = set.logResponseContent ?? dynamoNTS_globalSettings.logResponseContent; */
114
+ this.logResponseContent = set.logResponseContent ?? dynamoNTS_globalSettings.logResponseContent;
109
115
  } catch (error) {
110
116
  Dynamo_Log.error(
111
- `\nEndpoint params setup failed: name: '${set.name}' (security: ${set.security}) endpoint: ${set.endpoint}\nERROR:\n`, error);
117
+ `\nEndpoint params setup failed: name: '${set.name}' (security: ${set.security}) endpoint: ${set.endpoint}` +
118
+ `\nERROR:` +
119
+ `\n`, error
120
+ );
112
121
  throw error;
113
122
  }
114
123
  }
@@ -120,17 +129,37 @@ export class DynamoNTS_EndpointParams{
120
129
  private async preLog(req: Request, res: Response, issuer: string): Promise<void> {
121
130
  try {
122
131
  if (this.logRequest) {
123
- if (this.logRequestsContent) {
132
+ let msg: string = `===> incoming ${this.name} request... (issuer: ${issuer})`;
133
+
134
+ if (this.logRequestsParams) {
135
+ const params = this.getPathParamsLogContent(req);
136
+ msg += `\npathParams: ${params}`;
137
+ }
138
+
139
+ if (this.logRequestsContent && req.body && 0 < Object.keys(req.body).length) {
140
+ Dynamo_Log.info(msg + `\nbody:`, req.body);
141
+ } else {
142
+ Dynamo_Log.info(msg);
143
+ }
144
+
145
+ /* if (this.logRequestsContent) {
124
146
  const params = this.getPathParamsLogContent(req);
125
147
 
126
148
  if (req.body && 0 < Object.keys(req.body).length) {
127
- console.log(`===> incoming ${this.name} request... (issuer: ${issuer})\npathParams:${params}\nbody:`, req.body);
149
+ console.log(
150
+ `===> incoming ${this.name} request... (issuer: ${issuer})` +
151
+ `\npathParams: ${params}` +
152
+ `\nbody:`, req.body
153
+ );
128
154
  } else {
129
- console.log(`===> incoming ${this.name} request... (issuer: ${issuer})\npathParams:${params}`);
155
+ console.log(
156
+ `===> incoming ${this.name} request... (issuer: ${issuer})` +
157
+ `\npathParams: ${params}`
158
+ );
130
159
  }
131
160
  } else {
132
- console.log(`===> incoming ${this.name} request...`);
133
- }
161
+ console.log(`===> incoming ${this.name} request...`);
162
+ } */
134
163
  }
135
164
 
136
165
  } catch (error) {
@@ -192,7 +221,7 @@ export class DynamoNTS_EndpointParams{
192
221
 
193
222
  Dynamo_Log.error(msg);
194
223
  console.log(
195
- (error as Dynamo_Error)?.flag.includes('DYNAMO') ?
224
+ (error as Dynamo_Error)?.flag?.includes('DYNAMO') ?
196
225
  (error as Dynamo_Error).getErrorSimplified() :
197
226
  error,
198
227
  '\n'
@@ -96,7 +96,10 @@ export class DynamoNTS_SocketEvent<T>{
96
96
  private async getPreLog(content: T, issuer?: string): Promise<void> {
97
97
  try {
98
98
  if (this.logEventContent && this.eventKey !== DynamoNTS_SocketEventKey.connection) {
99
- Dynamo_Log.log(`---> incoming socket(${this.serviceName}) event: ${this.eventKey};\ncontent:`, content);
99
+ Dynamo_Log.log(
100
+ `---> incoming socket(${this.serviceName}) event: ${this.eventKey};
101
+ \ncontent:`, content
102
+ );
100
103
  } else {
101
104
  Dynamo_Log.log(`---> incoming socket(${this.serviceName}) event: ${this.eventKey}...`);
102
105
  }
@@ -33,6 +33,10 @@ export interface DynamoNTS_GlobalSettings {
33
33
  * this is an application wide default setting for route debug logs
34
34
  */
35
35
  logRequest?: boolean;
36
+ /**
37
+ * this is an application wide default setting for route debug logs
38
+ */
39
+ logRequestsParams?: boolean;
36
40
  /**
37
41
  * this is an application wide default setting for route debug logs
38
42
  */
@@ -58,5 +62,17 @@ export interface DynamoNTS_GlobalSettings {
58
62
  /**
59
63
  * this is an application wide default setting for api debug logs
60
64
  */
61
- logDetailedApiEvents?: boolean;
65
+ logApiEvents?: boolean;
66
+ /**
67
+ * this is an application wide default setting for api debug logs
68
+ */
69
+ logApiRequestContents?: boolean;
70
+ /**
71
+ * this is an application wide default setting for api debug logs
72
+ */
73
+ logApiRequestSettings?: boolean;
74
+ /**
75
+ * this is an application wide default setting for api debug logs
76
+ */
77
+ logApiResponseContents?: boolean;
62
78
  }
@@ -698,7 +698,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
698
698
  }
699
699
  }
700
700
 
701
- private _getDefaultErrorSettings(fnName: string, error?: Error | Dynamo_Error) {
701
+ private _getDefaultErrorSettings(fnName: string, error: Error | Dynamo_Error) {
702
702
  return {
703
703
  status: (error as Dynamo_Error)?.___status ?? 500,
704
704
  message: (error as Error)?.message ?? `${fnName} was UNSUCCESFUL (NTS; ${this.dataParams.dataName})`,
@@ -100,7 +100,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
100
100
  }
101
101
  });
102
102
 
103
- data = this.stringifyDataId(data, 'createData');
103
+ data = this.stringifyDataId(newData, 'createData');
104
104
 
105
105
  return data;
106
106
  }
@@ -141,14 +141,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
141
141
  });
142
142
  });
143
143
 
144
- if (typeof newData._id !== 'string' || typeof newData._id === 'object') {
145
- newData._id = `${newData._id}`;
146
- if (typeof data._id !== 'string' || typeof data._id === 'object') {
147
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.modifyData)')
148
- }
149
- }
150
- data._id = newData._id;
151
- data.__v = newData.__v;
144
+ data = this.stringifyDataId(newData, 'modifyData');
152
145
 
153
146
  return data;
154
147
  }
@@ -159,6 +152,15 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
159
152
  * @returns data
160
153
  */
161
154
  async getDataById(id: string): Promise<T> {
155
+ if (!id) {
156
+ throw new Dynamo_Error({
157
+ ...this._getDefaultErrorSettings('getDataById', new Error(`No ID provided! (NTS DB)`)),
158
+
159
+ errorCode: 'NTS-DBS-GI1',
160
+ message: `get ${this.dataParams.dbName} by ID was unsuccessful (NTS DB)`,
161
+ });
162
+ }
163
+
162
164
  let data: T = await this.dataModel.findById(id).then(res => {
163
165
  return res?.toObject() as T ?? null;
164
166
  }).catch(error => {
@@ -170,12 +172,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
170
172
  });
171
173
  });
172
174
 
173
- if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
174
- data._id = `${data._id}`;
175
- if (typeof data._id !== 'string' || typeof data._id === 'object') {
176
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getDataById)')
177
- }
178
- }
175
+ data = this.stringifyDataId(data, 'getDataById');
176
+
179
177
  return data;
180
178
  }
181
179
 
@@ -210,12 +208,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
210
208
  });
211
209
  });
212
210
 
213
- if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
214
- data._id = `${data._id}`;
215
- if (typeof data._id !== 'string' || typeof data._id === 'object') {
216
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getDataByDependencyId)')
217
- }
218
- }
211
+ data = this.stringifyDataId(data, 'getDataByDependencyId');
212
+
219
213
  return data;
220
214
  }
221
215
 
@@ -252,12 +246,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
252
246
 
253
247
  if (0 < dataList.length) {
254
248
  dataList.forEach((data: T) => {
255
- if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
256
- data._id = `${data._id}`;
257
- if (typeof data._id !== 'string' || typeof data._id === 'object') {
258
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getDataListByDependencyId)')
259
- }
260
- }
249
+ data = this.stringifyDataId(data, 'getDataListByDependencyId');
261
250
  });
262
251
  }
263
252
 
@@ -297,12 +286,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
297
286
 
298
287
  if (0 < dataList.length) {
299
288
  dataList.forEach((data: T) => {
300
- if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
301
- data._id = `${data._id}`;
302
- if (typeof data._id !== 'string' || typeof data._id === 'object') {
303
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getDataListByDependencyIds)')
304
- }
305
- }
289
+ data = this.stringifyDataId(data, 'getDataListByDependencyIds');
306
290
  });
307
291
  }
308
292
 
@@ -453,25 +437,21 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
453
437
  }
454
438
  });
455
439
 
456
- let dataList: T[] = await this.dataModel.find(filter)
457
- .then(res => res ?? [])
458
- .catch(error => {
459
- throw new Dynamo_Error({
460
- ...this._getDefaultErrorSettings('searchData', error),
461
-
462
- errorCode: 'NTS-DBS-SD1',
463
- message: `search ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
440
+ let dataList: T[] = await this.dataModel
441
+ .find(filter)
442
+ .then(res => res ?? [])
443
+ .catch(error => {
444
+ throw new Dynamo_Error({
445
+ ...this._getDefaultErrorSettings('searchData', error),
446
+
447
+ errorCode: 'NTS-DBS-SD1',
448
+ message: `search ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
449
+ });
464
450
  });
465
- });
466
451
 
467
452
  if (0 < dataList.length) {
468
453
  dataList.forEach((data: T) => {
469
- if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
470
- data._id = `${data._id}`;
471
- if (typeof data._id !== 'string' || typeof data._id === 'object') {
472
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.searchData)')
473
- }
474
- }
454
+ data = this.stringifyDataId(data, 'searchData');
475
455
  });
476
456
  }
477
457
 
@@ -568,12 +548,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
568
548
 
569
549
  if (0 < dataList.length) {
570
550
  dataList.forEach((data: T) => {
571
- if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
572
- data._id = `${data._id}`;
573
- if (typeof data._id !== 'string' || typeof data._id === 'object') {
574
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.find)')
575
- }
576
- }
551
+ data = this.stringifyDataId(data, 'find');
577
552
  });
578
553
  }
579
554
 
@@ -630,12 +605,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
630
605
 
631
606
  if (0 < dataList.length) {
632
607
  dataList.forEach((data: T) => {
633
- if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
634
- data._id = `${data._id}`;
635
- if (typeof data._id !== 'string' || typeof data._id === 'object') {
636
- Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findWithPaging)')
637
- }
638
- }
608
+ data = this.stringifyDataId(data, 'findWithPaging');
639
609
  });
640
610
  }
641
611
 
@@ -667,12 +637,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
667
637
  });
668
638
  });
669
639
 
670
- if (typeof newData._id !== 'string' || typeof newData._id === 'object') {
671
- newData._id = `${newData._id}`;
672
- if (typeof newData._id !== 'string' || typeof newData._id === 'object') {
673
- Dynamo_Log.error('newData._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findByIdAndUpdate)')
674
- }
675
- }
640
+ newData = this.stringifyDataId(newData, 'findByIdAndUpdate');
676
641
 
677
642
  return newData;
678
643
  }
@@ -816,7 +781,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
816
781
  // PRIVATE FUNCTIONS
817
782
 
818
783
  private stringifyDataId(data: T, fnName: string): T {
819
- if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
784
+ if (data?._id && (typeof data._id !== 'string' || typeof data._id === 'object')) {
820
785
  data._id = `${data._id}`;
821
786
 
822
787
  if (typeof data._id !== 'string' || typeof data._id === 'object') {
@@ -101,6 +101,21 @@ export class DynamoNTS_ApiService {
101
101
  callParams.httpOptions.params = httpParams;
102
102
  } */
103
103
 
104
+ if (dynamoNTS_globalSettings.logApiEvents) {
105
+ if (dynamoNTS_globalSettings.logApiRequestContents) {
106
+ Dynamo_Log.log(`< outgoing API call: ${url} \nbody:`, inputParams?.body);
107
+ } else {
108
+ Dynamo_Log.log(`< outgoing API call: ${url}`);
109
+ }
110
+ if (dynamoNTS_globalSettings.logApiRequestSettings) {
111
+ Dynamo_Log.log(`callParams:`, callParams);
112
+ Dynamo_Log.log('inputParams:', {
113
+ pathParams: inputParams.pathParams ?? {},
114
+ body: inputParams.body ?? null
115
+ });
116
+ }
117
+ }
118
+
104
119
  switch (callParams.type) {
105
120
  case DynamoNTS_HttpCallType.get:
106
121
  if (inputParams?.body) {
@@ -113,10 +128,12 @@ export class DynamoNTS_ApiService {
113
128
  a = res.data;
114
129
  }
115
130
 
116
- if (dynamoNTS_globalSettings.logDetailedApiEvents) {
117
- Dynamo_Log.success(`${callParams.name} was successful`, res.data);
118
- } else {
119
- Dynamo_Log.success(`${callParams.name} was successful`);
131
+ if (dynamoNTS_globalSettings.logApiEvents) {
132
+ if (dynamoNTS_globalSettings.logApiResponseContents) {
133
+ Dynamo_Log.success(`${callParams.name} was successful`, res.data);
134
+ } else {
135
+ Dynamo_Log.success(`${callParams.name} was successful`);
136
+ }
120
137
  }
121
138
  });
122
139
  break;
@@ -129,10 +146,12 @@ export class DynamoNTS_ApiService {
129
146
  a = res;
130
147
  }
131
148
 
132
- if (dynamoNTS_globalSettings.logDetailedApiEvents) {
133
- Dynamo_Log.success(`${callParams.name} was successful`, res.data);
134
- } else {
135
- Dynamo_Log.success(`${callParams.name} was successful`);
149
+ if (dynamoNTS_globalSettings.logApiEvents) {
150
+ if (dynamoNTS_globalSettings.logApiResponseContents) {
151
+ Dynamo_Log.success(`${callParams.name} was successful`, res.data);
152
+ } else {
153
+ Dynamo_Log.success(`${callParams.name} was successful`);
154
+ }
136
155
  }
137
156
  });
138
157
  break;
@@ -152,10 +171,12 @@ export class DynamoNTS_ApiService {
152
171
  a = res.data;
153
172
  }
154
173
 
155
- if (dynamoNTS_globalSettings.logDetailedApiEvents) {
156
- Dynamo_Log.success(`${callParams.name} api call was successful`, res.data);
157
- } else {
158
- Dynamo_Log.success(`${callParams.name} api call was successful`);
174
+ if (dynamoNTS_globalSettings.logApiEvents) {
175
+ if (dynamoNTS_globalSettings.logApiResponseContents) {
176
+ Dynamo_Log.success(`> ${callParams.name} api call was successful`, res.data);
177
+ } else {
178
+ Dynamo_Log.success(`> ${callParams.name} api call was successful`);
179
+ }
159
180
  }
160
181
  });
161
182
  break;
@@ -170,8 +191,11 @@ export class DynamoNTS_ApiService {
170
191
  return a as T;
171
192
  }
172
193
  } catch (error) {
173
- Dynamo_Log.error(`\nAPI ERROR: ${callParams?.name} failed...` +
174
- `\n${callParams?.baseUrl}${callParams?.endPoint}\ncallParams:`, callParams);
194
+ Dynamo_Log.error(
195
+ `\n> API ERROR: ${callParams?.name} failed...` +
196
+ `\n${callParams?.baseUrl}${callParams?.endPoint}` +
197
+ `\ncallParams:`, callParams
198
+ );
175
199
 
176
200
  if (callParams?.httpOptions?.responseType === DynamoNTS_HttpResponseType.text) {
177
201
  error.error = JSON.parse(error.error);
@@ -41,7 +41,7 @@ export class DynamoNTS_EmailService {
41
41
  }
42
42
  ) {
43
43
  try {
44
- /* this.serviceName = this.constructor?.name; */
44
+ this.serviceName = this.constructor?.name;
45
45
  // console.log('\n\n\n\n\nNEW CONSTRUCT STARTED', set.email);
46
46
  this.senderName = set.senderName;
47
47
  this.senderNEmail = `${set.senderName} <${set.email}>`;
@@ -77,16 +77,19 @@ export class DynamoNTS_EmailService {
77
77
  *
78
78
  * @param set
79
79
  */
80
- public async sendEmail(set: {
81
- to: string,
82
- subject: string,
83
- content?: string,
84
- useTemplate?: string,
85
- templateProperties?: {
86
- [propertyKey: string]: string
87
- },
88
- attachments?: Attachment[]
89
- }): Promise<void> {
80
+ public async sendEmail(
81
+ set: {
82
+ to: string,
83
+ subject: string,
84
+ content?: string,
85
+ useTemplate?: string,
86
+ templateProperties?: {
87
+ [propertyKey: string]: string
88
+ },
89
+ attachments?: Attachment[]
90
+ },
91
+ issuer?: string,
92
+ ): Promise<void> {
90
93
  try {
91
94
  let content: string;
92
95
 
@@ -95,21 +98,25 @@ export class DynamoNTS_EmailService {
95
98
  } else {
96
99
  if (!set.useTemplate) {
97
100
  throw new Dynamo_Error({
101
+ ...this._getDefaultErrorSettings(
102
+ 'sendEmail',
103
+ new Error(`No content setting passsed to emailSending!`),
104
+ issuer
105
+ ),
106
+
98
107
  errorCode: 'NTS-ES4-101',
99
- addECToUserMsg: true,
100
- message: 'No content setting passsed to emailSending!',
101
- userMessage: this.defaultErrorUserMsg,
102
- issuerService: this.serviceName,
103
108
  });
104
109
  }
105
110
 
106
111
  if (!this.templates[set.useTemplate]) {
107
112
  throw new Dynamo_Error({
113
+ ...this._getDefaultErrorSettings(
114
+ 'sendEmail',
115
+ new Error(`No email template found with this parameter! (${set.useTemplate})`),
116
+ issuer
117
+ ),
118
+
108
119
  errorCode: 'NTS-ES4-102',
109
- addECToUserMsg: true,
110
- message: `No email template found with this parameter! (${set.useTemplate})`,
111
- userMessage: this.defaultErrorUserMsg,
112
- issuerService: this.serviceName,
113
120
  });
114
121
  }
115
122
 
@@ -124,11 +131,13 @@ export class DynamoNTS_EmailService {
124
131
  Dynamo_Log.error('\nDynamoBEEmailService ERROR: INVALID sendEmail settings', set);
125
132
 
126
133
  throw new Dynamo_Error({
134
+ ...this._getDefaultErrorSettings(
135
+ 'sendEmail',
136
+ new Error(`TemplateProperties missing! properties needed: ${props}`),
137
+ issuer
138
+ ),
139
+
127
140
  errorCode: 'NTS-ES4-103',
128
- addECToUserMsg: true,
129
- message: `TemplateProperties missing! properties needed: ${props}`,
130
- userMessage: this.defaultErrorUserMsg,
131
- issuerService: this.serviceName,
132
141
  });
133
142
  }
134
143
  this.templatePropertyKeys[set.useTemplate].forEach((propertyKey: string) => {
@@ -159,14 +168,21 @@ export class DynamoNTS_EmailService {
159
168
  });
160
169
  });
161
170
  } catch (error) {
162
- throw new Dynamo_Error({
163
- errorCode: 'NTS-ES4-100',
164
- addECToUserMsg: true,
165
- message: `SendEmail failed!`,
166
- userMessage: this.defaultErrorUserMsg,
167
- issuerService: this.serviceName,
168
- error
169
- });
171
+ if (error.includes('all recipients were rejected')) {
172
+ throw new Dynamo_Error({
173
+ ...this._getDefaultErrorSettings('sendEmail', error, issuer),
174
+
175
+ errorCode: 'NTS-ES4-104',
176
+ userMessage: `Can't send mail to ${set.to}`,
177
+ })
178
+ } else {
179
+ throw new Dynamo_Error({
180
+ ...this._getDefaultErrorSettings('sendEmail', error, issuer),
181
+
182
+ errorCode: 'NTS-ES4-100',
183
+ message: `SendEmail failed!`,
184
+ });
185
+ }
170
186
  }
171
187
  }
172
188
 
@@ -240,4 +256,16 @@ export class DynamoNTS_EmailService {
240
256
  Dynamo_Log.error(`\nDynamoBEEmailService ERROR, getTemplatePropertyKeys ERROR`, new Error(), '\ntemplate:\n', template);
241
257
  }
242
258
  }
259
+
260
+ private _getDefaultErrorSettings(fnName: string, error: Error | Dynamo_Error, issuer: string) {
261
+ return {
262
+ status: (error as Dynamo_Error)?.___status ?? 500,
263
+ message: (error as Error)?.message ?? `${fnName} was UNSUCCESFUL (NTS; ${this.serviceName})`,
264
+ addECToUserMsg: true,
265
+ userMessage: this.defaultErrorUserMsg,
266
+ issuer: issuer,
267
+ issuerService: this.serviceName,
268
+ error: error,
269
+ }
270
+ }
243
271
  }
@@ -223,6 +223,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
223
223
 
224
224
  constructor(extended?: boolean){
225
225
  super();
226
+
227
+ process.on('unhandledRejection', (reason, p) => {
228
+ Dynamo_Log.highlightedError(
229
+ 'Unhandled Rejection at: ', p,
230
+ '\nRejection reason:', reason
231
+ );
232
+ });
226
233
 
227
234
  this.asyncConstruct(extended).catch((error: any) => {
228
235
  Dynamo_Log.error(`\nApplication: ${this._params.name} start failed.\n`, error);
@@ -234,11 +241,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
234
241
  try {
235
242
  this.systemControls.app.init = true;
236
243
  this._params = this.getAppParams();
237
- dynamo_error_default.issuerSystem = this._params.name;
244
+
245
+ dynamo_error_default.issuerSystem = this._params.systemName;
238
246
 
239
- if (this.overrideDynamoNTSGlobalSettings) {
240
- this.overrideDynamoNTSGlobalSettings();
241
- }
247
+ this.overrideDynamoNTSGlobalSettings?.();
248
+
242
249
  this.logSetup = dynamoNTS_globalSettings.logSetup;
243
250
 
244
251
  this.globalService = DynamoNTS_GlobalService.getInstance();
@@ -258,9 +265,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
258
265
  this._routingModules = this.getRoutingModules();
259
266
  }
260
267
 
261
- if (this.createEntries) {
262
- await this.createEntries();
263
- }
268
+ await this.createEntries?.();
264
269
 
265
270
  console.log(`\n\n\nStarting ${this._params.name}... `);
266
271
 
@@ -288,9 +293,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
288
293
  this._rootServices = await this.getRootServices();
289
294
  }
290
295
 
291
- if (this.postProcess) {
292
- await this.postProcess();
293
- }
296
+ await this.postProcess?.();
294
297
 
295
298
 
296
299
  if (!extended) {