@futdevpro/nts-dynamo 1.6.35 → 1.6.36

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.
@@ -1,5 +1,5 @@
1
1
 
2
- import { Dynamo_Log } from '@futdevpro/fsm-dynamo';
2
+ import { Dynamo_Array, Dynamo_Log } from '@futdevpro/fsm-dynamo';
3
3
  import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
4
4
  import { DynamoNTS_SocketEventType } from '../../_enums/http/socket-event-type.enum';
5
5
 
@@ -37,7 +37,7 @@ export class DynamoNTS_SocketEvent<T>{
37
37
  } else {
38
38
  this.logEvent = dynamoNTS_globalSettings.logAllSocketEvent;
39
39
  }
40
- this.logEventContent = set.logEventContent !== undefined ? set.logEventContent : dynamoNTS_globalSettings.logEventContent;
40
+ this.logEventContent = set.logEventContent !== undefined ? set.logEventContent : dynamoNTS_globalSettings.logSocketEventContent;
41
41
 
42
42
  if (this.logEvent) {
43
43
  this.preProcessess.unshift(this.getPreLog());
@@ -63,6 +63,7 @@ export class DynamoNTS_SocketEvent<T>{
63
63
  console.log(`\n==> incoming ${this.socketName} socket event: ${this.eventType}...`);
64
64
  }
65
65
  }
66
+
66
67
  return content;
