@futdevpro/nts-dynamo 1.6.52 → 1.6.53
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.
- package/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +5 -19
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.js +20 -13
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_services/socket/socket-client.service.d.ts +1 -1
- package/lib/_services/socket/socket-client.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-client.service.js +20 -25
- package/lib/_services/socket/socket-client.service.js.map +1 -1
- package/lib/_services/socket/socket-server.service.d.ts +0 -1
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +19 -12
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/_models/control-models/endpoint-params.control-model.ts +6 -21
- package/src/_models/control-models/socket-presence.control-model.ts +17 -13
- package/src/_services/socket/socket-client.service.ts +19 -20
- package/src/_services/socket/socket-server.service.ts +3 -2
|
@@ -117,23 +117,16 @@ export class DynamoNTS_EndpointParams{
|
|
|
117
117
|
*
|
|
118
118
|
* @returns
|
|
119
119
|
*/
|
|
120
|
-
private async preLog(req: Request, res: Response): Promise<void> {
|
|
120
|
+
private async preLog(req: Request, res: Response, issuer: string): Promise<void> {
|
|
121
121
|
try {
|
|
122
122
|
if (this.logRequest) {
|
|
123
123
|
if (this.logRequestsContent) {
|
|
124
124
|
const params = this.getPathParamsLogContent(req);
|
|
125
|
-
/* let params = '';
|
|
126
|
-
for(let i = 0; i < this.pathParams.length; i++) {
|
|
127
|
-
params += `\n ${this.pathParams[i]}: ${req.params[this.pathParams[i]]}`;
|
|
128
|
-
if (i + 1 < this.pathParams.length) {
|
|
129
|
-
params += ',';
|
|
130
|
-
}
|
|
131
|
-
} */
|
|
132
125
|
|
|
133
126
|
if (req.body && 0 < Object.keys(req.body).length) {
|
|
134
|
-
console.log(`===> incoming ${this.name} request
|
|
127
|
+
console.log(`===> incoming ${this.name} request... (issuer: ${issuer})\npathParams:${params}\nbody:`, req.body);
|
|
135
128
|
} else {
|
|
136
|
-
console.log(`===> incoming ${this.name} request
|
|
129
|
+
console.log(`===> incoming ${this.name} request... (issuer: ${issuer})\npathParams:${params}`);
|
|
137
130
|
}
|
|
138
131
|
} else {
|
|
139
132
|
console.log(`===> incoming ${this.name} request...`);
|
|
@@ -152,8 +145,10 @@ export class DynamoNTS_EndpointParams{
|
|
|
152
145
|
getFullExecution(): (req: Request, res: Response) => Promise<void> {
|
|
153
146
|
return async (req: Request, res: Response) => {
|
|
154
147
|
try {
|
|
148
|
+
const issuer: string = DynamoNTS_GlobalService?.getAuthService()?.getIssuerFromRequest(req);
|
|
149
|
+
|
|
155
150
|
if (this.logRequest) {
|
|
156
|
-
await this.preLog(req, res);
|
|
151
|
+
await this.preLog(req, res, issuer);
|
|
157
152
|
}
|
|
158
153
|
|
|
159
154
|
await Dynamo_Array.asyncForEach(this.preProcessess,
|
|
@@ -161,8 +156,6 @@ export class DynamoNTS_EndpointParams{
|
|
|
161
156
|
await preProcess(req, res);
|
|
162
157
|
}
|
|
163
158
|
);
|
|
164
|
-
|
|
165
|
-
const issuer: string = DynamoNTS_GlobalService?.getAuthService()?.getIssuerFromRequest(req);
|
|
166
159
|
|
|
167
160
|
await Dynamo_Array.asyncForEach(this.tasks,
|
|
168
161
|
async (task: (req: Request, res: Response, issuer?: string) => Promise<void>) => {
|
|
@@ -192,9 +185,6 @@ export class DynamoNTS_EndpointParams{
|
|
|
192
185
|
private error(req: Request, res: Response, error: Error | Dynamo_Error): void {
|
|
193
186
|
try {
|
|
194
187
|
let msg: string = `Endpoint catched an error. ${this.name} (${this.endpoint})`;
|
|
195
|
-
/* this.pathParams.forEach((param: string) => {
|
|
196
|
-
msg += `\n${param}: ${req.params[param]}`;
|
|
197
|
-
}); */
|
|
198
188
|
msg += this.getPathParamsLogContent(req);
|
|
199
189
|
msg += `\nERROR:`;
|
|
200
190
|
|
|
@@ -206,11 +196,6 @@ export class DynamoNTS_EndpointParams{
|
|
|
206
196
|
'\n'
|
|
207
197
|
);
|
|
208
198
|
|
|
209
|
-
/* if (this.logRequest && req.body && 0 < Object.keys(req.body).length) {
|
|
210
|
-
console.log('body: ');
|
|
211
|
-
console.log(req.body, '\n');
|
|
212
|
-
} */
|
|
213
|
-
|
|
214
199
|
res.status((error as Dynamo_Error)?.___status ?? 501);
|
|
215
200
|
res.send(error);
|
|
216
201
|
|
|
@@ -47,27 +47,26 @@ export class DynamoNTS_SocketPresence {
|
|
|
47
47
|
* @param content
|
|
48
48
|
*/
|
|
49
49
|
emitEvent?(event: string, content: any) {
|
|
50
|
-
let anyFailed: boolean = false;
|
|
50
|
+
/* let anyFailed: boolean = false; */
|
|
51
51
|
const errors = [];
|
|
52
52
|
const inactiveSockets: SocketIO.Socket[] = [];
|
|
53
53
|
|
|
54
54
|
this.sockets.forEach((socket: SocketIO.Socket, index: number) => {
|
|
55
55
|
if (!socket.connected) {
|
|
56
|
-
Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed
|
|
57
|
-
anyFailed = true;
|
|
56
|
+
Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!\nERROR: socket[${socket.id}] is not connected! (it will be removed...)`);
|
|
58
57
|
|
|
59
|
-
errors.push(
|
|
58
|
+
/* errors.push(
|
|
60
59
|
new Dynamo_Error({
|
|
61
60
|
status: 500,
|
|
62
61
|
errorCode: 'NTS-SPC-EE1',
|
|
63
62
|
addECToUserMsg: true,
|
|
64
|
-
message: `Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed
|
|
63
|
+
message: `Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!\nERROR: socket[${socket.id}] is not connected!`,
|
|
65
64
|
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.',
|
|
66
65
|
})
|
|
67
|
-
);
|
|
66
|
+
); */
|
|
68
67
|
|
|
69
68
|
inactiveSockets.push(socket);
|
|
70
|
-
socket
|
|
69
|
+
socket?.disconnect(true);
|
|
71
70
|
}
|
|
72
71
|
});
|
|
73
72
|
|
|
@@ -75,30 +74,35 @@ export class DynamoNTS_SocketPresence {
|
|
|
75
74
|
|
|
76
75
|
this.sockets.forEach((socket: SocketIO.Socket, index: number) => {
|
|
77
76
|
const success: boolean = socket.emit(event, content, error => {
|
|
78
|
-
Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!
|
|
77
|
+
Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!(0)\nerror:`, error);
|
|
79
78
|
errors.push(error);
|
|
80
|
-
anyFailed = true;
|
|
81
79
|
});
|
|
82
80
|
|
|
83
81
|
if (!success) {
|
|
84
|
-
Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!
|
|
85
|
-
anyFailed = true;
|
|
82
|
+
Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!(1)`);
|
|
86
83
|
}
|
|
87
84
|
});
|
|
88
85
|
|
|
89
|
-
if (
|
|
86
|
+
if (0 < errors.length) {
|
|
90
87
|
throw new Dynamo_Error({
|
|
91
88
|
status: 500,
|
|
92
89
|
errorCode: 'NTS-SPC-EE2',
|
|
93
90
|
addECToUserMsg: true,
|
|
94
91
|
message: `Emitting event '${event}' on socket(s)(${this.serviceName}) failed!`,
|
|
95
92
|
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.',
|
|
96
|
-
/* errors: errors, */
|
|
97
93
|
additionalContent: {
|
|
98
94
|
inactiveSockets: inactiveSockets,
|
|
99
95
|
errors: errors,
|
|
100
96
|
}
|
|
101
97
|
});
|
|
98
|
+
} else if (this.sockets.length === 0) {
|
|
99
|
+
throw new Dynamo_Error({
|
|
100
|
+
status: 404,
|
|
101
|
+
errorCode: 'NTS-SPC-EE3',
|
|
102
|
+
addECToUserMsg: true,
|
|
103
|
+
message: `Emitting event '${event}' on socket(s)(${this.serviceName}) failed! No more sockets left connected!`,
|
|
104
|
+
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.',
|
|
105
|
+
});
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
|
|
@@ -24,7 +24,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
24
24
|
protected _connected: boolean = false;
|
|
25
25
|
get connected(): boolean { return this._connected; }
|
|
26
26
|
|
|
27
|
-
protected
|
|
27
|
+
protected debugLog: boolean = dynamoNTS_globalSettings.logSetup;
|
|
28
28
|
protected logFn: boolean;
|
|
29
29
|
|
|
30
30
|
private defaultEvents: DynamoNTS_SocketEvent<any>[] = [
|
|
@@ -33,7 +33,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
33
33
|
tasks: [
|
|
34
34
|
async () => {
|
|
35
35
|
this._connected = true;
|
|
36
|
-
Dynamo_Log.success(
|
|
36
|
+
Dynamo_Log.success(`< > socket-client(${this.params.name}) connected!`);
|
|
37
37
|
}
|
|
38
38
|
]
|
|
39
39
|
}),
|
|
@@ -43,7 +43,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
43
43
|
tasks: [
|
|
44
44
|
async () => {
|
|
45
45
|
this._connected = false;
|
|
46
|
-
Dynamo_Log.warn(
|
|
46
|
+
Dynamo_Log.warn(`< x > socket-client(${this.params.name}) disconnected!`);
|
|
47
47
|
|
|
48
48
|
if (this._params.reconnect) {
|
|
49
49
|
await delay(this._params.reconnectDelay);
|
|
@@ -57,7 +57,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
57
57
|
eventKey: DynamoNTS_SocketEventKey.subscriptionSuccessful,
|
|
58
58
|
tasks: [
|
|
59
59
|
async () => {
|
|
60
|
-
Dynamo_Log.success(
|
|
60
|
+
Dynamo_Log.success(`<-=-> socket-client(${this.params.name}) subscription successful!`);
|
|
61
61
|
}
|
|
62
62
|
]
|
|
63
63
|
}),
|
|
@@ -66,7 +66,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
66
66
|
eventKey: DynamoNTS_SocketEventKey.error,
|
|
67
67
|
tasks: [
|
|
68
68
|
async (content: any) => {
|
|
69
|
-
Dynamo_Log.error(
|
|
69
|
+
Dynamo_Log.error(`---> socket-client(${this.params.name}) ERROR!:`, content);
|
|
70
70
|
}
|
|
71
71
|
]
|
|
72
72
|
}),
|
|
@@ -76,7 +76,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
76
76
|
super();
|
|
77
77
|
|
|
78
78
|
this.asyncConstructor().catch((error: any) => {
|
|
79
|
-
Dynamo_Log.error(
|
|
79
|
+
Dynamo_Log.error(`socket-client(${this.params?.name}) Service setup failed! ERROR:`, error);
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
|
|
@@ -90,11 +90,11 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
90
90
|
|
|
91
91
|
await this.setupSocketEvents();
|
|
92
92
|
|
|
93
|
-
Dynamo_Log.
|
|
93
|
+
Dynamo_Log.success(`\nsocket-client(${this.params?.name}) Service setup finished`);
|
|
94
94
|
|
|
95
95
|
await this.connectSocket();
|
|
96
96
|
} catch (error) {
|
|
97
|
-
Dynamo_Log.error(
|
|
97
|
+
Dynamo_Log.error(`socket-client(${this.params?.name}) Service setup failed!`, error);
|
|
98
98
|
throw new Dynamo_Error({
|
|
99
99
|
errorCode: 'NTS-SCS-001',
|
|
100
100
|
error: error,
|
|
@@ -107,6 +107,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
107
107
|
if (this.logFn) console.log('\nFn:. setupDefaultEvents');
|
|
108
108
|
|
|
109
109
|
this.defaultEvents.forEach((defaultEvent: DynamoNTS_SocketEvent<any>) => {
|
|
110
|
+
defaultEvent.serviceName = this.params.name;
|
|
110
111
|
const eventDeclared = this.incomingEvents.find((event: DynamoNTS_SocketEvent<any>) => event.eventKey === defaultEvent.eventKey);
|
|
111
112
|
if (!eventDeclared) {
|
|
112
113
|
this.incomingEvents.push(defaultEvent);
|
|
@@ -115,37 +116,35 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
115
116
|
}
|
|
116
117
|
});
|
|
117
118
|
} catch (error) {
|
|
118
|
-
Dynamo_Log.error(`
|
|
119
|
+
Dynamo_Log.error(`socket-client(${this.params.name}) Service Setup Default Events failed, ERROR:`, error);
|
|
119
120
|
throw error;
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
private async setupSocketEvents(): Promise<void> {
|
|
124
125
|
try {
|
|
125
|
-
if (this.
|
|
126
|
+
if (this.debugLog) console.log(`Setup socket-client(${this.params.name}) Events...`);
|
|
126
127
|
|
|
127
128
|
await Dynamo_Array.asyncForEach(this.incomingEvents, async (event: DynamoNTS_SocketEvent<any>) => {
|
|
128
|
-
|
|
129
|
-
event.socketName = this.name;
|
|
130
|
-
}
|
|
129
|
+
event.serviceName = this.params.name;
|
|
131
130
|
this.socket.on(event.eventKey, async (content: any) => {
|
|
132
131
|
try {
|
|
133
132
|
await event.executeEventTasks(content, this.params.service);
|
|
134
133
|
} catch (error) {
|
|
135
|
-
Dynamo_Log.error(`
|
|
134
|
+
Dynamo_Log.error(`socket-client(${this.params.name}) Event failed, ERROR:`, error);
|
|
136
135
|
await this.emitEvent(DynamoNTS_SocketEventKey.error, error);
|
|
137
136
|
}
|
|
138
137
|
});
|
|
139
138
|
});
|
|
140
139
|
} catch (error) {
|
|
141
|
-
Dynamo_Log.error(`
|
|
140
|
+
Dynamo_Log.error(`socket-client(${this.params.name}) Service Setup Socket Events failed, ERROR:`, error);
|
|
142
141
|
throw error;
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
|
|
146
145
|
private async connectSocket(): Promise<void> {
|
|
147
146
|
try {
|
|
148
|
-
Dynamo_Log.
|
|
147
|
+
Dynamo_Log.info(`< .. > socket-client(${this.params.name}) connecting to ${this.params.address}:${this.params.port} ...`);
|
|
149
148
|
|
|
150
149
|
this.socket.connect();
|
|
151
150
|
|
|
@@ -153,7 +152,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
153
152
|
await this.tryReconnectIfNeeded();
|
|
154
153
|
}
|
|
155
154
|
} catch (error) {
|
|
156
|
-
Dynamo_Log.error(`
|
|
155
|
+
Dynamo_Log.error(`socket-client(${this.params.name}) Service Connect Socket failed, ERROR:`, error);
|
|
157
156
|
throw error;
|
|
158
157
|
}
|
|
159
158
|
}
|
|
@@ -167,7 +166,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
167
166
|
await this.connectSocket();
|
|
168
167
|
}
|
|
169
168
|
} catch (error) {
|
|
170
|
-
Dynamo_Log.error(`
|
|
169
|
+
Dynamo_Log.error(`socket-client(${this.params.name}) Service Try Reconnect failed, ERROR:`, error);
|
|
171
170
|
throw error;
|
|
172
171
|
}
|
|
173
172
|
}
|
|
@@ -179,10 +178,10 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
|
|
|
179
178
|
*/
|
|
180
179
|
protected async emitEvent(eventType: string, content: any): Promise<void> {
|
|
181
180
|
try {
|
|
182
|
-
Dynamo_Log.log(`<-=- outgoing ${this.name}
|
|
181
|
+
Dynamo_Log.log(`<-=- outgoing socket-client(${this.params.name}) event: ${eventType}`);
|
|
183
182
|
this.socket.emit(eventType, content);
|
|
184
183
|
} catch (error) {
|
|
185
|
-
Dynamo_Log.error(`
|
|
184
|
+
Dynamo_Log.error(`socket-client(${this.params.name}) Service Emit Event failed: ${this.params?.name} (${this.params?.port})`, error);
|
|
186
185
|
throw error;
|
|
187
186
|
}
|
|
188
187
|
}
|
|
@@ -355,9 +355,10 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
emitServerEvent(event: string, content: any): void {
|
|
358
|
+
/* emitServerEvent(event: string, content: any): void {
|
|
359
359
|
try {
|
|
360
360
|
Dynamo_Log.log(` <=-- emitting server socket(${this.params.name}) event: ${event}`);
|
|
361
|
+
|
|
361
362
|
this.openSocketServer.emit(event, content, error => {
|
|
362
363
|
Dynamo_Log.error(`Emitting server event '${event}' failed!\nerror:`, error);
|
|
363
364
|
});
|
|
@@ -372,7 +373,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
372
373
|
message: `socket(${this.params.name}) Event Emit (${event}) failed: ${this.params?.name}`,
|
|
373
374
|
});
|
|
374
375
|
}
|
|
375
|
-
}
|
|
376
|
+
} */
|
|
376
377
|
|
|
377
378
|
idIsSubscribed(id: string): boolean {
|
|
378
379
|
try {
|