@futdevpro/nts-dynamo 1.5.51 → 1.5.52

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 (34) hide show
  1. package/lib/_models/dynamo-nts-endpoint-params.js +3 -2
  2. package/lib/_models/dynamo-nts-endpoint-params.js.map +1 -1
  3. package/lib/_services/dynamo-nts-app-extended.d.ts +87 -7
  4. package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
  5. package/lib/_services/dynamo-nts-app-extended.js +87 -7
  6. package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
  7. package/lib/_services/dynamo-nts-app.d.ts +131 -22
  8. package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
  9. package/lib/_services/dynamo-nts-app.js +104 -1
  10. package/lib/_services/dynamo-nts-app.js.map +1 -1
  11. package/lib/_services/dynamo-nts-auth.service.d.ts +78 -5
  12. package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
  13. package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
  14. package/lib/_services/dynamo-nts-data.service.d.ts +23 -1
  15. package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
  16. package/lib/_services/dynamo-nts-data.service.js +73 -53
  17. package/lib/_services/dynamo-nts-data.service.js.map +1 -1
  18. package/lib/_services/dynamo-nts-db.service.d.ts +164 -119
  19. package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
  20. package/lib/_services/dynamo-nts-db.service.js +327 -277
  21. package/lib/_services/dynamo-nts-db.service.js.map +1 -1
  22. package/lib/_services/dynamo-nts-routing-module.service.d.ts +39 -0
  23. package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
  24. package/lib/_services/dynamo-nts-routing-module.service.js +39 -0
  25. package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
  26. package/lib/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +15 -12
  28. package/src/_models/dynamo-nts-endpoint-params.ts +2 -2
  29. package/src/_services/dynamo-nts-app-extended.ts +87 -7
  30. package/src/_services/dynamo-nts-app.ts +131 -22
  31. package/src/_services/dynamo-nts-auth.service.ts +79 -5
  32. package/src/_services/dynamo-nts-data.service.ts +74 -54
  33. package/src/_services/dynamo-nts-db.service.ts +355 -281
  34. package/src/_services/dynamo-nts-routing-module.service.ts +39 -0
@@ -9,7 +9,7 @@ import { DynamoNTS_SocketService } from './dynamo-nts-socket.service';
9
9
  import { DynamoNTS_SocketSecurity } from '../_enums/dynamo-nts-socket-security.enum';
10
10
 
11
11
  /**
12
- * This will be the main service of our server project,
12
+ * This will be the MAIN service of our server project,
13
13
  * follow the types and type instructions while setting up your project
14
14
  *
15
15
  * In this service, there are abstract functions that you will need to implement,
@@ -20,13 +20,93 @@ import { DynamoNTS_SocketSecurity } from '../_enums/dynamo-nts-socket-security.e
20
20
  * You need to add socketService definitions to setupRoutingModules
21
21
  *
22
22
  * @example
23
- * ...
24
- * this.socketServices = [
25
- * NotificationService.getInstance(),
26
- * ChatService.getInstance(),
23
+ * export class App extends DynamoNTS_AppExtended {
24
+ *
25
+ * ...
26
+ *
27
+ * // Setting up App params, and preparing project global settings
28
+ * setupAppParams(): void {
29
+ * this.params = new DynamoNTS_AppParams({
30
+ * name: 'Warbots Distribution Server',
31
+ * title: warbotsTitleLog,
32
+ * version: version,
33
+ * dbName: 'warbots',
34
+ * });
35
+ *
36
+ * // dynamoNTS_GlobalSettings.logRequestsContent = false;
37
+ * }
38
+ *
39
+ * ...
40
+ *
41
+ * // Setting up DBServices
42
+ * setGlobalServiceCollection(): void {
43
+ * DynamoNTS_GlobalService.setServices({
44
+ * authService: AuthService.getInstance(),
45
+ * emailServiceCollection: EmailServiceCollectionService.getInstance(),
46
+ * dbModels: [
47
+ * userModelParams,
48
+ * userDataModelParams,
49
+ * userOptionsModelParams,
50
+ * userStatisticsModelParams,
51
+ * userAchievementsModelParams,
52
+ * userNotificationsModelParams,
53
+ *
54
+ * matchStatisticsModelParams,
55
+ * matchDataModelParams,
56
+
57
+ * usageSessionModelParams,
58
+ * customDataModelParams,
59
+ * ]
60
+ * });
61
+ * }
62
+ *
63
+ * ...
64
+ *
65
+ * // Setting up Routes
66
+ * setupRoutingModules(): void {
67
+ * this.httpPort = env.port;
68
+
69
+ * this.routingModules = [
70
+ * new DynamoNTS_RoutingModule({
71
+ * route: '/user',
72
+ * controllers: [
73
+ * UserController.getInstance(),
74
+ * UserDataController.getInstance(),
75
+ * UserOptionsController.getInstance(),
76
+ * UserStatisticsController.getInstance(),
77
+ * UserAchievementsController.getInstance(),
78
+ * UserNotificationsController.getInstance()
79
+ * ]
80
+ * }),
81
+ * new DynamoNTS_RoutingModule({
82
+ * route: '/match',
83
+ * controllers: [
84
+ * MatchController.getInstance(),
85
+ * MatchDistributionController.getInstance(),
86
+ * MatchStatisticsController.getInstance(),
87
+ * ]
88
+ * }),
89
+ * new DynamoNTS_RoutingModule({
90
+ * route: '/server',
91
+ * controllers: [
92
+ * ServerController.getInstance(),
93
+ * ]
94
+ * }),
95
+
96
+ * getTestRoutingModule(),
97
+ * getUsageRoutingModule()
98
+ * ];
99
+ *
27
100
  * ...
28
- * ];
29
- * ...
101
+ *
102
+ * // Setting up Sockets
103
+ * this.socketServices = [
104
+ * NotificationService.getInstance(),
105
+ * ChatService.getInstance(),
106
+ * ...
107
+ * ];
108
+ * }
109
+ * }
30
110
  */
