@futdevpro/nts-dynamo 1.9.15 → 1.9.16
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 +7 -7
- package/.github/workflows/main.yml +206 -0
- package/HOWTO.md +15 -15
- package/README.md +140 -140
- package/build/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/endpoint-params.control-model.js +2 -0
- package/build/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/build/_models/control-models/socket-event.control-model.js +1 -1
- package/build/_services/core/global.service.d.ts.map +1 -1
- package/build/_services/core/global.service.js +1 -0
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/route/routing-module.service.d.ts +1 -0
- package/build/_services/route/routing-module.service.d.ts.map +1 -1
- package/build/_services/route/routing-module.service.js +17 -23
- package/build/_services/route/routing-module.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +4 -1
- package/build/_services/server/app.server.js.map +1 -1
- package/build/_services/socket/socket-client.service.d.ts.map +1 -1
- package/build/_services/socket/socket-client.service.js +1 -0
- package/build/_services/socket/socket-client.service.js.map +1 -1
- package/nodemon.json +17 -15
- package/package.json +5 -5
- package/src/_constants/global-settings.const.ts +27 -27
- package/src/_constants/index.ts +2 -2
- package/src/_constants/mocks/app-extended-server.mock.ts +198 -198
- package/src/_constants/mocks/app-params.mock.ts +9 -9
- package/src/_constants/mocks/app-server.mock.ts +185 -185
- package/src/_constants/mocks/auth-service.mock.ts +28 -28
- package/src/_constants/mocks/controller.mock.ts +16 -16
- package/src/_constants/mocks/data-model.mock.ts +83 -83
- package/src/_constants/mocks/email-service-collection.mock.ts +13 -13
- package/src/_constants/mocks/email-service.mock.ts +19 -19
- package/src/_constants/mocks/email-template.mock.html +14 -14
- package/src/_constants/mocks/endpoint.mock.ts +90 -90
- package/src/_constants/mocks/socket-client.mock.ts +43 -43
- package/src/_constants/mocks/socket-server.mock.ts +43 -43
- package/src/_enums/data-model-type.enum.ts +14 -14
- package/src/_enums/data-service-function.enum.ts +15 -15
- package/src/_enums/http/http-call-type.enum.ts +12 -12
- package/src/_enums/http/http-response-type.enum.ts +7 -7
- package/src/_enums/http/socket-event-type.enum.ts +18 -18
- package/src/_enums/index.ts +13 -13
- package/src/_enums/predefined-data-types.enum.ts +27 -27
- package/src/_enums/route-security.enum.ts +12 -12
- package/src/_enums/socket-security.enum.ts +11 -11
- package/src/_models/control-models/api-call-params.control-model.ts +126 -126
- package/src/_models/control-models/app-ext-system-controls.control-model.ts +9 -9
- package/src/_models/control-models/app-params.control-model.ts +45 -45
- package/src/_models/control-models/app-system-controls.control-model.ts +9 -9
- package/src/_models/control-models/endpoint-params.control-model.ts +309 -307
- package/src/_models/control-models/http-settings.control-model.ts +29 -29
- package/src/_models/control-models/index.ts +13 -13
- package/src/_models/control-models/socket-client-service-params.control-model.ts +28 -28
- package/src/_models/control-models/socket-event.control-model.ts +150 -150
- package/src/_models/control-models/socket-presence.control-model.ts +207 -207
- package/src/_models/control-models/socket-server-service-params.control-model.ts +20 -20
- package/src/_models/control-models/system-control.control-model.ts +12 -12
- package/src/_models/index.ts +9 -9
- package/src/_models/interfaces/certification-settings.interface.ts +7 -7
- package/src/_models/interfaces/global-service-settings.interface.ts +45 -45
- package/src/_models/interfaces/global-settings.interface.ts +83 -83
- package/src/_models/interfaces/index.ts +7 -7
- package/src/_models/interfaces/routing-module-settings.interface.ts +20 -20
- package/src/_models/types/db-filter.type.ts +108 -108
- package/src/_models/types/db-update.type.ts +100 -100
- package/src/_models/types/index.ts +5 -5
- package/src/_modules/api-service.index.ts +12 -12
- package/src/_modules/app-extended.index.ts +28 -28
- package/src/_modules/app.index.ts +24 -24
- package/src/_modules/auth.index.ts +7 -7
- package/src/_modules/constants.index.ts +2 -2
- package/src/_modules/controller.index.ts +10 -10
- package/src/_modules/custom-data/custom-data.controller.ts +69 -69
- package/src/_modules/custom-data/custom-data.data-service.ts +20 -20
- package/src/_modules/custom-data/get-custom-data-routing-module.util.ts +23 -23
- package/src/_modules/custom-data/index.ts +6 -6
- package/src/_modules/custom-data-module.index.ts +2 -2
- package/src/_modules/data-service.index.ts +9 -9
- package/src/_modules/email.index.ts +8 -8
- package/src/_modules/enums.index.ts +2 -2
- package/src/_modules/extended.index.ts +8 -8
- package/src/_modules/models.index.ts +2 -2
- package/src/_modules/services.index.ts +2 -2
- package/src/_modules/test/get-test-routing-module.util.ts +23 -23
- package/src/_modules/test/index.ts +5 -5
- package/src/_modules/test/test.controller.ts +115 -115
- package/src/_modules/test-module.index.ts +2 -2
- package/src/_modules/usage/get-usage-routing-module.util.ts +22 -22
- package/src/_modules/usage/index.ts +7 -7
- package/src/_modules/usage/usage.controller.ts +120 -120
- package/src/_modules/usage/usage.data-service.ts +172 -172
- package/src/_modules/usage-module.index.ts +2 -2
- package/src/_services/base/data.service.ts +921 -921
- package/src/_services/base/db.service.spec.ts +32 -32
- package/src/_services/base/db.service.ts +1063 -1063
- package/src/_services/base/singleton.service.ts +21 -21
- package/src/_services/core/api.service.ts +453 -453
- package/src/_services/core/auth.service.ts +172 -172
- package/src/_services/core/email.service.ts +678 -678
- package/src/_services/core/global.service.ts +270 -269
- package/src/_services/core/service-collection.service.ts +5 -5
- package/src/_services/index.ts +23 -23
- package/src/_services/route/controller.service.ts +129 -129
- package/src/_services/route/routing-module.service.ts +293 -273
- package/src/_services/server/app-extended.server.spec.ts +76 -76
- package/src/_services/server/app-extended.server.ts +520 -520
- package/src/_services/server/app.server.spec.ts +67 -67
- package/src/_services/server/app.server.ts +1181 -1179
- package/src/_services/shared.service.spec.ts +19 -19
- package/src/_services/shared.static-service.ts +73 -73
- package/src/_services/socket/socket-client.service.ts +236 -235
- package/src/_services/socket/socket-server.service.spec.ts +11 -11
- package/src/_services/socket/socket-server.service.ts +761 -761
- package/src/index.ts +18 -18
- package/tsconfig.json +41 -41
- package/build/tsconfig.tsbuildinfo +0 -1
|
@@ -1,307 +1,309 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { Request, Response } from 'express';
|
|
4
|
-
|
|
5
|
-
import { DynamoFM_Array, DynamoFM_Error, DynamoFM_Log } from '@futdevpro/fsm-dynamo';
|
|
6
|
-
import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
|
|
7
|
-
import { DynamoNTS_HttpCallType } from '../../_enums/http/http-call-type.enum';
|
|
8
|
-
import { DynamoNTS_globalSettings } from '../../_constants/global-settings.const';
|
|
9
|
-
import { DynamoNTS_GlobalService } from '../../_services/core/global.service';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* High level endpoint for API
|
|
13
|
-
* used for specific events such as saving or getting data,
|
|
14
|
-
* triggering events, logging in or out, and much more
|
|
15
|
-
*/
|
|
16
|
-
export class DynamoNTS_Endpoint_Params {
|
|
17
|
-
name: string;
|
|
18
|
-
security: DynamoNTS_RouteSecurity;
|
|
19
|
-
|
|
20
|
-
type: DynamoNTS_HttpCallType;
|
|
21
|
-
endpoint: string;
|
|
22
|
-
|
|
23
|
-
private pathParams: string[];
|
|
24
|
-
|
|
25
|
-
private preProcesses: ((req: Request, res: Response) => Promise<void>)[];
|
|
26
|
-
private tasks: ((req: Request, res: Response, issuer?: string) => Promise<void>)[];
|
|
27
|
-
|
|
28
|
-
private logRequest: boolean;
|
|
29
|
-
private logRequestsParams: boolean;
|
|
30
|
-
private logRequestsContent: boolean;
|
|
31
|
-
private logResponseContent: boolean;
|
|
32
|
-
|
|
33
|
-
constructor(
|
|
34
|
-
set: {
|
|
35
|
-
/**
|
|
36
|
-
* naming the endpoint will help to follow events on service
|
|
37
|
-
*/
|
|
38
|
-
name: string,
|
|
39
|
-
/**
|
|
40
|
-
* security settings for API, different security paths will need different handlers
|
|
41
|
-
*
|
|
42
|
-
* open; http, secure; https or both
|
|
43
|
-
*/
|
|
44
|
-
security?: DynamoNTS_RouteSecurity,
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* define basic Http Call Type such as; get, post, put, patch, delete
|
|
48
|
-
*/
|
|
49
|
-
type: DynamoNTS_HttpCallType,
|
|
50
|
-
/**
|
|
51
|
-
* set endpoint here, without baseUrl and route module path
|
|
52
|
-
*
|
|
53
|
-
* like: '/get-user/:userId'
|
|
54
|
-
*/
|
|
55
|
-
endpoint: string,
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* preProcesses are the functions you need to run before the actual function,
|
|
59
|
-
* such as authentications
|
|
60
|
-
*/
|
|
61
|
-
preProcesses?: ((req: Request, res: Response) => Promise<void>)[],
|
|
62
|
-
/**
|
|
63
|
-
* the actual tasks to run,
|
|
64
|
-
* the last one should contain the res.send(); execution to send response on API requests
|
|
65
|
-
*/
|
|
66
|
-
tasks: ((req: Request, res: Response, issuer?: string) => Promise<void>)[],
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* this flag will enable the debug logs on this endpoint
|
|
70
|
-
*/
|
|
71
|
-
logRequest?: boolean,
|
|
72
|
-
/**
|
|
73
|
-
* this flag will enable the debug logs on this endpoint's requests
|
|
74
|
-
*/
|
|
75
|
-
logRequestsParams?: boolean,
|
|
76
|
-
/**
|
|
77
|
-
* this flag will enable the debug logs on this endpoint's requests
|
|
78
|
-
*/
|
|
79
|
-
logRequestsContent?: boolean,
|
|
80
|
-
/**
|
|
81
|
-
* this flag will enable detailed debug logs on this endpoint's requests
|
|
82
|
-
*/
|
|
83
|
-
logResponseContent?: boolean,
|
|
84
|
-
}
|
|
85
|
-
) {
|
|
86
|
-
try {
|
|
87
|
-
this.name = set.name ?? set.endpoint;
|
|
88
|
-
this.security = set.security ?? DynamoNTS_globalSettings.defaultRouteSecurity;
|
|
89
|
-
|
|
90
|
-
this.type = set.type;
|
|
91
|
-
this.endpoint = set.endpoint;
|
|
92
|
-
|
|
93
|
-
if (!this.endpoint) {
|
|
94
|
-
throw new DynamoFM_Error({
|
|
95
|
-
status: 406,
|
|
96
|
-
errorCode: 'NTS-EP0-C00',
|
|
97
|
-
addECToUserMsg: true,
|
|
98
|
-
message: 'trying to create DynamoNTS_EndpointParams without endpoint value',
|
|
99
|
-
userMessage:
|
|
100
|
-
'We encountered an unhandled Server Error, ' +
|
|
101
|
-
'please contact the responsible development team.',
|
|
102
|
-
additionalContent: set,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
let pathParts: string[] = this.endpoint.split('/');
|
|
107
|
-
|
|
108
|
-
pathParts = pathParts.filter((part: string): boolean => part[0] === ':');
|
|
109
|
-
pathParts = pathParts.map((part: string): string => part.replace(':', ''));
|
|
110
|
-
this.pathParams = pathParts;
|
|
111
|
-
|
|
112
|
-
this.preProcesses = set.preProcesses ?? [];
|
|
113
|
-
this.tasks = set.tasks ?? [];
|
|
114
|
-
|
|
115
|
-
this.logRequest = set.logRequest ?? DynamoNTS_globalSettings.logRequest;
|
|
116
|
-
this.logRequestsParams = set.logRequestsParams ?? DynamoNTS_globalSettings.logRequestsParams;
|
|
117
|
-
this.logRequestsContent =
|
|
118
|
-
set.logRequestsContent ?? DynamoNTS_globalSettings.logRequestsContent;
|
|
119
|
-
this.logResponseContent =
|
|
120
|
-
set.logResponseContent ?? DynamoNTS_globalSettings.logResponseContent;
|
|
121
|
-
} catch (error) {
|
|
122
|
-
DynamoFM_Log.error(
|
|
123
|
-
`\nEndpoint params setup failed: name: '${set.name}' ` +
|
|
124
|
-
`(security: ${set.security}) endpoint: ${set.endpoint}` +
|
|
125
|
-
`\nERROR:` +
|
|
126
|
-
`\n`, error
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
throw error;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
*
|
|
135
|
-
* @returns
|
|
136
|
-
*/
|
|
137
|
-
private async preLog(req: Request, res: Response, issuer: string): Promise<void> {
|
|
138
|
-
try {
|
|
139
|
-
if (this.logRequest) {
|
|
140
|
-
let msg: string = `\n===>>> incoming '${this.name}' request... (issuer: ${issuer})`;
|
|
141
|
-
|
|
142
|
-
if (this.logRequestsParams) {
|
|
143
|
-
const params = this.getPathParamsLogContent(req);
|
|
144
|
-
|
|
145
|
-
msg += `\npathParams: ${params}`;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (this.logRequestsContent && req.body && 0 < Object.keys(req.body).length) {
|
|
149
|
-
DynamoFM_Log.info(msg + `\nbody:`, req.body);
|
|
150
|
-
} else {
|
|
151
|
-
DynamoFM_Log.info(msg);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
} catch (error) {
|
|
156
|
-
this.error(req, res, error, issuer);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
*
|
|
162
|
-
* @returns
|
|
163
|
-
*/
|
|
164
|
-
getFullExecution(): (req: Request, res: Response) => Promise<void> {
|
|
165
|
-
let issuer: string;
|
|
166
|
-
|
|
167
|
-
return async (req: Request, res: Response): Promise<void> => {
|
|
168
|
-
try {
|
|
169
|
-
issuer = DynamoNTS_GlobalService?.getAuthService()?.getIssuerFromRequest(req);
|
|
170
|
-
|
|
171
|
-
if (this.logRequest) {
|
|
172
|
-
await this.preLog(req, res, issuer);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
await DynamoFM_Array.asyncForEach(this.preProcesses,
|
|
176
|
-
async (preProcess: (req: Request, res: Response) => Promise<void>): Promise<void> => {
|
|
177
|
-
await preProcess(req, res);
|
|
178
|
-
}
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
await DynamoFM_Array.asyncForEach(this.tasks,
|
|
182
|
-
async (
|
|
183
|
-
task: (req: Request, res: Response, issuer?: string) => Promise<void>
|
|
184
|
-
): Promise<void> => {
|
|
185
|
-
await task(req, res, issuer);
|
|
186
|
-
}
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
if (this.logRequest) {
|
|
190
|
-
if (this.logResponseContent) {
|
|
191
|
-
DynamoFM_Log.success(` <<<===== '${this.name}' result sent.`);
|
|
192
|
-
DynamoFM_Log.warn('sorry, the logResponseContent is not implemented yet.');
|
|
193
|
-
} else {
|
|
194
|
-
DynamoFM_Log.success(` <<<===== '${this.name}' result sent.`);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
} catch (error) {
|
|
198
|
-
this.error(req, res, error, issuer);
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
*
|
|
205
|
-
* @param res
|
|
206
|
-
* @param error
|
|
207
|
-
*/
|
|
208
|
-
private async error(
|
|
209
|
-
req: Request,
|
|
210
|
-
res: Response,
|
|
211
|
-
error: Error | DynamoFM_Error,
|
|
212
|
-
issuer: string
|
|
213
|
-
): Promise<void> {
|
|
214
|
-
try {
|
|
215
|
-
let msg: string = `Endpoint catched an error. '${this.name}' (${this.endpoint})`;
|
|
216
|
-
|
|
217
|
-
msg += this.getPathParamsLogContent(req);
|
|
218
|
-
|
|
219
|
-
DynamoFM_Log.error(msg);
|
|
220
|
-
DynamoFM_Log.error(
|
|
221
|
-
'ERROR:',
|
|
222
|
-
(error as DynamoFM_Error)?.flag?.includes('DYNAMO') ?
|
|
223
|
-
(error as DynamoFM_Error).getErrorSimplified() :
|
|
224
|
-
error,
|
|
225
|
-
'\n'
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
if ((error as DynamoFM_Error)?.flag?.includes('DYNAMO')) {
|
|
229
|
-
if (!(error as DynamoFM_Error).additionalContent) {
|
|
230
|
-
(error as DynamoFM_Error).additionalContent = {};
|
|
231
|
-
}
|
|
232
|
-
(error as DynamoFM_Error).additionalContent.endpointInfo = msg;
|
|
233
|
-
DynamoFM_Log.error(`ErrorMessage: ${(error as DynamoFM_Error)._message}`);
|
|
234
|
-
DynamoFM_Log.error(`ErrorCode: ${(error as DynamoFM_Error)._errorCode}`);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
(error as DynamoFM_Error)
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
res.
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
DynamoFM_Log.error(`
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { Request, Response } from 'express';
|
|
4
|
+
|
|
5
|
+
import { DynamoFM_Array, DynamoFM_Error, DynamoFM_Log } from '@futdevpro/fsm-dynamo';
|
|
6
|
+
import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
|
|
7
|
+
import { DynamoNTS_HttpCallType } from '../../_enums/http/http-call-type.enum';
|
|
8
|
+
import { DynamoNTS_globalSettings } from '../../_constants/global-settings.const';
|
|
9
|
+
import { DynamoNTS_GlobalService } from '../../_services/core/global.service';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* High level endpoint for API
|
|
13
|
+
* used for specific events such as saving or getting data,
|
|
14
|
+
* triggering events, logging in or out, and much more
|
|
15
|
+
*/
|
|
16
|
+
export class DynamoNTS_Endpoint_Params {
|
|
17
|
+
name: string;
|
|
18
|
+
security: DynamoNTS_RouteSecurity;
|
|
19
|
+
|
|
20
|
+
type: DynamoNTS_HttpCallType;
|
|
21
|
+
endpoint: string;
|
|
22
|
+
|
|
23
|
+
private pathParams: string[];
|
|
24
|
+
|
|
25
|
+
private preProcesses: ((req: Request, res: Response) => Promise<void>)[];
|
|
26
|
+
private tasks: ((req: Request, res: Response, issuer?: string) => Promise<void>)[];
|
|
27
|
+
|
|
28
|
+
private logRequest: boolean;
|
|
29
|
+
private logRequestsParams: boolean;
|
|
30
|
+
private logRequestsContent: boolean;
|
|
31
|
+
private logResponseContent: boolean;
|
|
32
|
+
|
|
33
|
+
constructor(
|
|
34
|
+
set: {
|
|
35
|
+
/**
|
|
36
|
+
* naming the endpoint will help to follow events on service
|
|
37
|
+
*/
|
|
38
|
+
name: string,
|
|
39
|
+
/**
|
|
40
|
+
* security settings for API, different security paths will need different handlers
|
|
41
|
+
*
|
|
42
|
+
* open; http, secure; https or both
|
|
43
|
+
*/
|
|
44
|
+
security?: DynamoNTS_RouteSecurity,
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* define basic Http Call Type such as; get, post, put, patch, delete
|
|
48
|
+
*/
|
|
49
|
+
type: DynamoNTS_HttpCallType,
|
|
50
|
+
/**
|
|
51
|
+
* set endpoint here, without baseUrl and route module path
|
|
52
|
+
*
|
|
53
|
+
* like: '/get-user/:userId'
|
|
54
|
+
*/
|
|
55
|
+
endpoint: string,
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* preProcesses are the functions you need to run before the actual function,
|
|
59
|
+
* such as authentications
|
|
60
|
+
*/
|
|
61
|
+
preProcesses?: ((req: Request, res: Response) => Promise<void>)[],
|
|
62
|
+
/**
|
|
63
|
+
* the actual tasks to run,
|
|
64
|
+
* the last one should contain the res.send(); execution to send response on API requests
|
|
65
|
+
*/
|
|
66
|
+
tasks: ((req: Request, res: Response, issuer?: string) => Promise<void>)[],
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* this flag will enable the debug logs on this endpoint
|
|
70
|
+
*/
|
|
71
|
+
logRequest?: boolean,
|
|
72
|
+
/**
|
|
73
|
+
* this flag will enable the debug logs on this endpoint's requests
|
|
74
|
+
*/
|
|
75
|
+
logRequestsParams?: boolean,
|
|
76
|
+
/**
|
|
77
|
+
* this flag will enable the debug logs on this endpoint's requests
|
|
78
|
+
*/
|
|
79
|
+
logRequestsContent?: boolean,
|
|
80
|
+
/**
|
|
81
|
+
* this flag will enable detailed debug logs on this endpoint's requests
|
|
82
|
+
*/
|
|
83
|
+
logResponseContent?: boolean,
|
|
84
|
+
}
|
|
85
|
+
) {
|
|
86
|
+
try {
|
|
87
|
+
this.name = set.name ?? set.endpoint;
|
|
88
|
+
this.security = set.security ?? DynamoNTS_globalSettings.defaultRouteSecurity;
|
|
89
|
+
|
|
90
|
+
this.type = set.type;
|
|
91
|
+
this.endpoint = set.endpoint;
|
|
92
|
+
|
|
93
|
+
if (!this.endpoint) {
|
|
94
|
+
throw new DynamoFM_Error({
|
|
95
|
+
status: 406,
|
|
96
|
+
errorCode: 'NTS-EP0-C00',
|
|
97
|
+
addECToUserMsg: true,
|
|
98
|
+
message: 'trying to create DynamoNTS_EndpointParams without endpoint value',
|
|
99
|
+
userMessage:
|
|
100
|
+
'We encountered an unhandled Server Error, ' +
|
|
101
|
+
'please contact the responsible development team.',
|
|
102
|
+
additionalContent: set,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
let pathParts: string[] = this.endpoint.split('/');
|
|
107
|
+
|
|
108
|
+
pathParts = pathParts.filter((part: string): boolean => part[0] === ':');
|
|
109
|
+
pathParts = pathParts.map((part: string): string => part.replace(':', ''));
|
|
110
|
+
this.pathParams = pathParts;
|
|
111
|
+
|
|
112
|
+
this.preProcesses = set.preProcesses ?? [];
|
|
113
|
+
this.tasks = set.tasks ?? [];
|
|
114
|
+
|
|
115
|
+
this.logRequest = set.logRequest ?? DynamoNTS_globalSettings.logRequest;
|
|
116
|
+
this.logRequestsParams = set.logRequestsParams ?? DynamoNTS_globalSettings.logRequestsParams;
|
|
117
|
+
this.logRequestsContent =
|
|
118
|
+
set.logRequestsContent ?? DynamoNTS_globalSettings.logRequestsContent;
|
|
119
|
+
this.logResponseContent =
|
|
120
|
+
set.logResponseContent ?? DynamoNTS_globalSettings.logResponseContent;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
DynamoFM_Log.error(
|
|
123
|
+
`\nEndpoint params setup failed: name: '${set.name}' ` +
|
|
124
|
+
`(security: ${set.security}) endpoint: ${set.endpoint}` +
|
|
125
|
+
`\nERROR:` +
|
|
126
|
+
`\n`, error
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
*
|
|
135
|
+
* @returns
|
|
136
|
+
*/
|
|
137
|
+
private async preLog(req: Request, res: Response, issuer: string): Promise<void> {
|
|
138
|
+
try {
|
|
139
|
+
if (this.logRequest) {
|
|
140
|
+
let msg: string = `\n===>>> incoming '${this.name}' request... (issuer: ${issuer})`;
|
|
141
|
+
|
|
142
|
+
if (this.logRequestsParams) {
|
|
143
|
+
const params = this.getPathParamsLogContent(req);
|
|
144
|
+
|
|
145
|
+
msg += `\npathParams: ${params}`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (this.logRequestsContent && req.body && 0 < Object.keys(req.body).length) {
|
|
149
|
+
DynamoFM_Log.info(msg + `\nbody:`, req.body);
|
|
150
|
+
} else {
|
|
151
|
+
DynamoFM_Log.info(msg);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
} catch (error) {
|
|
156
|
+
this.error(req, res, error, issuer);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
*
|
|
162
|
+
* @returns
|
|
163
|
+
*/
|
|
164
|
+
getFullExecution(): (req: Request, res: Response) => Promise<void> {
|
|
165
|
+
let issuer: string;
|
|
166
|
+
|
|
167
|
+
return async (req: Request, res: Response): Promise<void> => {
|
|
168
|
+
try {
|
|
169
|
+
issuer = DynamoNTS_GlobalService?.getAuthService()?.getIssuerFromRequest(req);
|
|
170
|
+
|
|
171
|
+
if (this.logRequest) {
|
|
172
|
+
await this.preLog(req, res, issuer);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
await DynamoFM_Array.asyncForEach(this.preProcesses,
|
|
176
|
+
async (preProcess: (req: Request, res: Response) => Promise<void>): Promise<void> => {
|
|
177
|
+
await preProcess(req, res);
|
|
178
|
+
}
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
await DynamoFM_Array.asyncForEach(this.tasks,
|
|
182
|
+
async (
|
|
183
|
+
task: (req: Request, res: Response, issuer?: string) => Promise<void>
|
|
184
|
+
): Promise<void> => {
|
|
185
|
+
await task(req, res, issuer);
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
if (this.logRequest) {
|
|
190
|
+
if (this.logResponseContent) {
|
|
191
|
+
DynamoFM_Log.success(` <<<===== '${this.name}' result sent.`);
|
|
192
|
+
DynamoFM_Log.warn('sorry, the logResponseContent is not implemented yet.');
|
|
193
|
+
} else {
|
|
194
|
+
DynamoFM_Log.success(` <<<===== '${this.name}' result sent.`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
} catch (error) {
|
|
198
|
+
this.error(req, res, error, issuer);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
*
|
|
205
|
+
* @param res
|
|
206
|
+
* @param error
|
|
207
|
+
*/
|
|
208
|
+
private async error(
|
|
209
|
+
req: Request,
|
|
210
|
+
res: Response,
|
|
211
|
+
error: Error | DynamoFM_Error,
|
|
212
|
+
issuer: string
|
|
213
|
+
): Promise<void> {
|
|
214
|
+
try {
|
|
215
|
+
let msg: string = `Endpoint catched an error. '${this.name}' (${this.endpoint})`;
|
|
216
|
+
|
|
217
|
+
msg += this.getPathParamsLogContent(req);
|
|
218
|
+
|
|
219
|
+
DynamoFM_Log.error(msg);
|
|
220
|
+
DynamoFM_Log.error(
|
|
221
|
+
'ERROR:',
|
|
222
|
+
(error as DynamoFM_Error)?.flag?.includes('DYNAMO') ?
|
|
223
|
+
(error as DynamoFM_Error).getErrorSimplified() :
|
|
224
|
+
error,
|
|
225
|
+
'\n'
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
if ((error as DynamoFM_Error)?.flag?.includes('DYNAMO')) {
|
|
229
|
+
if (!(error as DynamoFM_Error).additionalContent) {
|
|
230
|
+
(error as DynamoFM_Error).additionalContent = {};
|
|
231
|
+
}
|
|
232
|
+
(error as DynamoFM_Error).additionalContent.endpointInfo = msg;
|
|
233
|
+
DynamoFM_Log.error(`ErrorMessage: ${(error as DynamoFM_Error)._message}`);
|
|
234
|
+
DynamoFM_Log.error(`ErrorCode: ${(error as DynamoFM_Error)._errorCode}`);
|
|
235
|
+
DynamoFM_Log.error(`UserMessage: ${(error as DynamoFM_Error).__userMessage}`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
await DynamoNTS_GlobalService.globalErrorHandler?.(
|
|
239
|
+
error,
|
|
240
|
+
req,
|
|
241
|
+
res,
|
|
242
|
+
issuer
|
|
243
|
+
).catch((err): void => {
|
|
244
|
+
DynamoFM_Log.warn(
|
|
245
|
+
'DynamoNTS_GlobalService.globalErrorHandler failed to handle error: ',
|
|
246
|
+
err
|
|
247
|
+
);
|
|
248
|
+
DynamoFM_Log.warn('It will proceed as normal.');
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
if (
|
|
252
|
+
(error as DynamoFM_Error)?.flag?.includes('DYNAMO') &&
|
|
253
|
+
(error as DynamoFM_Error).confidentialContent
|
|
254
|
+
) {
|
|
255
|
+
delete (error as DynamoFM_Error).confidentialContent;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
res.status((error as DynamoFM_Error)?.___status ?? 501);
|
|
259
|
+
res.send(error);
|
|
260
|
+
|
|
261
|
+
if (this.logRequest) {
|
|
262
|
+
if (this.logResponseContent) {
|
|
263
|
+
DynamoFM_Log.error(
|
|
264
|
+
` <<<===== '${this.name}' error sent: ${(error as DynamoFM_Error)?._message ?? ''}`
|
|
265
|
+
);
|
|
266
|
+
DynamoFM_Log.error(
|
|
267
|
+
'sorry, the logResponseContent is not implemented yet.'
|
|
268
|
+
);
|
|
269
|
+
} else {
|
|
270
|
+
DynamoFM_Log.error(
|
|
271
|
+
` <<<===== '${this.name}' error sent: ${(error as DynamoFM_Error)?._message ?? ''}`
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
DynamoFM_Log.error('');
|
|
277
|
+
|
|
278
|
+
} catch (error) {
|
|
279
|
+
DynamoFM_Log.H_error(
|
|
280
|
+
`\n\nDYNAMO MULTILEVEL ERROR:DynamoNTS_EndpointParams: error: ` +
|
|
281
|
+
`(${this.name}, ${this.endpoint})` +
|
|
282
|
+
`\n(DYNAMO MULTILEVEL ERROR means, that the ERROR HANDLING is ALSO FAILED, ` +
|
|
283
|
+
`and the error message was not sent.)` +
|
|
284
|
+
`\nERROR:`, error,
|
|
285
|
+
'\n'
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
if (error?.flag?.includes?.('DYNAMO-ERROR-OBJECT')) {
|
|
289
|
+
DynamoFM_Log.error(`ErrorMessage: ${(error as DynamoFM_Error)._message}`);
|
|
290
|
+
DynamoFM_Log.error(`ErrorCode: ${(error as DynamoFM_Error)._errorCode}`);
|
|
291
|
+
DynamoFM_Log.error(`UserMessage: ${(error as DynamoFM_Error).__userMessage}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
private getPathParamsLogContent(req: Request): string {
|
|
297
|
+
let params: string = '';
|
|
298
|
+
|
|
299
|
+
this.pathParams.forEach((param: string): void => {
|
|
300
|
+
params += `\n${param}: ${req.params[param]}`;
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
return params;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
import * as BodyParser from 'body-parser';
|
|
3
|
-
export class DynamoNTS_Http_Settings {
|
|
4
|
-
httpPort?: number;
|
|
5
|
-
httpsPort?: number;
|
|
6
|
-
|
|
7
|
-
httpUrlencoded?: BodyParser.OptionsUrlencoded = {
|
|
8
|
-
limit: '50mb',
|
|
9
|
-
extended: true,
|
|
10
|
-
};
|
|
11
|
-
httpJson?: BodyParser.OptionsJson = {
|
|
12
|
-
limit: '50mb',
|
|
13
|
-
};
|
|
14
|
-
httpsUrlencoded?: BodyParser.OptionsUrlencoded = {
|
|
15
|
-
limit: '50mb',
|
|
16
|
-
extended: true,
|
|
17
|
-
};
|
|
18
|
-
httpsJson?: BodyParser.OptionsJson = {
|
|
19
|
-
limit: '50mb',
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
constructor(
|
|
23
|
-
set?: DynamoNTS_Http_Settings
|
|
24
|
-
) {
|
|
25
|
-
if (set) {
|
|
26
|
-
Object.assign(this, set);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
|
|
2
|
+
import * as BodyParser from 'body-parser';
|
|
3
|
+
export class DynamoNTS_Http_Settings {
|
|
4
|
+
httpPort?: number;
|
|
5
|
+
httpsPort?: number;
|
|
6
|
+
|
|
7
|
+
httpUrlencoded?: BodyParser.OptionsUrlencoded = {
|
|
8
|
+
limit: '50mb',
|
|
9
|
+
extended: true,
|
|
10
|
+
};
|
|
11
|
+
httpJson?: BodyParser.OptionsJson = {
|
|
12
|
+
limit: '50mb',
|
|
13
|
+
};
|
|
14
|
+
httpsUrlencoded?: BodyParser.OptionsUrlencoded = {
|
|
15
|
+
limit: '50mb',
|
|
16
|
+
extended: true,
|
|
17
|
+
};
|
|
18
|
+
httpsJson?: BodyParser.OptionsJson = {
|
|
19
|
+
limit: '50mb',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
set?: DynamoNTS_Http_Settings
|
|
24
|
+
) {
|
|
25
|
+
if (set) {
|
|
26
|
+
Object.assign(this, set);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|