@futdevpro/nts-dynamo 1.7.1 → 1.7.4
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/.copilot/patterns.json +8 -0
- package/lib/_constants/mocks/socket-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.js +4 -1
- package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +3 -22
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.d.ts +5 -3
- package/lib/_models/control-models/socket-presence.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.js +34 -20
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_models/interfaces/global-service-settings.interface.d.ts +11 -0
- package/lib/_models/interfaces/global-service-settings.interface.d.ts.map +1 -1
- package/lib/_models/interfaces/port-settings.interface.d.ts +7 -1
- package/lib/_models/interfaces/port-settings.interface.d.ts.map +1 -1
- package/lib/_models/interfaces/port-settings.interface.js +23 -0
- package/lib/_models/interfaces/port-settings.interface.js.map +1 -1
- package/lib/_modules/usage/usage.controller.d.ts.map +1 -1
- package/lib/_modules/usage/usage.controller.js +0 -1
- package/lib/_modules/usage/usage.controller.js.map +1 -1
- package/lib/_services/base/data.service.d.ts +1 -1
- package/lib/_services/base/data.service.d.ts.map +1 -1
- package/lib/_services/base/data.service.js +5 -4
- package/lib/_services/base/data.service.js.map +1 -1
- package/lib/_services/core/api.service.d.ts +1 -0
- package/lib/_services/core/api.service.d.ts.map +1 -1
- package/lib/_services/core/api.service.js +19 -21
- package/lib/_services/core/api.service.js.map +1 -1
- package/lib/_services/core/email.service.js +1 -1
- package/lib/_services/core/email.service.js.map +1 -1
- package/lib/_services/core/global.service.d.ts +1 -3
- package/lib/_services/core/global.service.d.ts.map +1 -1
- package/lib/_services/core/global.service.js +2 -7
- package/lib/_services/core/global.service.js.map +1 -1
- package/lib/_services/server/app-extended.server.d.ts +2 -2
- package/lib/_services/server/app-extended.server.d.ts.map +1 -1
- package/lib/_services/server/app-extended.server.js +12 -10
- package/lib/_services/server/app-extended.server.js.map +1 -1
- package/lib/_services/server/app.server.d.ts +4 -40
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +61 -35
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/socket/socket-client.service.js +4 -4
- package/lib/_services/socket/socket-server.service.d.ts +3 -3
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +15 -14
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/nodemon.json +1 -1
- package/package.json +13 -13
- package/src/_constants/mocks/socket-server.mock.ts +4 -1
- package/src/_models/control-models/endpoint-params.control-model.ts +8 -24
- package/src/_models/control-models/socket-presence.control-model.ts +70 -21
- package/src/_models/interfaces/global-service-settings.interface.ts +11 -0
- package/src/_models/interfaces/port-settings.interface.ts +25 -3
- package/src/_modules/usage/usage.controller.ts +0 -1
- package/src/_services/base/data.service.ts +8 -5
- package/src/_services/core/api.service.ts +36 -21
- package/src/_services/core/email.service.ts +1 -1
- package/src/_services/core/global.service.ts +3 -9
- package/src/_services/server/app-extended.server.ts +18 -10
- package/src/_services/server/app.server.ts +127 -80
- package/src/_services/socket/socket-client.service.ts +4 -4
- package/src/_services/socket/socket-server.service.ts +17 -14
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@futdevpro/nts-dynamo",
|
|
3
|
-
"version": "01.07.
|
|
3
|
+
"version": "01.07.04",
|
|
4
4
|
"description": "Dynamic NodeTS (NodeJS-Typescript), MongoDB Backend System Framework by Future Development Program Ltd.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prep": "npm i rimraf nodemon -g",
|
|
7
|
+
"first-start": "npm run prep && nodemon",
|
|
8
|
+
"start": "nodemon",
|
|
7
9
|
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"build": "npm run build-
|
|
12
|
-
"build-tgz": "npm run build-simple && jasmine && npm pack && move ./*.tgz ../npm-tgz-collection",
|
|
10
|
+
"deploy": "npm run clean && npm run build-all",
|
|
11
|
+
"build": "npm run build-base && jasmine && npm publish",
|
|
12
|
+
"build-tgz": "npm run build-base && jasmine && npm pack && move ./*.tgz ../npm-tgz-collection",
|
|
13
|
+
"build-all": "npm run build-tgz && npm run build",
|
|
13
14
|
|
|
14
15
|
"build-base": "npm i && rimraf ./lib && npx tsc",
|
|
15
|
-
"build
|
|
16
|
-
"
|
|
17
|
-
"clean": "npm run prep && rimraf ./lib && rimraf package-lock.json && rimraf ./node_modules",
|
|
16
|
+
"clean-build": "npm run clean && npm run build-base",
|
|
17
|
+
"clean": "rimraf ./lib && rimraf package-lock.json && rimraf ./node_modules",
|
|
18
18
|
|
|
19
|
-
"test": "npm run build-
|
|
20
|
-
"test
|
|
19
|
+
"test": "npm run build-base && jasmine",
|
|
20
|
+
"clean-test": "npm run clean-build && jasmine"
|
|
21
21
|
},
|
|
22
22
|
"main": "./lib/index.js",
|
|
23
23
|
"module": "./lib/index.js",
|
|
@@ -221,8 +221,8 @@
|
|
|
221
221
|
"@types/socket.io-client": "^3.0.0",
|
|
222
222
|
"jasmine": "^5.0.2",
|
|
223
223
|
"jasmine-ts": "^0.4.0",
|
|
224
|
+
"socket.io": "^4.5.2",
|
|
224
225
|
"nodemon": "^3.0.1",
|
|
225
|
-
"rimraf": "^5.0.1"
|
|
226
|
-
"socket.io": "^4.5.2"
|
|
226
|
+
"rimraf": "^5.0.1"
|
|
227
227
|
}
|
|
228
228
|
}
|
|
@@ -24,7 +24,10 @@ export class DynamoNTS_SocketServer_Mock extends DynamoNTS_SocketServerService<D
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
protected async getPresenceFromSubscrioptionEventContent(socketSubscription: any, socket: Socket): Promise<DynamoNTS_SocketPresence> {
|
|
27
|
-
return new DynamoNTS_SocketPresence({
|
|
27
|
+
return new DynamoNTS_SocketPresence({
|
|
28
|
+
issuerId: socketSubscription.issuerId,
|
|
29
|
+
sockets: [ socket ]
|
|
30
|
+
}, 'ISSUER');
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
@@ -141,25 +141,6 @@ export class DynamoNTS_EndpointParams{
|
|
|
141
141
|
} else {
|
|
142
142
|
Dynamo_Log.info(msg);
|
|
143
143
|
}
|
|
144
|
-
|
|
145
|
-
/* if (this.logRequestsContent) {
|
|
146
|
-
const params = this.getPathParamsLogContent(req);
|
|
147
|
-
|
|
148
|
-
if (req.body && 0 < Object.keys(req.body).length) {
|
|
149
|
-
console.log(
|
|
150
|
-
`===> incoming ${this.name} request... (issuer: ${issuer})` +
|
|
151
|
-
`\npathParams: ${params}` +
|
|
152
|
-
`\nbody:`, req.body
|
|
153
|
-
);
|
|
154
|
-
} else {
|
|
155
|
-
console.log(
|
|
156
|
-
`===> incoming ${this.name} request... (issuer: ${issuer})` +
|
|
157
|
-
`\npathParams: ${params}`
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
} else {
|
|
161
|
-
console.log(`===> incoming ${this.name} request...`);
|
|
162
|
-
} */
|
|
163
144
|
}
|
|
164
145
|
|
|
165
146
|
} catch (error) {
|
|
@@ -203,7 +184,11 @@ export class DynamoNTS_EndpointParams{
|
|
|
203
184
|
}
|
|
204
185
|
}
|
|
205
186
|
} catch (error) {
|
|
206
|
-
|
|
187
|
+
Dynamo_Log.error(
|
|
188
|
+
'UNCATCHED getFullExecution ERROR',
|
|
189
|
+
'\nRequest:', req,
|
|
190
|
+
'\nResponse:', res, error, issuer
|
|
191
|
+
);
|
|
207
192
|
}
|
|
208
193
|
};
|
|
209
194
|
}
|
|
@@ -217,10 +202,9 @@ export class DynamoNTS_EndpointParams{
|
|
|
217
202
|
try {
|
|
218
203
|
let msg: string = `Endpoint catched an error. ${this.name} (${this.endpoint})`;
|
|
219
204
|
msg += this.getPathParamsLogContent(req);
|
|
220
|
-
msg += `\nERROR:`;
|
|
221
205
|
|
|
222
206
|
Dynamo_Log.error(msg);
|
|
223
|
-
|
|
207
|
+
Dynamo_Log.log('ERROR:',
|
|
224
208
|
(error as Dynamo_Error)?.flag?.includes('DYNAMO') ?
|
|
225
209
|
(error as Dynamo_Error).getErrorSimplified() :
|
|
226
210
|
error,
|
|
@@ -250,8 +234,8 @@ export class DynamoNTS_EndpointParams{
|
|
|
250
234
|
}
|
|
251
235
|
}
|
|
252
236
|
} catch (error) {
|
|
253
|
-
|
|
254
|
-
`\n\nDYNAMO MULTILEVEL ERROR:DynamoNTS_EndpointParams:error: (${this.name}, ${this.endpoint})` +
|
|
237
|
+
Dynamo_Log.error(
|
|
238
|
+
`\n\nDYNAMO MULTILEVEL ERROR:DynamoNTS_EndpointParams: error: (${this.name}, ${this.endpoint})` +
|
|
255
239
|
`\n(DYNAMO MULTILEVEL ERROR means, that the ERRORHANDLING is ALSO FAILED, and the error message was not sent.)` +
|
|
256
240
|
`\nERROR:`, error, '\n'
|
|
257
241
|
);
|
|
@@ -7,34 +7,58 @@ import * as SocketIO from 'socket.io';
|
|
|
7
7
|
*/
|
|
8
8
|
export class DynamoNTS_SocketPresence {
|
|
9
9
|
issuerId: string;
|
|
10
|
-
serviceName?: string;
|
|
11
|
-
sockets?: SocketIO.Socket[] = [];
|
|
10
|
+
serviceName?: string = 'unknown';
|
|
12
11
|
onDestroy?: (issuerId: string) => void = id => {};
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
defaultErrorUserMsg?: string =
|
|
14
|
+
`We encountered an unhandled Socket Error, ` +
|
|
15
|
+
`\nplease contact the responsible development team.`;
|
|
16
|
+
|
|
17
|
+
sockets?: SocketIO.Socket[] = [];
|
|
18
|
+
|
|
14
19
|
constructor(
|
|
15
|
-
set: DynamoNTS_SocketPresence
|
|
20
|
+
set: DynamoNTS_SocketPresence,
|
|
21
|
+
issuer: string
|
|
16
22
|
) {
|
|
17
23
|
if (!set?.issuerId) {
|
|
18
24
|
throw new Dynamo_Error({
|
|
19
|
-
|
|
25
|
+
...this._getDefaultErrorSettings(
|
|
26
|
+
'constructor',
|
|
27
|
+
new Error(
|
|
28
|
+
`trying to create DynamoNTS_SocketPresence without a valid issuerId!` +
|
|
29
|
+
`\nset: ${JSON.stringify(set)}`
|
|
30
|
+
),
|
|
31
|
+
issuer
|
|
32
|
+
),
|
|
33
|
+
|
|
20
34
|
errorCode: 'NTS-SD0-C00',
|
|
21
|
-
addECToUserMsg: true,
|
|
22
|
-
message: 'trying to create DynamoNTS_SocketPresence without a valid issuerId!',
|
|
23
|
-
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.'
|
|
24
35
|
});
|
|
25
36
|
}
|
|
26
37
|
|
|
27
38
|
this.issuerId = set.issuerId;
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
|
|
40
|
+
if (set.serviceName) {
|
|
41
|
+
this.serviceName = set.serviceName;
|
|
42
|
+
}
|
|
43
|
+
if (set.onDestroy) {
|
|
44
|
+
this.onDestroy = set.onDestroy;
|
|
45
|
+
}
|
|
46
|
+
if (set.defaultErrorUserMsg) {
|
|
47
|
+
this.defaultErrorUserMsg = set.defaultErrorUserMsg;
|
|
48
|
+
}
|
|
30
49
|
|
|
31
50
|
if (!set?.sockets?.length) {
|
|
32
51
|
throw new Dynamo_Error({
|
|
33
|
-
|
|
52
|
+
...this._getDefaultErrorSettings(
|
|
53
|
+
'constructor',
|
|
54
|
+
new Error(
|
|
55
|
+
`trying to create DynamoNTS_SocketPresence without a single active socket!` +
|
|
56
|
+
`\nissuerId: ${this.issuerId}`
|
|
57
|
+
),
|
|
58
|
+
issuer
|
|
59
|
+
),
|
|
60
|
+
|
|
34
61
|
errorCode: 'NTS-SD0-C01',
|
|
35
|
-
addECToUserMsg: true,
|
|
36
|
-
message: 'trying to create DynamoNTS_SocketPresence without a single active socket!',
|
|
37
|
-
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.'
|
|
38
62
|
});
|
|
39
63
|
}
|
|
40
64
|
|
|
@@ -46,7 +70,7 @@ export class DynamoNTS_SocketPresence {
|
|
|
46
70
|
* @param event
|
|
47
71
|
* @param content
|
|
48
72
|
*/
|
|
49
|
-
emitEvent?(event: string, content: any) {
|
|
73
|
+
emitEvent?(event: string, content: any, issuer: string) {
|
|
50
74
|
/* let anyFailed: boolean = false; */
|
|
51
75
|
const errors = [];
|
|
52
76
|
const inactiveSockets: SocketIO.Socket[] = [];
|
|
@@ -91,26 +115,51 @@ export class DynamoNTS_SocketPresence {
|
|
|
91
115
|
|
|
92
116
|
if (0 < errors.length) {
|
|
93
117
|
throw new Dynamo_Error({
|
|
118
|
+
...this._getDefaultErrorSettings(
|
|
119
|
+
'emitEvent',
|
|
120
|
+
new Error(
|
|
121
|
+
`Emitting event '${event}' on socket(s)(${this.serviceName}) failed!`+
|
|
122
|
+
`\n${errors.length} errors occured!`
|
|
123
|
+
),
|
|
124
|
+
issuer
|
|
125
|
+
),
|
|
126
|
+
|
|
94
127
|
status: 500,
|
|
95
128
|
errorCode: 'NTS-SPC-EE2',
|
|
96
|
-
addECToUserMsg: true,
|
|
97
|
-
message: `Emitting event '${event}' on socket(s)(${this.serviceName}) failed!`,
|
|
98
|
-
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.',
|
|
99
129
|
additionalContent: {
|
|
100
130
|
inactiveSockets: inactiveSockets,
|
|
101
131
|
errors: errors,
|
|
102
132
|
}
|
|
103
133
|
});
|
|
134
|
+
|
|
104
135
|
} else if (this.sockets.length === 0) {
|
|
105
136
|
throw new Dynamo_Error({
|
|
137
|
+
...this._getDefaultErrorSettings(
|
|
138
|
+
'emitEvent',
|
|
139
|
+
new Error(
|
|
140
|
+
`Emitting event '${event}' on socket(s)(${this.serviceName}) failed!`+
|
|
141
|
+
`\n No more sockets left connected!`
|
|
142
|
+
),
|
|
143
|
+
issuer
|
|
144
|
+
),
|
|
145
|
+
|
|
106
146
|
status: 404,
|
|
107
147
|
errorCode: 'NTS-SPC-EE3',
|
|
108
|
-
addECToUserMsg: true,
|
|
109
|
-
message: `Emitting event '${event}' on socket(s)(${this.serviceName}) failed! No more sockets left connected!`,
|
|
110
|
-
userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.',
|
|
111
148
|
});
|
|
112
149
|
}
|
|
113
150
|
}
|
|
151
|
+
|
|
152
|
+
private _getDefaultErrorSettings?(fnName: string, error: Error | Dynamo_Error, issuer: string) {
|
|
153
|
+
return {
|
|
154
|
+
status: (error as Dynamo_Error)?.___status ?? 406,
|
|
155
|
+
message: (error as Error)?.message ?? `${fnName} was UNSUCCESFUL (NTS; ${this.serviceName})`,
|
|
156
|
+
userMessage: this.defaultErrorUserMsg,
|
|
157
|
+
issuerService: this.serviceName + ` (${this?.constructor?.name}-DynamoNTS_SocketPresence)`,
|
|
158
|
+
addECToUserMsg: true,
|
|
159
|
+
issuer: issuer,
|
|
160
|
+
error: error,
|
|
161
|
+
}
|
|
162
|
+
}
|
|
114
163
|
|
|
115
164
|
}
|
|
116
165
|
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { Request, Response } from 'express';
|
|
6
|
+
|
|
2
7
|
import { Dynamo_DataParams } from '@futdevpro/fsm-dynamo';
|
|
3
8
|
|
|
4
9
|
import { DynamoNTS_ServiceCollection } from '../../_services/core/service-collection.service';
|
|
5
10
|
import { DynamoNTS_EmailService } from '../../_services/core/email.service';
|
|
6
11
|
import { DynamoNTS_AuthService } from '../../_services/core/auth.service';
|
|
7
12
|
|
|
13
|
+
|
|
8
14
|
export interface DynamoNTS_GlobalServiceSettings {
|
|
9
15
|
/**
|
|
10
16
|
* You need to setup your Own Auth Service extending the DynamoNTS_AuthService class
|
|
@@ -30,5 +36,10 @@ export interface DynamoNTS_GlobalServiceSettings {
|
|
|
30
36
|
* you can setup socket services by passing a DynamoNTS_SocketServiceCollection list at this point
|
|
31
37
|
*/
|
|
32
38
|
/* socketServiceCollection?: DynamoNTS_SocketServiceCollection, */
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* you can setup global error handler by passing a function at this point
|
|
42
|
+
*/
|
|
43
|
+
errorHandler?: (err: any, req?: Request, res?: Response, issuer?: string) => Promise<void>,
|
|
33
44
|
}
|
|
34
45
|
|
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import * as BodyParser from 'body-parser';
|
|
3
|
+
export class DynamoNTS_PortSettings {
|
|
4
|
+
httpPort?: number;
|
|
5
|
+
httpsPort?: number;
|
|
6
|
+
|
|
7
|
+
httpEncodeSettings?: BodyParser.OptionsUrlencoded = {
|
|
8
|
+
limit: '50mb',
|
|
9
|
+
extended: true,
|
|
10
|
+
};
|
|
11
|
+
httpJsonSettings?: BodyParser.OptionsJson = {
|
|
12
|
+
limit: '50mb',
|
|
13
|
+
};
|
|
14
|
+
httpsEncodeSettings?: BodyParser.OptionsUrlencoded = {
|
|
15
|
+
limit: '50mb',
|
|
16
|
+
extended: true,
|
|
17
|
+
};
|
|
18
|
+
httpsJsonSettings?: BodyParser.OptionsJson = {
|
|
19
|
+
limit: '50mb',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
set: DynamoNTS_PortSettings
|
|
24
|
+
) {
|
|
25
|
+
Object.assign(this, set);
|
|
26
|
+
}
|
|
5
27
|
}
|
|
@@ -75,7 +75,6 @@ export class UsageController extends DynamoNTS_Controller {
|
|
|
75
75
|
name: 'closeSession',
|
|
76
76
|
type: DynamoNTS_HttpCallType.get,
|
|
77
77
|
endpoint: usageModuleSettings.endPoints.closeSession,
|
|
78
|
-
preProcessess: [ this.authService.authTokenPermAccUsageData ],
|
|
79
78
|
tasks: [
|
|
80
79
|
async (req: Request, res: Response, issuer: string) => {
|
|
81
80
|
const usageService = new UsageService({
|
|
@@ -548,7 +548,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
548
548
|
* (when you simultaneously trying to change the same data's
|
|
549
549
|
* different values from different flows)
|
|
550
550
|
*/
|
|
551
|
-
async saveData(): Promise<
|
|
551
|
+
async saveData(): Promise<T> {
|
|
552
552
|
try {
|
|
553
553
|
if (!this.data) {
|
|
554
554
|
throw new Dynamo_Error({
|
|
@@ -561,7 +561,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
561
561
|
if (!this.data._id && (!this.depKey || !this.data[this.depKey])) {
|
|
562
562
|
// if ID of dependencyID is not present, data not exists, create new data
|
|
563
563
|
this.data = await this.dataDBService.createData(this.data, this.issuer);
|
|
564
|
-
return;
|
|
564
|
+
return this.data;
|
|
565
565
|
}
|
|
566
566
|
|
|
567
567
|
let dataExists: T;
|
|
@@ -569,10 +569,12 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
569
569
|
// check if data already exists with the specific ID
|
|
570
570
|
if (this.data._id) {
|
|
571
571
|
dataExists = await this.getDataById(null, true);
|
|
572
|
+
|
|
572
573
|
if (dataExists) {
|
|
573
574
|
// if data exists do modify
|
|
574
575
|
this.data = await this.dataDBService.modifyData(this.data, this.issuer);
|
|
575
|
-
return;
|
|
576
|
+
return this.data;
|
|
577
|
+
|
|
576
578
|
} else {
|
|
577
579
|
throw new Dynamo_Error({
|
|
578
580
|
...this._getDefaultErrorSettings(
|
|
@@ -603,7 +605,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
603
605
|
if (dataExists) {
|
|
604
606
|
// if data exists do modify
|
|
605
607
|
this.data = await this.dataDBService.modifyData(this.data, this.issuer);
|
|
606
|
-
return;
|
|
608
|
+
return this.data;
|
|
607
609
|
} else {
|
|
608
610
|
// if data not exists check that dependency already exists for this
|
|
609
611
|
const dependencyExists = await this.getDependencyDataDBService().getDataById(this.data[this.depKey]);
|
|
@@ -623,6 +625,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
623
625
|
|
|
624
626
|
// if data not exists create new data
|
|
625
627
|
this.data = await this.dataDBService.createData(this.data, this.issuer);
|
|
628
|
+
return this.data;
|
|
626
629
|
|
|
627
630
|
} catch (error) {
|
|
628
631
|
if (['NTS-DS0-SD1', 'NTS-DS0-SD2'].includes(error?.errorCode)) {
|
|
@@ -784,7 +787,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
784
787
|
addECToUserMsg: true,
|
|
785
788
|
userMessage: this.defaultErrorUserMsg,
|
|
786
789
|
issuer: this.issuer,
|
|
787
|
-
issuerService: this.serviceName
|
|
790
|
+
issuerService: this.serviceName + ` (${this?.constructor?.name}-DynamoNTS_DataService)`,
|
|
788
791
|
error: error,
|
|
789
792
|
}
|
|
790
793
|
}
|
|
@@ -205,49 +205,53 @@ export class DynamoNTS_ApiService {
|
|
|
205
205
|
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL`/* , new Error() */);
|
|
206
206
|
|
|
207
207
|
throw new Dynamo_Error({
|
|
208
|
-
|
|
209
|
-
|
|
208
|
+
...this._getDefaultErrorSettings(
|
|
209
|
+
callParams.name + ' startApiCall',
|
|
210
|
+
error.response.data
|
|
211
|
+
),
|
|
212
|
+
|
|
213
|
+
errorCode: 'NTS-API-SAC1',
|
|
210
214
|
message: 'API call failed on the other end! error response found...',
|
|
211
|
-
userMessage: this.defaultErrorUserMsg,
|
|
212
|
-
issuerService: this.name,
|
|
213
|
-
error: error.response.data,
|
|
214
215
|
});
|
|
215
216
|
|
|
216
217
|
} else if (error.code === 'ENOTFOUND') {
|
|
217
218
|
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL`/* , new Error() */);
|
|
218
219
|
|
|
219
220
|
throw new Dynamo_Error({
|
|
221
|
+
...this._getDefaultErrorSettings(
|
|
222
|
+
callParams.name + ' startApiCall',
|
|
223
|
+
error
|
|
224
|
+
),
|
|
225
|
+
|
|
220
226
|
status: 404,
|
|
221
|
-
errorCode: 'NTS-API-
|
|
222
|
-
addECToUserMsg: true,
|
|
227
|
+
errorCode: 'NTS-API-SAC2',
|
|
223
228
|
message: 'DNS error; address cannot be resolved!',
|
|
224
|
-
userMessage: this.defaultErrorUserMsg,
|
|
225
|
-
issuerService: this.name,
|
|
226
|
-
error
|
|
227
229
|
});
|
|
228
230
|
|
|
229
231
|
} else if (error.code === 'ECONNREFUSED') {
|
|
230
232
|
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL`/* , new Error() */);
|
|
231
233
|
|
|
232
234
|
throw new Dynamo_Error({
|
|
235
|
+
...this._getDefaultErrorSettings(
|
|
236
|
+
callParams.name + ' startApiCall',
|
|
237
|
+
error
|
|
238
|
+
),
|
|
239
|
+
|
|
233
240
|
status: 404,
|
|
234
|
-
errorCode: 'NTS-API-
|
|
235
|
-
|
|
236
|
-
message: 'Authentication error!',
|
|
237
|
-
userMessage: this.defaultErrorUserMsg,
|
|
238
|
-
issuerService: this.name,
|
|
239
|
-
error
|
|
241
|
+
errorCode: 'NTS-API-SAC3',
|
|
242
|
+
message: `Can't connect to the endpoin!`,
|
|
240
243
|
});
|
|
241
244
|
|
|
242
245
|
} else if (error.config && error.message) {
|
|
243
246
|
|
|
244
247
|
throw new Dynamo_Error({
|
|
248
|
+
...this._getDefaultErrorSettings(
|
|
249
|
+
callParams.name + ' startApiCall',
|
|
250
|
+
error
|
|
251
|
+
),
|
|
252
|
+
|
|
245
253
|
status: +error.message.substring(error.message.length - 4, 3),
|
|
246
|
-
errorCode: 'NTS-API-
|
|
247
|
-
addECToUserMsg: true,
|
|
248
|
-
userMessage: this.defaultErrorUserMsg,
|
|
249
|
-
issuerService: this/* .constructor */.name,
|
|
250
|
-
error
|
|
254
|
+
errorCode: 'NTS-API-SAC4',
|
|
251
255
|
});
|
|
252
256
|
} else {
|
|
253
257
|
Dynamo_Log.error(`\n${callParams.name} was UNSUCCESSFUL`, error/*, '\n\n' , new Error() */);
|
|
@@ -256,5 +260,16 @@ export class DynamoNTS_ApiService {
|
|
|
256
260
|
}
|
|
257
261
|
}
|
|
258
262
|
}
|
|
263
|
+
|
|
264
|
+
private static _getDefaultErrorSettings(fnName: string, error: Error | Dynamo_Error) {
|
|
265
|
+
return {
|
|
266
|
+
status: (error as Dynamo_Error)?.___status ?? 500,
|
|
267
|
+
message: (error as Error)?.message ?? `${fnName} was UNSUCCESFUL (NTS)`,
|
|
268
|
+
addECToUserMsg: true,
|
|
269
|
+
userMessage: this.defaultErrorUserMsg,
|
|
270
|
+
issuerService: `${this?.constructor?.name}-${this?.name}-DynamoNTS_ApiService`,
|
|
271
|
+
error: error,
|
|
272
|
+
}
|
|
273
|
+
}
|
|
259
274
|
}
|
|
260
275
|
|
|
@@ -168,7 +168,7 @@ export class DynamoNTS_EmailService {
|
|
|
168
168
|
});
|
|
169
169
|
});
|
|
170
170
|
} catch (error) {
|
|
171
|
-
if (error
|
|
171
|
+
if (error?.includes?.('all recipients were rejected')) {
|
|
172
172
|
throw new Dynamo_Error({
|
|
173
173
|
...this._getDefaultErrorSettings('sendEmail', error, issuer),
|
|
174
174
|
|
|
@@ -37,11 +37,8 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
|
|
|
37
37
|
dbServiceCollection: DynamoNTS_ServiceCollection<DynamoNTS_DBService<any>>; // DynamoNTS_DBServiceCollection;
|
|
38
38
|
emailServiceCollection: DynamoNTS_ServiceCollection<DynamoNTS_EmailService>; // DynamoNTS_EmailServiceCollection;
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return this._globalErrorHandler;
|
|
43
|
-
}
|
|
44
|
-
|
|
40
|
+
static globalErrorHandler?: (err: any, req?: Request, res?: Response, issuer?: string) => Promise<void>;
|
|
41
|
+
|
|
45
42
|
/**
|
|
46
43
|
* You need to setup global Services through this function
|
|
47
44
|
*/
|
|
@@ -66,6 +63,7 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
|
|
|
66
63
|
|
|
67
64
|
this.instance.authService = set.authService;
|
|
68
65
|
this.instance.emailServiceCollection = set.emailServiceCollection;
|
|
66
|
+
DynamoNTS_GlobalService.globalErrorHandler = set.errorHandler;
|
|
69
67
|
} catch (error) {
|
|
70
68
|
Dynamo_Log.error(`Failed to create DynamoNTS_GlobalService.`, error);
|
|
71
69
|
/* error = new Dynamo_Error({
|
|
@@ -80,10 +78,6 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
|
|
|
80
78
|
this._params = params;
|
|
81
79
|
}
|
|
82
80
|
|
|
83
|
-
static setGlobalErrorHandler(handler?: (err: any, req: Request, res: Response, issuer: string) => Promise<void>): void {
|
|
84
|
-
this.instance.globalErrorHandler = handler;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
81
|
/**
|
|
88
82
|
*
|
|
89
83
|
* @returns
|
|
@@ -114,8 +114,8 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
114
114
|
|
|
115
115
|
private systemControlsExt: DynamoNTS_AppExtSysControls = new DynamoNTS_AppExtSysControls();
|
|
116
116
|
override get started(): boolean { return this.systemControlsExt.appExtended.started; }
|
|
117
|
-
private
|
|
118
|
-
private
|
|
117
|
+
private httpsSocketSettingUpCount: number = 0;
|
|
118
|
+
private httpSocketSettingUpCount: number = 0;
|
|
119
119
|
|
|
120
120
|
private socketSecurity: DynamoNTS_RouteSecurity;
|
|
121
121
|
|
|
@@ -137,7 +137,11 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
137
137
|
super(true);
|
|
138
138
|
|
|
139
139
|
this.asyncConstructExt().catch((error: any) => {
|
|
140
|
-
Dynamo_Log.error(
|
|
140
|
+
Dynamo_Log.error(
|
|
141
|
+
`\nExtended Application: ${this.params?.name} start failed.` +
|
|
142
|
+
`\n`, error,
|
|
143
|
+
'\n'
|
|
144
|
+
);
|
|
141
145
|
});
|
|
142
146
|
}
|
|
143
147
|
|
|
@@ -169,7 +173,11 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
169
173
|
Dynamo_Log.H_success(`${this.params.name} started successfully.`);
|
|
170
174
|
|
|
171
175
|
} catch (error) {
|
|
172
|
-
Dynamo_Log.error(
|
|
176
|
+
Dynamo_Log.error(
|
|
177
|
+
`\nExtended Application: ${this.params?.name} start failed.` +
|
|
178
|
+
`\n`, error,
|
|
179
|
+
'\n'
|
|
180
|
+
);
|
|
173
181
|
throw new Dynamo_Error({
|
|
174
182
|
errorCode: 'NTS-AES-001',
|
|
175
183
|
error: error,
|
|
@@ -387,7 +395,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
387
395
|
|
|
388
396
|
if (service.security === DynamoNTS_SocketSecurity.open) {
|
|
389
397
|
if (this.logSetup) console.log(`\nsocket setup (open): ${service?.name}:${service.port}`);
|
|
390
|
-
this.
|
|
398
|
+
this.httpSocketSettingUpCount++;
|
|
391
399
|
this.systemControlsExt.httpSocketServer.started = false;
|
|
392
400
|
|
|
393
401
|
this.allSocketServers.push(
|
|
@@ -395,8 +403,8 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
395
403
|
new SocketIO.Server(this.httpSocketServer),
|
|
396
404
|
DynamoNTS_SocketSecurity.open,
|
|
397
405
|
() => {
|
|
398
|
-
this.
|
|
399
|
-
if (this.
|
|
406
|
+
this.httpSocketSettingUpCount--;
|
|
407
|
+
if (this.httpSocketSettingUpCount === 0) {
|
|
400
408
|
this.systemControlsExt.httpSocketServer.started = true;
|
|
401
409
|
}
|
|
402
410
|
}
|
|
@@ -405,7 +413,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
405
413
|
|
|
406
414
|
} else if (service.security === DynamoNTS_SocketSecurity.secure) {
|
|
407
415
|
if (this.logSetup) console.log(`\nsocket setup (secure): ${service?.name}:${service.port}`);
|
|
408
|
-
this.
|
|
416
|
+
this.httpsSocketSettingUpCount++;
|
|
409
417
|
this.systemControlsExt.httpsSocketServer.started = false;
|
|
410
418
|
|
|
411
419
|
this.allSocketServers.push(
|
|
@@ -413,8 +421,8 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
413
421
|
new SocketIO.Server(this.httpsServer),
|
|
414
422
|
DynamoNTS_SocketSecurity.secure,
|
|
415
423
|
() => {
|
|
416
|
-
this.
|
|
417
|
-
if (this.
|
|
424
|
+
this.httpsSocketSettingUpCount--;
|
|
425
|
+
if (this.httpsSocketSettingUpCount === 0) {
|
|
418
426
|
this.systemControlsExt.httpsSocketServer.started = true;
|
|
419
427
|
}
|
|
420
428
|
}
|