31
111
  export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
32
112
 
@@ -14,11 +14,114 @@ import { DynamoNTS_EndpointParams } from '../_models/dynamo-nts-endpoint-params'
14
14
  import { dynamoNTS_GlobalSettings } from '../_constants';
15
15
 
16
16
  /**
17
- * This will be the main service of our server project,
17
+ * This will be the MAIN service of our server project,
18
18
  * follow the types and type instructions while setting up your project
19
19
  *
20
20
  * In this service, there are abstract functions that you will need to implement,
21
21
  * where you need to set up the main params for your application.
22
+ *
23
+ * (after the example, you can find the list of services you can/should setup)
24
+ *
25
+ * @example
26
+ * export class App extends DynamoNTS_AppExtended {
27
+ *
28
+ * ...
29
+ *
30
+ * // Setting up App params, and preparing project global settings
31
+ * setupAppParams(): void {
32
+ * this.params = new DynamoNTS_AppParams({
33
+ * name: 'Warbots Distribution Server',
34
+ * title: warbotsTitleLog,
35
+ * version: version,
36
+ * dbName: 'warbots',
37
+ * });
38
+ *
39
+ * // dynamoNTS_GlobalSettings.logRequestsContent = false;
40
+ * }
41
+ *
42
+ * ...
43
+ *
44
+ * // Setting up DBServices
45
+ * setGlobalServiceCollection(): void {
46
+ * DynamoNTS_GlobalService.setServices({
47
+ * authService: AuthService.getInstance(),
48
+ * emailServiceCollection: EmailServiceCollectionService.getInstance(),
49
+ * dbModels: [
50
+ * userModelParams,
51
+ * userDataModelParams,
52
+ * userOptionsModelParams,
53
+ * userStatisticsModelParams,
54
+ * userAchievementsModelParams,
55
+ * userNotificationsModelParams,
56
+ *
57
+ * matchStatisticsModelParams,
58
+ * matchDataModelParams,
59
+
60
+ * usageSessionModelParams,
61
+ * customDataModelParams,
62
+ * ]
63
+ * });
64
+ * }
65
+ *
66
+ * ...
67
+ *
68
+ * // Setting up Routes
69
+ * setupRoutingModules(): void {
70
+ * this.httpPort = env.port;
71
+
72
+ * this.routingModules = [
73
+ * new DynamoNTS_RoutingModule({
74
+ * route: '/user',
75
+ * controllers: [
76
+ * UserController.getInstance(),
77
+ * UserDataController.getInstance(),
78
+ * UserOptionsController.getInstance(),
79
+ * UserStatisticsController.getInstance(),
80
+ * UserAchievementsController.getInstance(),
81
+ * UserNotificationsController.getInstance()
82
+ * ]
83
+ * }),
84
+ * new DynamoNTS_RoutingModule({
85
+ * route: '/match',
86
+ * controllers: [
87
+ * MatchController.getInstance(),
88
+ * MatchDistributionController.getInstance(),
89
+ * MatchStatisticsController.getInstance(),
90
+ * ]
91
+ * }),
92
+ * new DynamoNTS_RoutingModule({
93
+ * route: '/server',
94
+ * controllers: [
95
+ * ServerController.getInstance(),
96
+ * ]
97
+ * }),
98
+
99
+ * getTestRoutingModule(),
100
+ * getUsageRoutingModule()
101
+ * ];
102
+ * }
103
+ * }
104
+ *
105
+ * //
106
+ * // The Services available
107
+ * //
108
+ * // Authentication Service
109
+ * // A commonly used basic service,
110
+ * // which is necessary fur certain functions (such as registering call issuers)
111
+ * //
112
+ * // This will handle Authentication Token checking/refreshing, checking issuer's identifier and routeParams,
113
+ * // handling JWT Token, or maybe with OAuth2 or other commonly used security procedures
114
+ * //
115
+ * // You can create one with this Dynamo Object:
116
+ * //
117
+ *
118
+ * @example
119
+ * // follow the instructions on the abstract class (DynamoNTS_AuthService)
120
+ * export class AuthService extends DynamoNTS_AuthService {}
121
+ *
122
+ *
123
+ *
124
+ * //
22
125
  */
