@futdevpro/nts-dynamo 1.5.54 → 1.5.58
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/README.md +123 -0
- package/lib/_enums/data-model-type.enum.d.ts +7 -0
- package/lib/_enums/data-model-type.enum.d.ts.map +1 -1
- package/lib/_enums/data-model-type.enum.js +7 -0
- package/lib/_enums/data-model-type.enum.js.map +1 -1
- package/lib/_enums/dynamo-nts-data-service-function.enum.d.ts +5 -0
- package/lib/_enums/dynamo-nts-data-service-function.enum.d.ts.map +1 -1
- package/lib/_enums/dynamo-nts-data-service-function.enum.js +5 -1
- package/lib/_enums/dynamo-nts-data-service-function.enum.js.map +1 -1
- package/lib/_enums/dynamo-nts-route-security.enum.d.ts +6 -0
- package/lib/_enums/dynamo-nts-route-security.enum.d.ts.map +1 -1
- package/lib/_enums/dynamo-nts-route-security.enum.js +6 -0
- package/lib/_enums/dynamo-nts-route-security.enum.js.map +1 -1
- package/lib/_enums/dynamo-nts-socket-security.enum.d.ts +6 -0
- package/lib/_enums/dynamo-nts-socket-security.enum.d.ts.map +1 -1
- package/lib/_enums/dynamo-nts-socket-security.enum.js +6 -0
- package/lib/_enums/dynamo-nts-socket-security.enum.js.map +1 -1
- package/lib/_enums/http/http-call-type.enum.d.ts +4 -0
- package/lib/_enums/http/http-call-type.enum.d.ts.map +1 -1
- package/lib/_enums/http/http-call-type.enum.js +4 -0
- package/lib/_enums/http/http-call-type.enum.js.map +1 -1
- package/lib/_enums/predefined-data-types.enum.d.ts +3 -0
- package/lib/_enums/predefined-data-types.enum.d.ts.map +1 -1
- package/lib/_enums/predefined-data-types.enum.js +3 -0
- package/lib/_enums/predefined-data-types.enum.js.map +1 -1
- package/lib/_models/dynamo-nts-api-call-params.d.ts +61 -2
- package/lib/_models/dynamo-nts-api-call-params.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-api-call-params.js +24 -7
- package/lib/_models/dynamo-nts-api-call-params.js.map +1 -1
- package/lib/_models/dynamo-nts-app-params.d.ts +33 -1
- package/lib/_models/dynamo-nts-app-params.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-app-params.js +1 -1
- package/lib/_models/dynamo-nts-app-params.js.map +1 -1
- package/lib/_models/dynamo-nts-endpoint-params.d.ts +36 -1
- package/lib/_models/dynamo-nts-endpoint-params.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-endpoint-params.js +15 -13
- package/lib/_models/dynamo-nts-endpoint-params.js.map +1 -1
- package/lib/_models/dynamo-nts-global-settings.d.ts +31 -0
- package/lib/_models/dynamo-nts-global-settings.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-routing-module-settings.d.ts +10 -1
- package/lib/_models/dynamo-nts-routing-module-settings.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-socket-dictionary.d.ts +3 -0
- package/lib/_models/dynamo-nts-socket-dictionary.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-socket-dictionary.js +3 -0
- package/lib/_models/dynamo-nts-socket-dictionary.js.map +1 -1
- package/lib/_models/dynamo-nts-socket-event-params.d.ts +1 -1
- package/lib/_models/dynamo-nts-socket-event-params.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-socket-event-params.js +3 -3
- package/lib/_models/dynamo-nts-socket-event-params.js.map +1 -1
- package/lib/_models/dynamo-nts-socket-service-params.d.ts +1 -1
- package/lib/_models/dynamo-nts-socket-service-params.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-socket-service-params.js +3 -3
- package/lib/_models/dynamo-nts-socket-service-params.js.map +1 -1
- package/lib/_modules/usage/usage.service.js +1 -1
- package/lib/_modules/usage/usage.service.js.map +1 -1
- package/lib/_services/dynamo-nts-api.service.d.ts +17 -2
- package/lib/_services/dynamo-nts-api.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-api.service.js +19 -11
- package/lib/_services/dynamo-nts-api.service.js.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.d.ts +10 -1
- package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.js +8 -8
- package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
- package/lib/_services/dynamo-nts-app.d.ts +30 -3
- package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app.js +19 -19
- package/lib/_services/dynamo-nts-app.js.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.d.ts +4 -4
- package/lib/_services/dynamo-nts-controller.service.d.ts +55 -0
- package/lib/_services/dynamo-nts-controller.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-controller.service.js +2 -2
- package/lib/_services/dynamo-nts-controller.service.js.map +1 -1
- package/lib/_services/dynamo-nts-data.service.d.ts +15 -3
- package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-data.service.js +203 -147
- package/lib/_services/dynamo-nts-data.service.js.map +1 -1
- package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-db.service.js +132 -83
- package/lib/_services/dynamo-nts-db.service.js.map +1 -1
- package/lib/_services/dynamo-nts-email.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-email.service.js +26 -22
- package/lib/_services/dynamo-nts-email.service.js.map +1 -1
- package/lib/_services/dynamo-nts-global.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-global.service.js +3 -3
- package/lib/_services/dynamo-nts-global.service.js.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.js +1 -2
- package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
- package/lib/_services/dynamo-nts-socket.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-socket.service.js +1 -2
- package/lib/_services/dynamo-nts-socket.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -13
- package/src/_assets/dynamo-nts-128.png +0 -0
- package/src/_assets/dynamo-nts-256.png +0 -0
- package/src/_assets/dynamo-nts-512.png +0 -0
- package/src/_assets/dynamo-nts-64.png +0 -0
- package/src/_enums/data-model-type.enum.ts +7 -0
- package/src/_enums/dynamo-nts-data-service-function.enum.ts +5 -1
- package/src/_enums/dynamo-nts-route-security.enum.ts +6 -0
- package/src/_enums/dynamo-nts-socket-security.enum.ts +6 -0
- package/src/_enums/http/http-call-type.enum.ts +4 -0
- package/src/_enums/predefined-data-types.enum.ts +3 -0
- package/src/_models/dynamo-nts-api-call-params.ts +74 -14
- package/src/_models/dynamo-nts-app-params.ts +33 -1
- package/src/_models/dynamo-nts-endpoint-params.ts +49 -14
- package/src/_models/dynamo-nts-global-settings.ts +31 -0
- package/src/_models/dynamo-nts-routing-module-settings.ts +10 -1
- package/src/_models/dynamo-nts-socket-dictionary.ts +3 -0
- package/src/_models/dynamo-nts-socket-event-params.ts +3 -3
- package/src/_models/dynamo-nts-socket-service-params.ts +3 -3
- package/src/_modules/usage/usage.service.ts +2 -2
- package/src/_services/dynamo-nts-api.service.ts +23 -12
- package/src/_services/dynamo-nts-app-extended.ts +17 -8
- package/src/_services/dynamo-nts-app.ts +47 -20
- package/src/_services/dynamo-nts-auth.service.ts +4 -4
- package/src/_services/dynamo-nts-controller.service.ts +57 -2
- package/src/_services/dynamo-nts-data.service.ts +200 -132
- package/src/_services/dynamo-nts-db.service.ts +122 -83
- package/src/_services/dynamo-nts-email.service.ts +33 -23
- package/src/_services/dynamo-nts-global.service.ts +3 -4
- package/src/_services/dynamo-nts-routing-module.service.ts +2 -3
- package/src/_services/dynamo-nts-socket.service.ts +2 -3
- package/src/version.json +0 -2
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
|
|
2
2
|
import * as Axios from 'axios';
|
|
3
|
-
import { Dynamo_Error } from '@futdevpro/fsm-dynamo';
|
|
3
|
+
import { Dynamo_Error, Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
4
4
|
|
|
5
5
|
import { HttpCallType } from '../_enums/http/http-call-type.enum';
|
|
6
6
|
import { HttpResponseType } from '../_enums/http/http-response-type.enum';
|
|
7
7
|
import { DynamoNTS_ApiCallParams } from '../_models/dynamo-nts-api-call-params';
|
|
8
|
-
import { DynamoNTS_Shared } from './dynamo-nts-shared.service';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
10
|
+
* This predefined Api service contains the basic API call function which can be used in various ways
|
|
12
11
|
*/
|
|
13
12
|
export class DynamoNTS_ApiService {
|
|
14
13
|
|
|
@@ -21,12 +20,24 @@ export class DynamoNTS_ApiService {
|
|
|
21
20
|
* @returns
|
|
22
21
|
*/
|
|
23
22
|
public static async startApiCall<T>(
|
|
23
|
+
/**
|
|
24
|
+
* you must setup the basic api call params with this.
|
|
25
|
+
* follow the instructions in the constructor: new DynamoNTS_ApiCallParams({ ... })
|
|
26
|
+
*/
|
|
24
27
|
callParams: DynamoNTS_ApiCallParams,
|
|
28
|
+
/**
|
|
29
|
+
* you can pass data and other inputs in this section
|
|
30
|
+
*/
|
|
25
31
|
inputParams?: {
|
|
26
32
|
pathParams?: {
|
|
33
|
+
/**
|
|
34
|
+
* path params setted in endpoint
|
|
35
|
+
*/
|
|
27
36
|
[param: string]: string
|
|
28
37
|
},
|
|
29
|
-
|
|
38
|
+
/**
|
|
39
|
+
* api call's body
|
|
40
|
+
*/
|
|
30
41
|
body?: any
|
|
31
42
|
}
|
|
32
43
|
): Promise<any> {
|
|
@@ -40,7 +51,7 @@ export class DynamoNTS_ApiService {
|
|
|
40
51
|
if (callParams.httpOptions.headers[headerKey]) {
|
|
41
52
|
privateAxiosInstance.defaults.headers.common[headerKey] = callParams.httpOptions.headers[headerKey];
|
|
42
53
|
} else {
|
|
43
|
-
|
|
54
|
+
Dynamo_Log.logError('DYNAMOBE ERROR: \n missing header:', headerKey, '\n\n', new Error());
|
|
44
55
|
}
|
|
45
56
|
}
|
|
46
57
|
}
|
|
@@ -57,11 +68,11 @@ export class DynamoNTS_ApiService {
|
|
|
57
68
|
url = url.replace(`:${pathParamKey}`, inputParams.pathParams[pathParamKey]);
|
|
58
69
|
break;
|
|
59
70
|
default:
|
|
60
|
-
|
|
71
|
+
Dynamo_Log.logError(`DYNAMOBE ERROR: \n wrong path param type: (${pathParamKey}): ${paramType} \n${inputParams.pathParams[pathParamKey]}\nMUST BE string or number\n\n`, new Error());
|
|
61
72
|
break;
|
|
62
73
|
}
|
|
63
74
|
} else {
|
|
64
|
-
|
|
75
|
+
Dynamo_Log.logError('DYNAMOBE ERROR: \n missing pathParam:', pathParamKey, '\n\n', new Error());
|
|
65
76
|
}
|
|
66
77
|
}
|
|
67
78
|
}
|
|
@@ -130,7 +141,7 @@ export class DynamoNTS_ApiService {
|
|
|
130
141
|
});
|
|
131
142
|
break;
|
|
132
143
|
default:
|
|
133
|
-
|
|
144
|
+
Dynamo_Log.logError('DYNAMOBE ERROR: \n wrong api call type', '\n\n', new Error());
|
|
134
145
|
break;
|
|
135
146
|
}
|
|
136
147
|
|
|
@@ -140,7 +151,7 @@ export class DynamoNTS_ApiService {
|
|
|
140
151
|
return a as T;
|
|
141
152
|
}
|
|
142
153
|
} catch (error) {
|
|
143
|
-
|
|
154
|
+
Dynamo_Log.logError(`\nAPI ERROR: ${callParams?.name} failed...` +
|
|
144
155
|
`\n${callParams?.baseUrl}${callParams?.endPoint}`);
|
|
145
156
|
|
|
146
157
|
if (callParams?.httpOptions?.responseType === HttpResponseType.text) {
|
|
@@ -148,7 +159,7 @@ export class DynamoNTS_ApiService {
|
|
|
148
159
|
}
|
|
149
160
|
|
|
150
161
|
if (error?.response?.data?.flag === 'DYNAMO ERROR OBJECT') {
|
|
151
|
-
|
|
162
|
+
Dynamo_Log.logError(`\n${callParams.name} was UNSUCCESSFUL\n\n`, new Error());
|
|
152
163
|
|
|
153
164
|
throw new Dynamo_Error({
|
|
154
165
|
errorCode: 'NTS-API-002',
|
|
@@ -158,7 +169,7 @@ export class DynamoNTS_ApiService {
|
|
|
158
169
|
error: error.response.data
|
|
159
170
|
});
|
|
160
171
|
} else if (error.code === 'ENOTFOUND') {
|
|
161
|
-
|
|
172
|
+
Dynamo_Log.logError(`\n${callParams.name} was UNSUCCESSFUL\n\n`, new Error());
|
|
162
173
|
|
|
163
174
|
throw new Dynamo_Error({
|
|
164
175
|
status: 404,
|
|
@@ -178,7 +189,7 @@ export class DynamoNTS_ApiService {
|
|
|
178
189
|
error
|
|
179
190
|
});
|
|
180
191
|
} else {
|
|
181
|
-
|
|
192
|
+
Dynamo_Log.logError(`\n${callParams.name} was UNSUCCESSFUL`, error, '\n\n', new Error());
|
|
182
193
|
|
|
183
194
|
throw error;
|
|
184
195
|
}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import * as SocketIO from 'socket.io';
|
|
3
3
|
import * as Http from 'http';
|
|
4
4
|
|
|
5
|
-
import { DynamoNTS_Shared } from './dynamo-nts-shared.service';
|
|
6
5
|
import { DynamoNTS_RouteSecurity } from '../_enums/dynamo-nts-route-security.enum';
|
|
7
6
|
import { DynamoNTS_App } from './dynamo-nts-app';
|
|
8
7
|
import { DynamoNTS_SocketService } from './dynamo-nts-socket.service';
|
|
9
8
|
import { DynamoNTS_SocketSecurity } from '../_enums/dynamo-nts-socket-security.enum';
|
|
9
|
+
import { Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* This will be the MAIN service of our server project,
|
|
@@ -27,7 +27,7 @@ import { DynamoNTS_SocketSecurity } from '../_enums/dynamo-nts-socket-security.e
|
|
|
27
27
|
* // Setting up App params, and preparing project global settings
|
|
28
28
|
* setupAppParams(): void {
|
|
29
29
|
* this.params = new DynamoNTS_AppParams({
|
|
30
|
-
* name: 'Warbots
|
|
30
|
+
* name: 'Warbots Server',
|
|
31
31
|
* title: warbotsTitleLog,
|
|
32
32
|
* version: version,
|
|
33
33
|
* dbName: 'warbots',
|
|
@@ -112,6 +112,15 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
112
112
|
|
|
113
113
|
private socketSecurity: DynamoNTS_RouteSecurity;
|
|
114
114
|
|
|
115
|
+
/**
|
|
116
|
+
* @example
|
|
117
|
+
* // Setting up Sockets
|
|
118
|
+
* this.socketServices = [
|
|
119
|
+
* NotificationService.getInstance(),
|
|
120
|
+
* ChatService.getInstance(),
|
|
121
|
+
* ...
|
|
122
|
+
* ];
|
|
123
|
+
*/
|
|
115
124
|
protected socketServices: DynamoNTS_SocketService<any>[];
|
|
116
125
|
|
|
117
126
|
constructor(){
|
|
@@ -123,15 +132,15 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
123
132
|
|
|
124
133
|
this.setupSocketServices();
|
|
125
134
|
|
|
126
|
-
if (this.
|
|
135
|
+
if (this.debugLog) console.log(`\nAll sockets setted up.... sockets using security: ${this.socketSecurity}`);
|
|
127
136
|
} else {
|
|
128
|
-
|
|
137
|
+
Dynamo_Log.logWarning(
|
|
129
138
|
'\nNo socketServices setted up while using Extended Application.',
|
|
130
139
|
'\nYou should use DynamoNTS_App if you don`t need socket services.\n'
|
|
131
140
|
);
|
|
132
141
|
}
|
|
133
142
|
} catch (error) {
|
|
134
|
-
|
|
143
|
+
Dynamo_Log.logError('\nExtended Application start failed.\n', error, '\n');
|
|
135
144
|
}
|
|
136
145
|
}
|
|
137
146
|
|
|
@@ -179,7 +188,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
179
188
|
errorMsg += `\n ${service.name} (port: ${service.port})`;
|
|
180
189
|
}
|
|
181
190
|
});
|
|
182
|
-
|
|
191
|
+
Dynamo_Log.logError(errorMsg);
|
|
183
192
|
|
|
184
193
|
let error = new Error('Secure routes cannot be established!');
|
|
185
194
|
let errorStack: string[] = error.stack.split('\n');
|
|
@@ -206,10 +215,10 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
|
|
|
206
215
|
}
|
|
207
216
|
|
|
208
217
|
if (service.security === DynamoNTS_SocketSecurity.open) {
|
|
209
|
-
if (this.
|
|
218
|
+
if (this.debugLog) console.log(`\nsocket setup (open): ${service.name}:${service.port}`);
|
|
210
219
|
service.setupSocketServer(new SocketIO.Server(httpSocketServer));
|
|
211
220
|
} else if (service.security === DynamoNTS_SocketSecurity.secure) {
|
|
212
|
-
if (this.
|
|
221
|
+
if (this.debugLog) console.log(`\nsocket setup (secure): ${service.name}:${service.port}`);
|
|
213
222
|
service.setupSocketServer(new SocketIO.Server(this.httpsServer));
|
|
214
223
|
} else {
|
|
215
224
|
let error = new Error(`INVALID Socket Service security: ${service.security} on ${service.name}`);
|
|
@@ -6,12 +6,12 @@ import * as Https from 'https';
|
|
|
6
6
|
import * as FileSystem from 'fs';
|
|
7
7
|
import * as BodyParser from 'body-parser';
|
|
8
8
|
|
|
9
|
-
import { DynamoNTS_Shared } from './dynamo-nts-shared.service';
|
|
10
9
|
import { DynamoNTS_SingletonService } from './dynamo-nts-singleton.service';
|
|
11
10
|
import { DynamoNTS_RouteSecurity } from '../_enums/dynamo-nts-route-security.enum';
|
|
12
11
|
import { DynamoNTS_RoutingModule } from './dynamo-nts-routing-module.service';
|
|
13
12
|
import { DynamoNTS_EndpointParams } from '../_models/dynamo-nts-endpoint-params';
|
|
14
13
|
import { dynamoNTS_GlobalSettings } from '../_constants';
|
|
14
|
+
import { Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* This will be the MAIN service of our server project,
|
|
@@ -27,10 +27,10 @@ import { dynamoNTS_GlobalSettings } from '../_constants';
|
|
|
27
27
|
*
|
|
28
28
|
* ...
|
|
29
29
|
*
|
|
30
|
-
*
|
|
30
|
+
* // Setting up App params, and preparing project global settings
|
|
31
31
|
* setupAppParams(): void {
|
|
32
32
|
* this.params = new DynamoNTS_AppParams({
|
|
33
|
-
* name: 'Warbots
|
|
33
|
+
* name: 'Warbots Server',
|
|
34
34
|
* title: warbotsTitleLog,
|
|
35
35
|
* version: version,
|
|
36
36
|
* dbName: 'warbots',
|
|
@@ -125,15 +125,36 @@ import { dynamoNTS_GlobalSettings } from '../_constants';
|
|
|
125
125
|
*/
|
|
126
126
|
export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Setup this in the setupAppParams(), which will be called first in the constuctor
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
*
|
|
133
|
+
* this.params = new DynamoNTS_AppParams({
|
|
134
|
+
* name: 'Warbots Server',
|
|
135
|
+
* title: warbotsTitleLog,
|
|
136
|
+
* version: version,
|
|
137
|
+
* dbName: 'warbots',
|
|
138
|
+
* });
|
|
139
|
+
*/
|
|
128
140
|
protected params: DynamoNTS_AppParams;
|
|
129
141
|
|
|
130
142
|
protected mongoose = Mongoose;
|
|
131
143
|
|
|
132
144
|
protected security: DynamoNTS_RouteSecurity;
|
|
133
145
|
|
|
146
|
+
/**
|
|
147
|
+
* setup this in the setupRoutingModules()
|
|
148
|
+
*/
|
|
134
149
|
protected httpPort?: number;
|
|
150
|
+
/**
|
|
151
|
+
* setup this in the setupRoutingModules()
|
|
152
|
+
*/
|
|
135
153
|
protected httpsPort?: number;
|
|
136
154
|
|
|
155
|
+
/**
|
|
156
|
+
* setup this in the setupRoutingModules()
|
|
157
|
+
*/
|
|
137
158
|
protected cert?: {
|
|
138
159
|
keyPath: FileSystem.PathLike,
|
|
139
160
|
certPath: FileSystem.PathLike,
|
|
@@ -143,9 +164,15 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
143
164
|
private secureExpress: Express.Application;
|
|
144
165
|
protected httpsServer: Https.Server;
|
|
145
166
|
|
|
167
|
+
/**
|
|
168
|
+
* setup this in the setupRoutingModules()
|
|
169
|
+
*/
|
|
146
170
|
protected routingModules: DynamoNTS_RoutingModule[];
|
|
147
171
|
|
|
148
|
-
|
|
172
|
+
/**
|
|
173
|
+
* setting this value to true, enables this service debug logs
|
|
174
|
+
*/
|
|
175
|
+
protected debugLog: boolean;
|
|
149
176
|
|
|
150
177
|
constructor(){
|
|
151
178
|
super();
|
|
@@ -158,7 +185,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
158
185
|
this.startDB();
|
|
159
186
|
|
|
160
187
|
this.setGlobalServiceCollection();
|
|
161
|
-
this.
|
|
188
|
+
this.debugLog = dynamoNTS_GlobalSettings.logSetup;
|
|
162
189
|
|
|
163
190
|
this.setupRoutingModules();
|
|
164
191
|
this.setSecurity();
|
|
@@ -174,10 +201,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
174
201
|
this.mountSecureRoutes();
|
|
175
202
|
}
|
|
176
203
|
|
|
177
|
-
if (this.
|
|
204
|
+
if (this.debugLog) console.log(`\nRoutes mounted.... server using security: ${this.security}`);
|
|
178
205
|
}
|
|
179
206
|
} catch (error) {
|
|
180
|
-
|
|
207
|
+
Dynamo_Log.logError('\nApplication start failed.\n', error);
|
|
181
208
|
}
|
|
182
209
|
}
|
|
183
210
|
|
|
@@ -187,10 +214,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
187
214
|
private startDB(): void {
|
|
188
215
|
this.mongoose.connection
|
|
189
216
|
.on('error', (error) => {
|
|
190
|
-
|
|
217
|
+
Dynamo_Log.logError('\nUnable to connect to MongoDB server, ERROR: ', error);
|
|
191
218
|
})
|
|
192
219
|
.once('open', () => {
|
|
193
|
-
|
|
220
|
+
Dynamo_Log.logSuccess('\nConnected to MongoDB\n');
|
|
194
221
|
});
|
|
195
222
|
|
|
196
223
|
this.mongoose.connect(
|
|
@@ -224,7 +251,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
224
251
|
});
|
|
225
252
|
}
|
|
226
253
|
});
|
|
227
|
-
|
|
254
|
+
Dynamo_Log.logError(errorMsg);
|
|
228
255
|
|
|
229
256
|
let error = new Error('Open routes cannot be established!');
|
|
230
257
|
let errorStack: string[] = error.stack.split('\n');
|
|
@@ -261,7 +288,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
261
288
|
});
|
|
262
289
|
}
|
|
263
290
|
});
|
|
264
|
-
|
|
291
|
+
Dynamo_Log.logError(errorMsg);
|
|
265
292
|
|
|
266
293
|
let error = new Error('Secure routes cannot be established!');
|
|
267
294
|
let errorStack: string[] = error.stack.split('\n');
|
|
@@ -307,30 +334,30 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
307
334
|
if (this.security !== DynamoNTS_RouteSecurity.open) {
|
|
308
335
|
this.httpsServer
|
|
309
336
|
.listen(this.httpsPort, 'localhost', 0, () => {
|
|
310
|
-
|
|
337
|
+
Dynamo_Log.logSuccess(`\nHTTPS (secure) server is listening on port ${this.httpsPort}\n`);
|
|
311
338
|
})
|
|
312
339
|
.on('error', (error) => {
|
|
313
|
-
|
|
340
|
+
Dynamo_Log.logError(`\nHTTPS (secure) server ERROR`, error);
|
|
314
341
|
})
|
|
315
342
|
.on('uncaughtException', (ex) => {
|
|
316
|
-
|
|
343
|
+
Dynamo_Log.logWarning(`\nHTTPS (secure) server uncaughtException`, ex);
|
|
317
344
|
});
|
|
318
345
|
}
|
|
319
346
|
|
|
320
347
|
if (this.security !== DynamoNTS_RouteSecurity.secure) {
|
|
321
348
|
this.openExpress
|
|
322
349
|
.listen(this.httpPort, () => {
|
|
323
|
-
|
|
350
|
+
Dynamo_Log.logSuccess(`\nHTTP (-open-) server is listening on port ${this.httpPort}\n`);
|
|
324
351
|
})
|
|
325
352
|
.on('error', (error) => {
|
|
326
|
-
|
|
353
|
+
Dynamo_Log.logError(`\nHTTP (-open-) server ERROR`, error);
|
|
327
354
|
})
|
|
328
355
|
.on('uncaughtException', (ex) => {
|
|
329
|
-
|
|
356
|
+
Dynamo_Log.logWarning(`\nHTTP (-open-) server uncaughtException`, ex);
|
|
330
357
|
});
|
|
331
358
|
}
|
|
332
359
|
} catch (error) {
|
|
333
|
-
|
|
360
|
+
Dynamo_Log.logError(`startExpresses failed...`, error);
|
|
334
361
|
}
|
|
335
362
|
}
|
|
336
363
|
|
|
@@ -340,7 +367,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
340
367
|
private mountSecureRoutes (): void {
|
|
341
368
|
this.routingModules.forEach((module: DynamoNTS_RoutingModule) => {
|
|
342
369
|
if (module.security !== DynamoNTS_RouteSecurity.open) {
|
|
343
|
-
if (this.
|
|
370
|
+
if (this.debugLog) console.log(`route mount (secure): ${module.route}`);
|
|
344
371
|
const existingRoutes: DynamoNTS_RoutingModule[] = this.routingModules.filter(
|
|
345
372
|
(mod: DynamoNTS_RoutingModule) => mod.route === module.route);
|
|
346
373
|
if (1 < existingRoutes.length) {
|
|
@@ -362,7 +389,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
362
389
|
private mountOpenRoutes (): void {
|
|
363
390
|
this.routingModules.forEach((module: DynamoNTS_RoutingModule) => {
|
|
364
391
|
if (module.security !== DynamoNTS_RouteSecurity.secure) {
|
|
365
|
-
if (this.
|
|
392
|
+
if (this.debugLog) console.log(`route mount (open): ${module.route}`);
|
|
366
393
|
const existingRoutes: DynamoNTS_RoutingModule[] = this.routingModules.filter(
|
|
367
394
|
(mod: DynamoNTS_RoutingModule) => mod.route === module.route);
|
|
368
395
|
if (1 < existingRoutes.length) {
|
|
@@ -65,7 +65,7 @@ export abstract class DynamoNTS_AuthService extends DynamoNTS_SingletonService {
|
|
|
65
65
|
* let token = AuthService.getTokenFromRequest(req);
|
|
66
66
|
* token = await AuthService.verifyToken(token);
|
|
67
67
|
*
|
|
68
|
-
*
|
|
68
|
+
* Dynamo_Log.logSuccess('token authenticated');
|
|
69
69
|
* res.setHeader('authorization', `Bearer ${token}`);
|
|
70
70
|
* next();
|
|
71
71
|
* } catch (error) {
|
|
@@ -76,7 +76,7 @@ export abstract class DynamoNTS_AuthService extends DynamoNTS_SingletonService {
|
|
|
76
76
|
* userMessage: `Authorization failed.`,
|
|
77
77
|
* error
|
|
78
78
|
* });
|
|
79
|
-
*
|
|
79
|
+
* Dynamo_Log.logError(error?.message, error);
|
|
80
80
|
*
|
|
81
81
|
* res.status(error.status);
|
|
82
82
|
* res.send(error);
|
|
@@ -99,7 +99,7 @@ export abstract class DynamoNTS_AuthService extends DynamoNTS_SingletonService {
|
|
|
99
99
|
* try {
|
|
100
100
|
* let token = AuthService.getTokenFromRequest(req);
|
|
101
101
|
* token = await AuthService.verifyTokenSelf(token, req?.params?.userId);
|
|
102
|
-
*
|
|
102
|
+
* Dynamo_Log.logSuccess('selftoken authenticated');
|
|
103
103
|
*
|
|
104
104
|
* res.setHeader('authorization', `Bearer ${token}`);
|
|
105
105
|
* next();
|
|
@@ -111,7 +111,7 @@ export abstract class DynamoNTS_AuthService extends DynamoNTS_SingletonService {
|
|
|
111
111
|
* userMessage: `Authorization failed.`,
|
|
112
112
|
* error
|
|
113
113
|
* });
|
|
114
|
-
*
|
|
114
|
+
* Dynamo_Log.logError(error?.message, error);
|
|
115
115
|
*
|
|
116
116
|
* res.status(error.status);
|
|
117
117
|
* res.send(error);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
+
import { Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
3
4
|
import { DynamoNTS_EndpointParams } from '../_models/dynamo-nts-endpoint-params';
|
|
4
|
-
import { DynamoNTS_Shared } from './dynamo-nts-shared.service';
|
|
5
5
|
import { DynamoNTS_SingletonService } from './dynamo-nts-singleton.service';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -46,6 +46,33 @@ import { DynamoNTS_SingletonService } from './dynamo-nts-singleton.service';
|
|
|
46
46
|
*/
|
|
47
47
|
export abstract class DynamoNTS_Controller extends DynamoNTS_SingletonService {
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* setup this in the setupEndpoints(), which will be called on the construcion
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
*
|
|
54
|
+
* this.endpoints = [
|
|
55
|
+
* new DynamoNTS_EndpointParams({
|
|
56
|
+
* name: 'getUserMatchStatistics',
|
|
57
|
+
* type: HttpCallType.get,
|
|
58
|
+
* endpoint: '/get/user-match-statistics/:userId',
|
|
59
|
+
* preProcessess: [ this.authService.authenticateTokenSelf ],
|
|
60
|
+
* tasks: [
|
|
61
|
+
* async (req: Request, res: Response) => {
|
|
62
|
+
* const userMatchStatistics = new UserMatchStatisticsService({
|
|
63
|
+
* data: { userId: req.params.userId }
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* await userMatchStatistics.getDataByDependencyId();
|
|
67
|
+
*
|
|
68
|
+
* res.send(
|
|
69
|
+
* userMatchStatistics.data
|
|
70
|
+
* );
|
|
71
|
+
* }
|
|
72
|
+
* ]
|
|
73
|
+
* }),
|
|
74
|
+
* ];
|
|
75
|
+
*/
|
|
49
76
|
endpoints: DynamoNTS_EndpointParams[];
|
|
50
77
|
|
|
51
78
|
protected constructor(){
|
|
@@ -54,12 +81,40 @@ export abstract class DynamoNTS_Controller extends DynamoNTS_SingletonService {
|
|
|
54
81
|
try {
|
|
55
82
|
this.setupEndpoints();
|
|
56
83
|
} catch (error) {
|
|
57
|
-
|
|
84
|
+
Dynamo_Log.logError(`DynamoBEController ERROR setup failed:`, error);
|
|
58
85
|
}
|
|
59
86
|
}
|
|
60
87
|
|
|
61
88
|
/**
|
|
62
89
|
* You must setup endpoints and required services in this function
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
*
|
|
93
|
+
* setupEndpoints(): void {
|
|
94
|
+
* this.authService = AuthService.getInstance();
|
|
95
|
+
*
|
|
96
|
+
* this.endpoints = [
|
|
97
|
+
* new DynamoNTS_EndpointParams({
|
|
98
|
+
* name: 'getUserMatchStatistics',
|
|
99
|
+
* type: HttpCallType.get,
|
|
100
|
+
* endpoint: '/get/user-match-statistics/:userId',
|
|
101
|
+
* preProcessess: [ this.authService.authenticateTokenSelf ],
|
|
102
|
+
* tasks: [
|
|
103
|
+
* async (req: Request, res: Response) => {
|
|
104
|
+
* const userMatchStatistics = new UserMatchStatisticsService({
|
|
105
|
+
* data: { userId: req.params.userId }
|
|
106
|
+
* });
|
|
107
|
+
*
|
|
108
|
+
* await userMatchStatistics.getDataByDependencyId();
|
|
109
|
+
*
|
|
110
|
+
* res.send(
|
|
111
|
+
* userMatchStatistics.data
|
|
112
|
+
* );
|
|
113
|
+
* }
|
|
114
|
+
* ]
|
|
115
|
+
* }),
|
|
116
|
+
* ];
|
|
117
|
+
* }
|
|
63
118
|
*/
|
|
64
119
|
abstract setupEndpoints(): void
|
|
65
120
|
}
|