@futdevpro/nts-dynamo 1.9.15 → 1.9.17

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 (132) hide show
  1. package/.copilot/patterns.json +7 -7
  2. package/.github/workflows/main.yml +221 -0
  3. package/HOWTO.md +15 -15
  4. package/README.md +140 -140
  5. package/build/_constants/mocks/auth-service.mock.d.ts.map +1 -1
  6. package/build/_models/control-models/app-params.control-model.d.ts +1 -0
  7. package/build/_models/control-models/app-params.control-model.d.ts.map +1 -1
  8. package/build/_models/control-models/app-params.control-model.js.map +1 -1
  9. package/build/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
  10. package/build/_models/control-models/endpoint-params.control-model.js +2 -0
  11. package/build/_models/control-models/endpoint-params.control-model.js.map +1 -1
  12. package/build/_models/control-models/socket-event.control-model.js +1 -1
  13. package/build/_models/interfaces/certification-settings.interface.d.ts +0 -1
  14. package/build/_models/interfaces/certification-settings.interface.d.ts.map +1 -1
  15. package/build/_models/interfaces/global-service-settings.interface.d.ts +1 -1
  16. package/build/_models/interfaces/global-service-settings.interface.d.ts.map +1 -1
  17. package/build/_modules/custom-data/get-custom-data-routing-module.util.js +1 -2
  18. package/build/_modules/custom-data/get-custom-data-routing-module.util.js.map +1 -1
  19. package/build/_modules/test/get-test-routing-module.util.js +1 -2
  20. package/build/_modules/test/get-test-routing-module.util.js.map +1 -1
  21. package/build/_modules/usage/get-usage-routing-module.util.js +1 -2
  22. package/build/_modules/usage/get-usage-routing-module.util.js.map +1 -1
  23. package/build/_services/core/global.service.d.ts.map +1 -1
  24. package/build/_services/core/global.service.js +14 -6
  25. package/build/_services/core/global.service.js.map +1 -1
  26. package/build/_services/route/routing-module.service.d.ts +1 -1
  27. package/build/_services/route/routing-module.service.d.ts.map +1 -1
  28. package/build/_services/route/routing-module.service.js +19 -25
  29. package/build/_services/route/routing-module.service.js.map +1 -1
  30. package/build/_services/server/app.server.d.ts +0 -2
  31. package/build/_services/server/app.server.d.ts.map +1 -1
  32. package/build/_services/server/app.server.js +4 -1
  33. package/build/_services/server/app.server.js.map +1 -1
  34. package/build/_services/socket/socket-client.service.d.ts.map +1 -1
  35. package/build/_services/socket/socket-client.service.js +1 -0
  36. package/build/_services/socket/socket-client.service.js.map +1 -1
  37. package/nodemon.json +17 -15
  38. package/package.json +5 -5
  39. package/src/_constants/global-settings.const.ts +27 -27
  40. package/src/_constants/index.ts +2 -2
  41. package/src/_constants/mocks/app-extended-server.mock.ts +198 -198
  42. package/src/_constants/mocks/app-params.mock.ts +9 -9
  43. package/src/_constants/mocks/app-server.mock.ts +185 -185
  44. package/src/_constants/mocks/auth-service.mock.ts +28 -28
  45. package/src/_constants/mocks/controller.mock.ts +16 -16
  46. package/src/_constants/mocks/data-model.mock.ts +83 -83
  47. package/src/_constants/mocks/email-service-collection.mock.ts +13 -13
  48. package/src/_constants/mocks/email-service.mock.ts +19 -19
  49. package/src/_constants/mocks/email-template.mock.html +14 -14
  50. package/src/_constants/mocks/endpoint.mock.ts +90 -90
  51. package/src/_constants/mocks/socket-client.mock.ts +43 -43
  52. package/src/_constants/mocks/socket-server.mock.ts +43 -43
  53. package/src/_enums/data-model-type.enum.ts +14 -14
  54. package/src/_enums/data-service-function.enum.ts +15 -15
  55. package/src/_enums/http/http-call-type.enum.ts +12 -12
  56. package/src/_enums/http/http-response-type.enum.ts +7 -7
  57. package/src/_enums/http/socket-event-type.enum.ts +18 -18
  58. package/src/_enums/index.ts +13 -13
  59. package/src/_enums/predefined-data-types.enum.ts +27 -27
  60. package/src/_enums/route-security.enum.ts +12 -12
  61. package/src/_enums/socket-security.enum.ts +11 -11
  62. package/src/_models/control-models/api-call-params.control-model.ts +126 -126
  63. package/src/_models/control-models/app-ext-system-controls.control-model.ts +9 -9
  64. package/src/_models/control-models/app-params.control-model.ts +46 -45
  65. package/src/_models/control-models/app-system-controls.control-model.ts +9 -9
  66. package/src/_models/control-models/endpoint-params.control-model.ts +309 -307
  67. package/src/_models/control-models/http-settings.control-model.ts +29 -29
  68. package/src/_models/control-models/index.ts +13 -13
  69. package/src/_models/control-models/socket-client-service-params.control-model.ts +28 -28
  70. package/src/_models/control-models/socket-event.control-model.ts +150 -150
  71. package/src/_models/control-models/socket-presence.control-model.ts +207 -207
  72. package/src/_models/control-models/socket-server-service-params.control-model.ts +20 -20
  73. package/src/_models/control-models/system-control.control-model.ts +12 -12
  74. package/src/_models/index.ts +9 -9
  75. package/src/_models/interfaces/certification-settings.interface.ts +7 -7
  76. package/src/_models/interfaces/global-service-settings.interface.ts +45 -45
  77. package/src/_models/interfaces/global-settings.interface.ts +83 -83
  78. package/src/_models/interfaces/index.ts +7 -7
  79. package/src/_models/interfaces/routing-module-settings.interface.ts +20 -20
  80. package/src/_models/types/db-filter.type.ts +108 -108
  81. package/src/_models/types/db-update.type.ts +100 -100
  82. package/src/_models/types/index.ts +5 -5
  83. package/src/_modules/api-service.index.ts +12 -12
  84. package/src/_modules/app-extended.index.ts +28 -28
  85. package/src/_modules/app.index.ts +24 -24
  86. package/src/_modules/auth.index.ts +7 -7
  87. package/src/_modules/constants.index.ts +2 -2
  88. package/src/_modules/controller.index.ts +10 -10
  89. package/src/_modules/custom-data/custom-data.controller.ts +69 -69
  90. package/src/_modules/custom-data/custom-data.data-service.ts +20 -20
  91. package/src/_modules/custom-data/get-custom-data-routing-module.util.ts +23 -23
  92. package/src/_modules/custom-data/index.ts +6 -6
  93. package/src/_modules/custom-data-module.index.ts +2 -2
  94. package/src/_modules/data-service.index.ts +9 -9
  95. package/src/_modules/email.index.ts +8 -8
  96. package/src/_modules/enums.index.ts +2 -2
  97. package/src/_modules/extended.index.ts +8 -8
  98. package/src/_modules/models.index.ts +2 -2
  99. package/src/_modules/services.index.ts +2 -2
  100. package/src/_modules/test/get-test-routing-module.util.ts +23 -23
  101. package/src/_modules/test/index.ts +5 -5
  102. package/src/_modules/test/test.controller.ts +115 -115
  103. package/src/_modules/test-module.index.ts +2 -2
  104. package/src/_modules/usage/get-usage-routing-module.util.ts +22 -22
  105. package/src/_modules/usage/index.ts +7 -7
  106. package/src/_modules/usage/usage.controller.ts +120 -120
  107. package/src/_modules/usage/usage.data-service.ts +172 -172
  108. package/src/_modules/usage-module.index.ts +2 -2
  109. package/src/_services/base/data.service.ts +921 -921
  110. package/src/_services/base/db.service.spec.ts +32 -32
  111. package/src/_services/base/db.service.ts +1063 -1063
  112. package/src/_services/base/singleton.service.ts +21 -21
  113. package/src/_services/core/api.service.ts +453 -453
  114. package/src/_services/core/auth.service.ts +172 -172
  115. package/src/_services/core/email.service.ts +678 -678
  116. package/src/_services/core/global.service.ts +275 -269
  117. package/src/_services/core/service-collection.service.ts +5 -5
  118. package/src/_services/index.ts +23 -23
  119. package/src/_services/route/controller.service.ts +129 -129
  120. package/src/_services/route/routing-module.service.ts +293 -273
  121. package/src/_services/server/app-extended.server.spec.ts +76 -76
  122. package/src/_services/server/app-extended.server.ts +520 -520
  123. package/src/_services/server/app.server.spec.ts +67 -67
  124. package/src/_services/server/app.server.ts +1181 -1179
  125. package/src/_services/shared.service.spec.ts +19 -19
  126. package/src/_services/shared.static-service.ts +73 -73
  127. package/src/_services/socket/socket-client.service.ts +236 -235
  128. package/src/_services/socket/socket-server.service.spec.ts +11 -11
  129. package/src/_services/socket/socket-server.service.ts +761 -761
  130. package/src/index.ts +18 -18
  131. package/tsconfig.json +41 -41
  132. 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