23
126
  export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
24
127
 
@@ -289,37 +392,42 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
289
392
  }
290
393
 
291
394
  /**
395
+ * Setting up App params, and preparing project global settings
292
396
  * You must setup app params in this function like this:
293
397
  *
294
398
  * @example
295
- * this.params = new DynamoBEAppParams({
296
- * name: 'Sample Server',
297
- * title: 'A BIG nice header that will be logged on start',
298
- * version: version,
299
- * dbName: 'sampleapp',
300
- * });
399
+ * setupAppParams(): void {
400
+ * this.params = new DynamoBEAppParams({
401
+ * name: 'Sample Server',
402
+ * title: 'A BIG nice header that will be logged on start',
403
+ * version: version,
404
+ * dbName: 'sampleapp',
405
+ * });
406
+ *
407
+ * DBE_Global_S.setGlobalSettings({
408
+ * defaultRouteSecurity: DynamoBERouteSecurity.secure,
409
+ * logSetup: true,
410
+ * });
411
+ * }
301
412
  */
302
413
  abstract setupAppParams(): void;
303
414
 
304
415
  /**
416
+ * Setting up DBServices
305
417
  * You must setup globalServiceCollection and dbServices in this function
306
418
  *
307
419
  * @example
308
- * DBE_Global_S.setServices({
309
- * authService: AuthService.getInstance(),
310
- * emailServiceCollection: EmailServiceCollectionService.getInstance(),
311
- * dbModels: [
312
- * accountModelParams,
313
- * projectModelParams,
314
- * ...
315
- * ]
316
- * });
317
- *
318
- * DBE_Global_S.setGlobalSettings({
319
- * defaultRouteSecurity: DynamoBERouteSecurity.secure,
320
- * logSetup: true,
321
- * });
322
- *
420
+ * setGlobalServiceCollection(): void {
421
+ * DBE_Global_S.setServices({
422
+ * authService: AuthService.getInstance(),
423
+ * emailServiceCollection: EmailServiceCollectionService.getInstance(),
424
+ * dbModels: [
425
+ * accountModelParams,
426
+ * projectModelParams,
427
+ * ...
428
+ * ]
429
+ * });
430
+ * }
323
431
  */
324
432
  abstract setGlobalServiceCollection(): void;
325
433
 
@@ -327,6 +435,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
327
435
  * You must setup endpoints and required services in this function
328
436
  *
329
437
  * @example
