@futdevpro/nts-dynamo 1.6.27 → 1.6.29

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 (31) hide show
  1. package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -1
  2. package/lib/_constants/mocks/app-extended-server.mock.js +3 -0
  3. package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -1
  4. package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
  5. package/lib/_constants/mocks/app-server.mock.js +2 -0
  6. package/lib/_constants/mocks/app-server.mock.js.map +1 -1
  7. package/lib/_constants/mocks/auth-service.mock.d.ts +4 -4
  8. package/lib/_constants/mocks/auth-service.mock.d.ts.map +1 -1
  9. package/lib/_constants/mocks/auth-service.mock.js +7 -13
  10. package/lib/_constants/mocks/auth-service.mock.js.map +1 -1
  11. package/lib/_models/control-models/endpoint-params.control-model.d.ts +11 -13
  12. package/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
  13. package/lib/_models/control-models/endpoint-params.control-model.js +15 -29
  14. package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
  15. package/lib/_services/core/auth.service.d.ts +4 -4
  16. package/lib/_services/core/auth.service.d.ts.map +1 -1
  17. package/lib/_services/route/routing-module.service.d.ts.map +1 -1
  18. package/lib/_services/route/routing-module.service.js +10 -10
  19. package/lib/_services/route/routing-module.service.js.map +1 -1
  20. package/lib/_services/server/app.server.d.ts.map +1 -1
  21. package/lib/_services/server/app.server.js +2 -2
  22. package/lib/_services/server/app.server.js.map +1 -1
  23. package/lib/tsconfig.tsbuildinfo +1 -1
  24. package/package.json +1 -1
  25. package/src/_constants/mocks/app-extended-server.mock.ts +3 -0
  26. package/src/_constants/mocks/app-server.mock.ts +2 -0
  27. package/src/_constants/mocks/auth-service.mock.ts +4 -10
  28. package/src/_models/control-models/endpoint-params.control-model.ts +47 -61
  29. package/src/_services/core/auth.service.ts +3 -3
  30. package/src/_services/route/routing-module.service.ts +10 -25
  31. package/src/_services/server/app.server.ts +3 -4
@@ -19,6 +19,7 @@ import { SocketClient_Mock } from './socket-client.mock';
19
19
  import { dependency_mock_DataParams, dependent_mock_DataParams } from './data-model.mock';
20
20
  import { dynamo_error_default } from '@futdevpro/fsm-dynamo';
21
21
  import { EmailServiceCollection_Mock } from './email-service-collection.mock';
22
+ import { getCustomDataRoutingModule } from '../../_modules/custom-data';
22
23
 
