@futdevpro/nts-dynamo 1.6.28 → 1.6.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/app-extended-server.mock.js +3 -0
- package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -1
- package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/app-server.mock.js +2 -0
- package/lib/_constants/mocks/app-server.mock.js.map +1 -1
- package/lib/_constants/mocks/auth-service.mock.d.ts +4 -4
- package/lib/_constants/mocks/auth-service.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/auth-service.mock.js +7 -13
- package/lib/_constants/mocks/auth-service.mock.js.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.d.ts +9 -11
- package/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +31 -42
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_services/core/auth.service.d.ts +4 -4
- package/lib/_services/core/auth.service.d.ts.map +1 -1
- package/lib/_services/route/routing-module.service.d.ts.map +1 -1
- package/lib/_services/route/routing-module.service.js +10 -10
- package/lib/_services/route/routing-module.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/_constants/mocks/app-extended-server.mock.ts +3 -0
- package/src/_constants/mocks/app-server.mock.ts +2 -0
- package/src/_constants/mocks/auth-service.mock.ts +4 -10
- package/src/_models/control-models/endpoint-params.control-model.ts +59 -74
- package/src/_services/core/auth.service.ts +3 -3
- package/src/_services/route/routing-module.service.ts +10 -25
|
@@ -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
|
|
14
|
-
next();
|
|
15
|
-
}
|
|
13
|
+
async authenticateToken(req: Request, res: Response): Promise<void> {}
|
|
16
14
|
|
|
17
|
-
async authenticateTokenSelf(req: Request, res: Response
|
|
18
|
-
|
|
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
|
-
private preProcessess: ((req: Request, res: Response
|
|
25
|
+
private preProcessess: ((req: Request, res: Response) => Promise<void>)[]
|
|
26
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
|
|
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
|
|
@@ -106,10 +106,6 @@ export class DynamoNTS_EndpointParams{
|
|
|
106
106
|
this.logRequest = set.logRequest ?? dynamoNTS_globalSettings.logRequest;
|
|
107
107
|
this.logRequestsContent = set.logRequestsContent ?? dynamoNTS_globalSettings.logRequestsContent;
|
|
108
108
|
this.logResponseContent = set.logResponseContent ?? dynamoNTS_globalSettings.logResponseContent;
|
|
109
|
-
|
|
110
|
-
if (this.logRequest) {
|
|
111
|
-
this.preProcessess.unshift(this.getPreLog());
|
|
112
|
-
}
|
|
113
109
|
} catch (error) {
|
|
114
110
|
Dynamo_Log.error(
|
|
115
111
|
`\nEndpoint params setup failed: name: '${set.name}' (security: ${set.security}) endpoint: ${set.endpoint}\nERROR:\n`, error);
|
|
@@ -121,71 +117,57 @@ export class DynamoNTS_EndpointParams{
|
|
|
121
117
|
*
|
|
122
118
|
* @returns
|
|
123
119
|
*/
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (this.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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}`);
|
|
120
|
+
private async preLog(req: Request, res: Response): Promise<void> {
|
|
121
|
+
try {
|
|
122
|
+
if (this.logRequest) {
|
|
123
|
+
if (this.logRequestsContent) {
|
|
124
|
+
let inputs = '';
|
|
125
|
+
for(let i = 0; i < this.pathParams.length; i++) {
|
|
126
|
+
inputs += ` ${this.pathParams[i]}: ${req.params[this.pathParams[i]]}`;
|
|
127
|
+
if (i + 1 < this.pathParams.length || req.body && `${req.body}` !== '{}') {
|
|
128
|
+
inputs += ',';
|
|
141
129
|
}
|
|
142
|
-
} else {
|
|
143
|
-
console.log(`==> incoming ${this.name} request...`);
|
|
144
130
|
}
|
|
145
|
-
}
|
|
146
131
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
getPreProcessExecutions(): ((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
|
-
}
|
|
132
|
+
if (req.body && 0 < Object.keys(req.body).length) {
|
|
133
|
+
console.log(`==> incoming ${this.name} request...${inputs} body:`, req.body);
|
|
134
|
+
} else {
|
|
135
|
+
console.log(`==> incoming ${this.name} request...${inputs}`);
|
|
169
136
|
}
|
|
170
|
-
}
|
|
171
|
-
|
|
137
|
+
} else {
|
|
138
|
+
console.log(`==> incoming ${this.name} request...`);
|
|
172
139
|
}
|
|
173
140
|
}
|
|
174
|
-
|
|
141
|
+
|
|
142
|
+
} catch (error) {
|
|
143
|
+
this.error(req, res, error);
|
|
144
|
+
}
|
|
175
145
|
}
|
|
176
146
|
|
|
177
147
|
/**
|
|
178
148
|
*
|
|
179
149
|
* @returns
|
|
180
150
|
*/
|
|
181
|
-
|
|
151
|
+
getFullExecution(): (req: Request, res: Response) => Promise<void> {
|
|
182
152
|
return async (req: Request, res: Response) => {
|
|
183
|
-
try {
|
|
153
|
+
try {
|
|
154
|
+
if (this.logRequest) {
|
|
155
|
+
await this.preLog(req, res);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
await Dynamo_Array.asyncForEach(this.preProcessess,
|
|
159
|
+
async (preProcess: (req: Request, res: Response) => Promise<void>) => {
|
|
160
|
+
await preProcess(req, res);
|
|
161
|
+
}
|
|
162
|
+
);
|
|
163
|
+
|
|
184
164
|
const issuer: string = DynamoNTS_GlobalService?.getAuthService()?.getAccountIdFromRequest(req);
|
|
185
165
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
166
|
+
await Dynamo_Array.asyncForEach(this.tasks,
|
|
167
|
+
async (task: (req: Request, res: Response, issuer?: string) => Promise<void>) => {
|
|
168
|
+
await task(req, res, issuer);
|
|
169
|
+
}
|
|
170
|
+
);
|
|
189
171
|
|
|
190
172
|
if (this.logRequest) {
|
|
191
173
|
if (this.logResponseContent) {
|
|
@@ -196,7 +178,7 @@ export class DynamoNTS_EndpointParams{
|
|
|
196
178
|
}
|
|
197
179
|
}
|
|
198
180
|
} catch (error) {
|
|
199
|
-
this.error(res, error);
|
|
181
|
+
this.error(req, res, error);
|
|
200
182
|
}
|
|
201
183
|
};
|
|
202
184
|
}
|
|
@@ -206,17 +188,20 @@ export class DynamoNTS_EndpointParams{
|
|
|
206
188
|
* @param res
|
|
207
189
|
* @param error
|
|
208
190
|
*/
|
|
209
|
-
error(res: Response, error: Error | Dynamo_Error): void {
|
|
191
|
+
private error(req: Request, res: Response, error: Error | Dynamo_Error): void {
|
|
210
192
|
try {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
193
|
+
let msg = `Endpoint catched an error. ${this.name} (${this.endpoint})` +
|
|
194
|
+
this.pathParams.forEach((param: string) => {
|
|
195
|
+
msg += `\n${param}: ${req.params[param]}`;
|
|
196
|
+
});
|
|
197
|
+
msg += `\nERROR:`;
|
|
198
|
+
|
|
199
|
+
Dynamo_Log.error(msg);
|
|
200
|
+
console.log((error as Dynamo_Error)?.flag.includes('DYNAMO') ? (error as Dynamo_Error).getErrorSimplified() : error, '\n');
|
|
201
|
+
if (this.logRequest) {
|
|
202
|
+
Dynamo_Log.error('body');
|
|
203
|
+
console.log(req.body, '\n');
|
|
204
|
+
}
|
|
220
205
|
|
|
221
206
|
res.status((error as Dynamo_Error)?.___status ?? 501);
|
|
222
207
|
res.send(error);
|
|
@@ -225,7 +210,7 @@ export class DynamoNTS_EndpointParams{
|
|
|
225
210
|
if (this.logResponseContent) {
|
|
226
211
|
Dynamo_Log.error(
|
|
227
212
|
` <<<===== ${this.name} error sent.` +
|
|
228
|
-
(error as Dynamo_Error)?.
|
|
213
|
+
(error as Dynamo_Error)?._message ?? ''
|
|
229
214
|
);
|
|
230
215
|
Dynamo_Log.error(
|
|
231
216
|
'sorry, the logResponseContent is not implemented yet.'
|
|
@@ -233,7 +218,7 @@ export class DynamoNTS_EndpointParams{
|
|
|
233
218
|
} else {
|
|
234
219
|
Dynamo_Log.error(
|
|
235
220
|
` <<<===== ${this.name} error sent.` +
|
|
236
|
-
(error as Dynamo_Error)?.
|
|
221
|
+
(error as Dynamo_Error)?._message ?? ''
|
|
237
222
|
);
|
|
238
223
|
}
|
|
239
224
|
}
|
|
@@ -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
|
|
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
|
|
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
|
|
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.getPreProcessExecutions(), 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.getPreProcessExecutions(), 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.getPreProcessExecutions(), 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.getPreProcessExecutions(), 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.getPreProcessExecutions(), 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.getPreProcessExecutions(), 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.getPreProcessExecutions(), 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.getPreProcessExecutions(), 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.getPreProcessExecutions(), 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.getPreProcessExecutions(), endpointParams.getTasksExecution());
|
|
218
|
+
this.secureRouter.delete(endpointParams.endpoint, endpointParams.getFullExecution());
|
|
234
219
|
break;
|
|
235
220
|
|
|
236
221
|
default:
|