438
+ * // Setting up Routes
330
439
  * setupRoutingModules(): void {
331
440
  * this.httpPort = env.httpPort;
332
441
  * this.httpsPort = env.httpsPort;
@@ -55,32 +55,106 @@ export abstract class DynamoNTS_AuthService extends DynamoNTS_SingletonService {
55
55
  }
56
56
 
57
57
  /**
58
+ * You need to implement a token validation logic,
59
+ * when if the token is invalid, or the authentication fails, it sends or throws an error
60
+ *
61
+ * @example
62
+ *
63
+ * async authenticateToken(req: Request, res: Response, next: NextFunction) {
64
+ * try {
65
+ * let token = AuthService.getTokenFromRequest(req);
66
+ * token = await AuthService.verifyToken(token);
67
+ *
68
+ * DynamoNTS_Shared.logSuccess('token authenticated');
69
+ * res.setHeader('authorization', `Bearer ${token}`);
70
+ * next();
71
+ * } catch (error) {
72
+ * error = new Dynamo_Error({
73
+ * status: 401,
74
+ * message: `authenticateToken (WB-ERROR)`,
75
+ * addECToUserMsg: true,
76
+ * userMessage: `Authorization failed.`,
77
+ * error
78
+ * });
79
+ * DynamoNTS_Shared.logError(error?.message, error);
80
+ *
81
+ * res.status(error.status);
82
+ * res.send(error);
83
+ * }
84
+ * }
85
+ * */
86
+ abstract authenticateToken(req: Request, res: Response, next: NextFunction): Promise<void>;
87
+
88
+ /**
89
+ * You need to implement a token validation logic,
90
+ * when if the token is invalid, or the authentication fails, it sends or throws an error
58
91
  *
59
92
  * @param req
60
93
  * @param res
61
94
  * @param next
62
- */
63
- abstract authenticateTokenSelf(req: Request, res: Response, next: NextFunction): Promise<void>;
64
- /**
95
+ *
96
+ * @example
97
+ *
98
+ * async authenticateTokenSelf(req: Request, res: Response, next: NextFunction): Promise<void> {
99
+ * try {
100
+ * let token = AuthService.getTokenFromRequest(req);
101
+ * token = await AuthService.verifyTokenSelf(token, req?.params?.userId);
102
+ * DynamoNTS_Shared.logSuccess('selftoken authenticated');
103
+ *
104
+ * res.setHeader('authorization', `Bearer ${token}`);
105
+ * next();
106
+ * } catch (error) {
107
+ * error = new Dynamo_Error({
108
+ * status: 401,
109
+ * message: `authenticateTokenSelf (WB-ERROR)`,
110
+ * addECToUserMsg: true,
111
+ * userMessage: `Authorization failed.`,
112
+ * error
113
+ * });
114
+ * DynamoNTS_Shared.logError(error?.message, error);
115
+ *
116
+ * res.status(error.status);
117
+ * res.send(error);
118
+ * }
119
+ * }
65
120
  *
66
121
  */
67
- abstract authenticateToken(req: Request, res: Response, next: NextFunction): Promise<void>;
122
+ abstract authenticateTokenSelf(req: Request, res: Response, next: NextFunction): Promise<void>;
68
123
 
69
124
  /**
70
125
  * Authenticate Token for Permission to Access UsageData
71
126
  * @param req
72
127
  * @param res
73
128
  * @param next
129
+ *
130
+ * @example
131
+ * You need to implement a token validation logic,
132
+ * when if the token is invalid, or the authentication fails, it sends or throws an error
133
+ *
134
+ * async authTokenPermAccUsageData(req: Request, res: Response, next: NextFunction): Promise<void> {
135
+ * AuthService.authTokenAndPerm(req, res, next, Permission.accessUsageData);
136
+ * }
74
137
  */
75
138
  abstract authTokenPermAccUsageData(req: Request, res: Response, next: NextFunction): Promise<void>;
76
139
 
77
140
  /**
78
141
  * The DynamoBE System is using this to get issuer, that will be set on DBServices
79
142
  * @param req
143
+ *
144
+ * @example
145
+ * getAccountIdFromRequest(req: Request): string {
146
+ * try {
147
+ * const authHeader = req.headers['authorization'];
148
+ * const token = authHeader.split(' ')[1];
149
+ * return this.getAccountIdFromToken(token);
150
+ * } catch {
151
+ * return undefined;
152
+ * }
153
+ * }
80
154
  */
81
155
  abstract getAccountIdFromRequest(req: Request): string;
82
156
  /**
83
- *
157
+ * Basic Module: UsageModule uses this function
84
158
  * @param req
85
159
  */
86
160
  abstract getUsernameFromRequest(req: Request): string;