67
68
  } catch (error) {
68
69
  console.error(`PreLog failed... (socket: ${this.socketName})`, error);
@@ -75,14 +76,20 @@ export class DynamoNTS_SocketEvent<T>{
75
76
  * @returns
76
77
  */
77
78
  async executeEventTasks?(content?: T, issuer?: string): Promise<void> {
78
- try {
79
- for (let i = 0; i < this.preProcessess.length; i++) {
79
+ try {
80
+ await Dynamo_Array.asyncForEach(this.preProcessess, async (preProcess: DynamoNTS_SocketEventPreprocessTask<any, any>) => {
81
+ content = await preProcess(content);
82
+ });
83
+ /* for (let i = 0; i < this.preProcessess.length; i++) {
80
84
  content = await this.preProcessess[i](content);
81
- }
85
+ } */
82
86
 
83
- for (let i = 0; i < this.tasks.length; i++) {
87
+ await Dynamo_Array.asyncForEach(this.tasks, async (task: DynamoNTS_SocketEventTask<T>) => {
88
+ await task(content, issuer);
89
+ });
90
+ /* for (let i = 0; i < this.tasks.length; i++) {
84
91
  await this.tasks[i](content, issuer);
85
- }
92
+ } */
86
93
  } catch (error) {
87
94
  console.error(`Socket Event tasks failed to execute on ${this.socketName}.... (${this.eventType})`, error, 'content:', content);
88
95
  }
@@ -53,5 +53,10 @@ export interface DynamoNTS_GlobalSettings {
53
53
  /**
54
54
  * this is an application wide default setting for socket debug logs
55
55
  */
56
- logEventContent?: boolean;
56
+ logSocketEventContent?: boolean;
57
+
58
+ /**
59
+ * this is an application wide default setting for api debug logs
60
+ */
61
+ logDetailedApiEvents?: boolean;
57
62
  }
@@ -5,6 +5,7 @@ import { Dynamo_Error, Dynamo_Log } from '@futdevpro/fsm-dynamo';
5
5
  import { DynamoNTS_HttpCallType } from '../../_enums/http/http-call-type.enum';
6
6
  import { DynamoNTS_HttpResponseType } from '../../_enums/http/http-response-type.enum';
7
7
  import { DynamoNTS_ApiCallParams } from '../../_models/control-models/api-call-params.control-model';
8
+ import { dynamoNTS_globalSettings } from '../../_constants';
8
9
 
9
10
  /**
10
11
  * This predefined Api service contains the basic API call function which can be used in various ways
@@ -111,7 +112,12 @@ export class DynamoNTS_ApiService {
111
112
  } else {
112
113
  a = res.data;
113
114
  }
114
- Dynamo_Log.success(`${callParams.name} was successful`, res.data);
115
+
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`);
120
+ }
115
121
  });
116
122
  break;
117
123
  case DynamoNTS_HttpCallType.delete:
@@ -122,7 +128,12 @@ export class DynamoNTS_ApiService {
122
128
  if (callParams.getFullResponse) {
123
129
  a = res;
124
130
  }
125
- Dynamo_Log.success(`${callParams.name} was successful`, res.data);
131
+
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`);
136
+ }
126
137
  });
127
138
  break;
128
139
  case DynamoNTS_HttpCallType.post:
@@ -140,7 +151,12 @@ export class DynamoNTS_ApiService {
140
151
  } else {
141
152
  a = res.data;
142
153
  }
143
- Dynamo_Log.success(`${callParams.name} api call was successful`, res.data);
154
+
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`);
159
+ }
144
160
  });
145
161
  break;
146
162
  default:
@@ -145,6 +145,8 @@ export abstract class DynamoNTS_SocketServerService<
145
145
  }
146
146
 
147
147
  this.subscriptionEvent.socketName = this.params.name;
148
+ } else {
149
+ Dynamo_Log.error('getPresenceFromSubscrioptionEventContent is not set', `${this.params.name} (${this.params.port})`);
148
150
  }
149
151
 
150
152
  this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
@@ -166,44 +168,79 @@ export abstract class DynamoNTS_SocketServerService<
166
168
  } */
167
169
  /* (security === DynamoNTS_SocketSecurity.open ? this.openSocketServer : this.secureSocketServer) */
168
170
  newSocketServer.on(DynamoNTS_SocketEventType.connection, async (socket: SocketIO.Socket) => {
169
- let issuer: string;
170
-
171
- for (let i = 0; i < this.connectEvent.preProcessess.length; i++) {
172
- await this.connectEvent.preProcessess[i](socket);
173
- }
174
-
175
- for (let i = 0; i < this.connectEvent.tasks.length; i++) {
176
- await this.connectEvent.tasks[i](socket);
177
- }
171
+ try {
172
+ let issuer: string;
173
+ if (dynamoNTS_globalSettings.logMainSocketEvent) {
174
+ console.log(`Socket (${this.params.name}): new incoming CONNECTION...`);
175
+ }
176
+
177
+ await Dynamo_Array.asyncForEach(this.connectEvent.preProcessess,
178
+ async (preProcess: (content: SocketIO.Socket) => Promise<void>) => {
179
+ await preProcess(socket);
180
+ }
181
+ );
182
+ /* for (let i = 0; i < this.connectEvent.preProcessess.length; i++) {
183
+ await this.connectEvent.preProcessess[i](socket);
184
+ } */
178
185
 
179
- if (this.getPresenceFromSubscrioptionEventContent) {
180
- socket.on(DynamoNTS_SocketEventType.subscribe, async (content: any) => {
181
- try {
182
- const presence: T_Presence = await this.getPresenceFromSubscrioptionEventContent(content, socket);
183
- issuer = presence.issuerId;
184
-
185
- this.socketSubscription(presence);
186
- await this.subscriptionEvent.executeEventTasks(content, issuer);
187
-
188
- console.log(`socket subscription successfull (${issuer})`);
189
- } catch (error) {
190
- Dynamo_Log.error(`Socket Subscription failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
191
- socket.emit(DynamoNTS_SocketEventType.error, error);
192
- socket.disconnect();
186
+ await Dynamo_Array.asyncForEach(this.connectEvent.tasks,
187
+ async (task: (content: SocketIO.Socket) => Promise<void>) => {
188
+ await task(socket);
193
189
  }
194
- })
195
- }
190
+ );
191
+ /* for (let i = 0; i < this.connectEvent.tasks.length; i++) {
192
+ await this.connectEvent.tasks[i](socket);
193
+ } */
194
+
195
+ if (this.getPresenceFromSubscrioptionEventContent) {
196
+ socket.on(DynamoNTS_SocketEventType.subscribe, async (content: any) => {
197
+ try {
198
+ if (dynamoNTS_globalSettings.logMainSocketEvent || dynamoNTS_globalSettings.logAllSocketEvent || dynamoNTS_globalSettings.logSocketEventContent) {
199
+ console.log(`---> incoming socket event: ${DynamoNTS_SocketEventType.subscribe} (${this.params.name}, presenceId: ${issuer})`, content);
200
+ } else {
201
+ console.log(`---> incoming socket event: ${DynamoNTS_SocketEventType.subscribe} (${this.params.name}, presenceId: ${issuer})`);
202
+ }
203
+
204
+ const presence: T_Presence = await this.getPresenceFromSubscrioptionEventContent(content, socket);
205
+ issuer = presence.issuerId;
206
+
207
+ this.socketSubscription(presence);
208
+ await this.subscriptionEvent.executeEventTasks(content, issuer);
209
+
210
+ Dynamo_Log.success(` <=> socket subscription successfull (${issuer})`);
211
+ } catch (error) {
212
+ Dynamo_Log.error(`Socket Subscription failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
213
+ socket.emit(DynamoNTS_SocketEventType.error, error);
214
+ socket.disconnect();
215
+ }
216
+ })
217
+ }
196
218
 
197
- this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
198
- socket.on(event.eventType, async (content: any) => {
199
- try {
200
- await event.executeEventTasks(content, issuer);
201
- } catch (error) {
202
- Dynamo_Log.error(`Socket Event failed: ${this.params.name} (${this.params.port})`, error);
203
- socket.emit(DynamoNTS_SocketEventType.error, error);
204
- }
219
+ this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
220
+ socket.on(event.eventType, async (content: any) => {
221
+ try {
222
+ if (dynamoNTS_globalSettings.logAllSocketEvent || dynamoNTS_globalSettings.logSocketEventContent) {
223
+ console.log(`---> incoming socket event: ${event.eventType} (${this.params.name}, presenceId: ${issuer})`, content);
224
+ } else {
225
+ console.log(`---> incoming socket event: ${event.eventType} (${this.params.name}, presenceId: ${issuer})`);
226
+ }
227
+
228
+ await event.executeEventTasks(content, issuer);
229
+ } catch (error) {
230
+ Dynamo_Log.error(`Socket Event failed: ${this.params.name} (${this.params.port})`, error);
231
+ socket.emit(DynamoNTS_SocketEventType.error, error);
232
+ }
233
+ });
205
234
  });
206
- });
235
+
236
+ if (dynamoNTS_globalSettings.logMainSocketEvent) {
237
+ console.log(`Socket (${this.params.name}): new CONNECTION established`);
238
+ }
239
+ } catch (error) {
240
+ Dynamo_Log.error(`Socket Connection failed: ${this.params.name} (${this.params.port}) will disconnect now...`, error);
241
+ socket.emit(DynamoNTS_SocketEventType.error, error);
242
+ socket.disconnect();
243
+ }
207
244
  });
208
245
 
209
246
  newSocketServer.listen(this.params.port);
@@ -283,6 +320,7 @@ export abstract class DynamoNTS_SocketServerService<
283
320
 
284
321
  emitEvent(event: string, content: any): void {
285
322
  try {
323
+ console.log(` <--- emitting socket event: ${event} (${this.params.name})`);
286
324
  this.openSocketServer.emit(event, content);
287
325
  } catch (error) {
288
326
  Dynamo_Log.error(`Socket Event Emit (${event}) failed: ${this.params?.name} (${this.params?.port})`, error);
@@ -312,6 +350,7 @@ export abstract class DynamoNTS_SocketServerService<
312
350
  try {
313
351
  const presence: DynamoNTS_SocketPresence = this.presences.find((pres: DynamoNTS_SocketPresence) => pres.issuerId === id);
314
352
  if (presence) {
353
+ console.log(` <--- emitting socket event for presence: ${event} (${this.params.name}, presenceId: ${id})`);
315
354
  presence.emitEvent(event, content);
316
355
  } else {
317
356
  if (error) {