23
24
  /**
24
25
  *
@@ -104,6 +105,7 @@ export class DynamoNTS_AppExtendedFull_Mock extends DynamoNTS_AppExtended {
104
105
  }),
105
106
 
106
107
  getTestRoutingModule(),
108
+ getCustomDataRoutingModule(),
107
109
  getUsageRoutingModule(),
108
110
  ];
109
111
  }
@@ -173,6 +175,7 @@ export class DynamoNTS_AppWbMock_Mock extends DynamoNTS_AppExtended {
173
175
  }),
174
176
 
175
177
  getTestRoutingModule(),
178
+ getCustomDataRoutingModule(),
176
179
  getUsageRoutingModule(),
177
180
  ];
178
181
  }
@@ -15,6 +15,7 @@ import { DynamoNTS_Controller_Mock } from './controller.mock';
15
15
  import { AuthService_Mock } from './auth-service.mock';
16
16
  import { dynamoNTS_globalSettings } from '../global-settings.const';
17
17
  import { dependency_mock_DataParams, dependent_mock_DataParams } from './data-model.mock';
18
+ import { getCustomDataRoutingModule } from '../../_modules/custom-data';
18
19
 
19
20
  /**
20
21
  *
@@ -95,6 +96,7 @@ export class DynamoNTS_AppFull_Mock extends DynamoNTS_App {
95
96
  }),
96
97
 
97
98
  getTestRoutingModule(),
99
+ getCustomDataRoutingModule(),
98
100
  getUsageRoutingModule(),
99
101
  ];
100
102
  }
@@ -10,13 +10,11 @@ export class AuthService_Mock extends DynamoNTS_AuthService {
10
10
  return AuthService_Mock.getSingletonInstance();
11
11
  }
12
12
 
13
- async authenticateToken(req: Request, res: Response, next: NextFunction): Promise<void> {
14
- next();
15
- }
13
+ async authenticateToken(req: Request, res: Response): Promise<void> {}
16
14
 
17
- async authenticateTokenSelf(req: Request, res: Response, next: NextFunction): Promise<void> {
18
- next();
19
- }
15
+ async authenticateTokenSelf(req: Request, res: Response): Promise<void> {}
16
+
17
+ async authTokenPermAccUsageData(req: Request, res: Response): Promise<void> {}
20
18
 
21
19
  getAccountIdFromRequest(req: Request): string {
22
20
  return 'accountId_mock';
@@ -26,9 +24,5 @@ export class AuthService_Mock extends DynamoNTS_AuthService {
26
24
  return 'username_mock';
27
25
  }
28
26
 
29
- async authTokenPermAccUsageData(req: Request, res: Response, next: NextFunction): Promise<void> {
30
- next();
31
- }
32
-
33
27
  }
34
28
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { NextFunction, Request, Response } from 'express';
4
4
 
5
- import { Dynamo_Error, Dynamo_Log } from '@futdevpro/fsm-dynamo';
5
+ import { Dynamo_Array, Dynamo_Error, Dynamo_Log } from '@futdevpro/fsm-dynamo';
6
6
  import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
7
7
  import { DynamoNTS_HttpCallType } from '../../_enums/http/http-call-type.enum';
8
8
  import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
@@ -20,14 +20,14 @@ export class DynamoNTS_EndpointParams{
20
20
  type: DynamoNTS_HttpCallType;
21
21
  endpoint: string;
22
22
 
23
- pathParams: string[];
23
+ private pathParams: string[];
24
24
 
25
- preProcessess: ((req: Request, res: Response, next: NextFunction) => Promise<void>)[]
26
- tasks: ((req: Request, res: Response, issuer?: string) => Promise<void>)[];
25
+ private preProcessess: ((req: Request, res: Response) => Promise<void>)[]
26
+ private tasks: ((req: Request, res: Response, issuer?: string) => Promise<void>)[];
27
27
 
28
- logRequest: boolean;
29
- logRequestsContent: boolean;
30
- logResponseContent: boolean;
28
+ private logRequest: boolean;
29
+ private logRequestsContent: boolean;
30
+ private logResponseContent: boolean;
31
31
 
32
32
  constructor(
33
33
  set: {
@@ -57,7 +57,7 @@ export class DynamoNTS_EndpointParams{
57
57
  * preprocesses are the functions you need to run before the actual function,
58
58
  * such as authentications
59
59
  */
