@futdevpro/nts-dynamo 1.6.55 → 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 (36) 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 +32 -12
  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/core/api.service.d.ts.map +1 -1
  18. package/lib/_services/core/api.service.js +42 -20
  19. package/lib/_services/core/api.service.js.map +1 -1
  20. package/lib/_services/server/app.server.d.ts.map +1 -1
  21. package/lib/_services/server/app.server.js +10 -13
  22. package/lib/_services/server/app.server.js.map +1 -1
  23. package/lib/_services/socket/socket-server.service.d.ts +1 -1
  24. package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
  25. package/lib/_services/socket/socket-server.service.js +11 -8
  26. package/lib/_services/socket/socket-server.service.js.map +1 -1
  27. package/lib/tsconfig.tsbuildinfo +1 -1
  28. package/package.json +2 -2
  29. package/src/_constants/global-settings.const.ts +4 -1
  30. package/src/_models/control-models/app-params.control-model.ts +13 -27
  31. package/src/_models/control-models/endpoint-params.control-model.ts +36 -7
  32. package/src/_models/control-models/socket-event.control-model.ts +4 -1
  33. package/src/_models/interfaces/global-settings.interface.ts +17 -1
  34. package/src/_services/core/api.service.ts +38 -14
  35. package/src/_services/server/app.server.ts +13 -10
  36. 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) {
@@ -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
  }
@@ -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);
@@ -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) {
@@ -184,8 +184,11 @@ export abstract class DynamoNTS_SocketServerService<
184
184
  * but subscribe event is an exception from this,
185
185
  * to be able to check content before getPresenceFromSubscrioptionEventContent
186
186
  */
187
- if (dynamoNTS_globalSettings.logMainSocketEvents || dynamoNTS_globalSettings.logAllSocketEvent || dynamoNTS_globalSettings.logSocketEventContent) {
188
- Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${DynamoNTS_SocketEventKey.subscribe};\ncontent:`, content);
187
+ if (dynamoNTS_globalSettings.logSocketEventContent) {
188
+ Dynamo_Log.log(
189
+ `---> incoming socket(${this.params.name}) event: ${DynamoNTS_SocketEventKey.subscribe};` +
190
+ `\ncontent:`, content
191
+ );
189
192
  } else {
190
193
  Dynamo_Log.log(`---> incoming socket(${this.params.name}) event: ${DynamoNTS_SocketEventKey.subscribe}`);
191
194
  }
@@ -391,9 +394,9 @@ export abstract class DynamoNTS_SocketServerService<
391
394
  }
392
395
  }
393
396
 
394
- emitError(presenceIssuerId: string, error: any): void {
397
+ async emitError(presenceIssuerId: string, error: any): Promise<void> {
395
398
  try {
396
- this.sendEventForId(presenceIssuerId, DynamoNTS_SocketEventKey.error, error);
399
+ await this.sendEventForId(presenceIssuerId, DynamoNTS_SocketEventKey.error, error);
397
400
  } catch (error) {
398
401
  throw new Dynamo_Error({
399
402
  ...this._getDefaultErrorSettings(