- await DynamoNTS_GlobalService.globalErrorHandler?.(
238
- error,
239
- req,
240
- res,
241
- issuer
242
- ).catch((err): void => {
243
- DynamoFM_Log.warn(
244
- 'DynamoNTS_GlobalService.globalErrorHandler failed to handle error: ',
245
- err
246
- );
247
- DynamoFM_Log.warn('It will proceed as normal.');
248
- });
249
-
250
- if (
251
- (error as DynamoFM_Error)?.flag?.includes('DYNAMO') &&
252
- (error as DynamoFM_Error).confidentialContent
253
- ) {
254
- delete (error as DynamoFM_Error).confidentialContent;
255
- }
256
-
257
- res.status((error as DynamoFM_Error)?.___status ?? 501);
258
- res.send(error);
259
-
260
- if (this.logRequest) {
261
- if (this.logResponseContent) {
262
- DynamoFM_Log.error(
263
- ` <<<===== '${this.name}' error sent: ${(error as DynamoFM_Error)?._message ?? ''}`
264
- );
265
- DynamoFM_Log.error(
266
- 'sorry, the logResponseContent is not implemented yet.'
267
- );
268
- } else {
269
- DynamoFM_Log.error(
270
- ` <<<===== '${this.name}' error sent: ${(error as DynamoFM_Error)?._message ?? ''}`
271
- );
272
- }
273
- }
274
-
275
- DynamoFM_Log.error('');
276
-
277
- } catch (error) {
278
- DynamoFM_Log.H_error(
279
- `\n\nDYNAMO MULTILEVEL ERROR:DynamoNTS_EndpointParams: error: ` +
280
- `(${this.name}, ${this.endpoint})` +
281
- `\n(DYNAMO MULTILEVEL ERROR means, that the ERROR HANDLING is ALSO FAILED, ` +
282
- `and the error message was not sent.)` +
283
- `\nERROR:`, error,
284
- '\n'
285
- );
286
-
287
- if (error?.flag?.includes?.('DYNAMO-ERROR-OBJECT')) {
288
- DynamoFM_Log.error(`ErrorMessage: ${(error as DynamoFM_Error)._message}`);
289
- DynamoFM_Log.error(`ErrorCode: ${(error as DynamoFM_Error)._errorCode}`);
290
- }
291
- }
292
- }
293
-
294
- private getPathParamsLogContent(req: Request): string {
295
- let params: string = '';
296
-
297
- this.pathParams.forEach((param: string): void => {
298
- params += `\n${param}: ${req.params[param]}`;
299
- });
300
-
301
- return params;
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
+ }