60
- preProcessess?: ((req: Request, res: Response, next: NextFunction) => Promise<void>)[],
60
+ preProcessess?: ((req: Request, res: Response) => Promise<void>)[],
61
61
  /**
62
62
  * the actual tasks to run,
63
63
  * the last one should contain the res.send(); execution to send response on API requests
@@ -107,9 +107,9 @@ export class DynamoNTS_EndpointParams{
107
107
  this.logRequestsContent = set.logRequestsContent ?? dynamoNTS_globalSettings.logRequestsContent;
108
108
  this.logResponseContent = set.logResponseContent ?? dynamoNTS_globalSettings.logResponseContent;
109
109
 
110
- if (this.logRequest) {
110
+ /* if (this.logRequest) {
111
111
  this.preProcessess.unshift(this.getPreLog());
112
- }
112
+ } */
113
113
  } catch (error) {
114
114
  Dynamo_Log.error(
115
115
  `\nEndpoint params setup failed: name: '${set.name}' (security: ${set.security}) endpoint: ${set.endpoint}\nERROR:\n`, error);
@@ -121,71 +121,57 @@ export class DynamoNTS_EndpointParams{
121
121
  *
122
122
  * @returns
123
123
  */
124
- getPreLog(): (req: Request, res: Response, next: NextFunction) => Promise<void> {
125
- return async (req: Request, res: Response, next: NextFunction) => {
126
- try {
127
- if (this.logRequest) {
128
- if (this.logRequestsContent) {
129
- let inputs = '';
130
- for(let i = 0; i < this.pathParams.length; i++) {
131
- inputs += ` ${this.pathParams[i]}: ${req.params[this.pathParams[i]]}`;
132
- if (i + 1 < this.pathParams.length || req.body && `${req.body}` !== '{}') {
133
- inputs += ',';
134
- }
135
- }
136
-
137
- if (req.body && 0 < Object.keys(req.body).length) {
138
- console.log(`==> incoming ${this.name} request...${inputs} body:`, req.body);
139
- } else {
140
- console.log(`==> incoming ${this.name} request...${inputs}`);
124
+ private async preLog(req: Request, res: Response): Promise<void> {
125
+ try {
126
+ if (this.logRequest) {
127
+ if (this.logRequestsContent) {
128
+ let inputs = '';
129
+ for(let i = 0; i < this.pathParams.length; i++) {
130
+ inputs += ` ${this.pathParams[i]}: ${req.params[this.pathParams[i]]}`;
131
+ if (i + 1 < this.pathParams.length || req.body && `${req.body}` !== '{}') {
132
+ inputs += ',';
141
133
  }
142
- } else {
143
- console.log(`==> incoming ${this.name} request...`);
144
134
  }
145
- }
146
135
 
147
- next();
148
- } catch (error) {
149
- this.error(res, error);
150
- }
151
- };
152
- }
153
-
154
- getPreProcessExecution(): ((req: Request, res: Response, next: NextFunction) => Promise<void>)[] {
155
- return this.preProcessess.map(
156
- (
157
- preProcess: (req: Request, res: Response, next: NextFunction) => Promise<void>
158
- ) => async (req: Request, res: Response, next: NextFunction) => {
159
- try {
160
- await preProcess(req, res, next)
161
-
162
- if (this.logRequest) {
163
- if (this.logResponseContent) {
164
- Dynamo_Log.success(` <<<===== ${this.name} result sent.`);
165
- Dynamo_Log.warn('sorry, the logResponseContent is not implemented yet.');
166
- } else {
167
- Dynamo_Log.success(` <<<===== ${this.name} result sent.`);
168
- }
136
+ if (req.body && 0 < Object.keys(req.body).length) {
137
+ console.log(`==> incoming ${this.name} request...${inputs} body:`, req.body);
138
+ } else {
139
+ console.log(`==> incoming ${this.name} request...${inputs}`);
169
140
  }
170
- } catch (error) {
171
- this.error(res, error);
141
+ } else {
142
+ console.log(`==> incoming ${this.name} request...`);
172
143
  }
173
144
  }
174
- );
145
+
146
+ } catch (error) {
147
+ this.error(res, error);
148
+ }
175
149
  }
176
150
 
177
151
  /**
178
152
  *
179
153
  * @returns
180
154
  */
181
- getTasksExecution(): (req: Request, res: Response) => Promise<void> {
155
+ getFullExecution(): (req: Request, res: Response) => Promise<void> {
182
156
  return async (req: Request, res: Response) => {
183
- try {
157
+ try {
158
+ if (this.logRequest) {
159
+ await this.preLog(req, res);
160
+ }
161
+
162
+ await Dynamo_Array.asyncForEach(this.preProcessess,
163
+ async (preProcess: (req: Request, res: Response) => Promise<void>) => {
164
+ await preProcess(req, res);
165
+ }
166
+ );
167
+
184
168
  const issuer: string = DynamoNTS_GlobalService?.getAuthService()?.getAccountIdFromRequest(req);
185
169
 
186
- for (let i = 0; i < this.tasks.length; i++) {
187
- await this.tasks[i](req, res, issuer);
188
- }
170
+ await Dynamo_Array.asyncForEach(this.tasks,
171
+ async (task: (req: Request, res: Response, issuer?: string) => Promise<void>) => {
172
+ await task(req, res, issuer);
173
+ }
174
+ );
189
175
 
190
176
  if (this.logRequest) {
191
177
  if (this.logResponseContent) {
@@ -206,7 +192,7 @@ export class DynamoNTS_EndpointParams{
206
192
  * @param res
207
193
  * @param error
208
194
  */
209
- error(res: Response, error: Error | Dynamo_Error): void {
195
+ private error(res: Response, error: Error | Dynamo_Error): void {
210
196
  try {
211
197
 
212
198
  Dynamo_Log.error(
@@ -90,7 +90,7 @@ export abstract class DynamoNTS_AuthService extends DynamoNTS_SingletonService {
90
90
  * }
91
91
  * }
92
92
  * */
93
- abstract authenticateToken(req: Request, res: Response, next: NextFunction): Promise<void>;
93
+ abstract authenticateToken(req: Request, res: Response): Promise<void>;
94
94
 
95
95
  /**
96
96
  * You need to implement a token validation logic,
@@ -126,7 +126,7 @@ export abstract class DynamoNTS_AuthService extends DynamoNTS_SingletonService {
126
126
  * }
127
127
  *
128
128
  */
129
- abstract authenticateTokenSelf(req: Request, res: Response, next: NextFunction): Promise<void>;
129
+ abstract authenticateTokenSelf(req: Request, res: Response): Promise<void>;
130
130
 
131
131
  /**
132
132
  * Authenticate Token for Permission to Access UsageData
@@ -142,7 +142,7 @@ export abstract class DynamoNTS_AuthService extends DynamoNTS_SingletonService {
142
142
  * AuthService.authTokenAndPerm(req, res, next, Permission.accessUsageData);
143
143
  * }
144
144
  */
145
- abstract authTokenPermAccUsageData(req: Request, res: Response, next: NextFunction): Promise<void>;
145
+ abstract authTokenPermAccUsageData(req: Request, res: Response): Promise<void>;
146
146
 
147
147
  /**
148
148
  * The DynamoBE System is using this to get issuer, that will be set on DBServices
@@ -160,33 +160,23 @@ export class DynamoNTS_RoutingModule {
160
160
  switch(endpointParams.type) {
161
161
 
162
162
  case DynamoNTS_HttpCallType.get:
163
- this.openRouter.get(endpointParams.endpoint,
164
- endpointParams.preProcessess, endpointParams.getTasksExecution()
165
- );
163
+ this.openRouter.get(endpointParams.endpoint, endpointParams.getFullExecution());
166
164
  break;
167
165
 
168
166
  case DynamoNTS_HttpCallType.post:
169
- this.openRouter.post(endpointParams.endpoint,
170
- endpointParams.preProcessess, endpointParams.getTasksExecution()
171
- );
167
+ this.openRouter.post(endpointParams.endpoint, endpointParams.getFullExecution());
172
168
  break;
173
169
 
174
170
  case DynamoNTS_HttpCallType.put:
175
- this.openRouter.put(endpointParams.endpoint,
176
- endpointParams.preProcessess, endpointParams.getTasksExecution()
177
- );
171
+ this.openRouter.put(endpointParams.endpoint, endpointParams.getFullExecution());
178
172
  break;
179
173
 
180
174
  case DynamoNTS_HttpCallType.patch:
181
- this.openRouter.patch(endpointParams.endpoint,
182
- endpointParams.preProcessess, endpointParams.getTasksExecution()
183
- );
175
+ this.openRouter.patch(endpointParams.endpoint, endpointParams.getFullExecution());
184
176
  break;
185
177
 
186
178
  case DynamoNTS_HttpCallType.delete:
187
- this.openRouter.delete(endpointParams.endpoint,
188
- endpointParams.preProcessess, endpointParams.getTasksExecution()
189
- );
179
+ this.openRouter.delete(endpointParams.endpoint, endpointParams.getFullExecution());
190
180
  break;
191
181
 
192
182
  default:
@@ -209,28 +199,23 @@ export class DynamoNTS_RoutingModule {
209
199
  private mountSecureRoute(endpointParams: DynamoNTS_EndpointParams): void {
210
200
  switch(endpointParams.type) {
211
201
  case DynamoNTS_HttpCallType.get:
212
- this.secureRouter.get(endpointParams.endpoint,
213
- endpointParams.preProcessess, endpointParams.getTasksExecution());
202
+ this.secureRouter.get(endpointParams.endpoint, endpointParams.getFullExecution());
214
203
  break;
215
204
 
216
205
  case DynamoNTS_HttpCallType.post:
217
- this.secureRouter.post(endpointParams.endpoint,
218
- endpointParams.preProcessess, endpointParams.getTasksExecution());
206
+ this.secureRouter.post(endpointParams.endpoint, endpointParams.getFullExecution());
219
207
  break;
220
208
 
221
209
  case DynamoNTS_HttpCallType.put:
222
- this.secureRouter.put(endpointParams.endpoint,
223
- endpointParams.preProcessess, endpointParams.getTasksExecution());
210
+ this.secureRouter.put(endpointParams.endpoint, endpointParams.getFullExecution());
224
211
  break;
225
212
 
226
213
  case DynamoNTS_HttpCallType.patch:
227
- this.secureRouter.patch(endpointParams.endpoint,
228
- endpointParams.preProcessess, endpointParams.getTasksExecution());
214
+ this.secureRouter.patch(endpointParams.endpoint, endpointParams.getFullExecution());
229
215
  break;
230
216
 
231
217
  case DynamoNTS_HttpCallType.delete:
232
- this.secureRouter.delete(endpointParams.endpoint,
233
- endpointParams.preProcessess, endpointParams.getTasksExecution());
218
+ this.secureRouter.delete(endpointParams.endpoint, endpointParams.getFullExecution());
234
219
  break;
235
220
 
236
221
  default:
@@ -6,7 +6,7 @@ import * as Https from 'https';
6
6
  import * as FileSystem from 'fs';
7
7
  import * as BodyParser from 'body-parser';
8
8
 
9
- import { delay, Dynamo_Array, Dynamo_Error, Dynamo_Log, second, wait } from '@futdevpro/fsm-dynamo';
9
+ import { Dynamo_Array, Dynamo_Error, Dynamo_Log, second, wait } from '@futdevpro/fsm-dynamo';
10
10
 
11
11
  import { DynamoNTS_SingletonService } from '../base/singleton.service';
12
12
  import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
@@ -18,7 +18,6 @@ import { DynamoNTS_GlobalServiceSettings } from '../../_models/interfaces/global
18
18
  import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
19
19
  import { DynamoNTS_AppParams } from '../../_models/control-models/app-params.control-model';
20
20
  import { DynamoNTS_EndpointParams } from '../../_models/control-models/endpoint-params.control-model';
21
- import { DynamoNTS_SystemControl } from '../../_models/control-models/system-control.control-model';
22
21
  import { DynamoNTS_AppSystemControls } from '../../_models/control-models/app-system-controls.control-model';
23
22
 
24
23
 
@@ -607,7 +606,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
607
606
  this.httpsServer
608
607
  .listen(this._ports.httpsPort, 'localhost', 0, () => {
609
608
  this.systemControls.httpsServer.started = true;
610
- Dynamo_Log.success(`\nHTTPS (secure) server is listening on port ${this._ports.httpsPort}`);
609
+ Dynamo_Log.success(`\nHTTPS (secure) server is listening on port: ${this._ports.httpsPort}`);
611
610
  resolve();
612
611
  })
613
612
  .on('error', (error) => {
@@ -641,7 +640,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
641
640
  this.httpServer = this.openExpress
642
641
  .listen(this._ports.httpPort, () => {
643
642
  this.systemControls.httpServer.started = true;
644
- Dynamo_Log.success(`\nHTTP (open) server is listening on port ${this._ports.httpPort}`);
643
+ Dynamo_Log.success(`\nHTTP (open) server is listening on port: ${this._ports.httpPort}`);
645
644
  resolve();
646
645
  })
647
646
  .on('error', (error) => {