@futdevpro/nts-dynamo 1.5.76 → 1.5.81

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 (227) hide show
  1. package/LICENSE +2 -2
  2. package/lib/_constants/dynamo-nts-global-settings.d.ts +2 -2
  3. package/lib/_constants/dynamo-nts-global-settings.js +17 -17
  4. package/lib/_constants/index.d.ts +1 -1
  5. package/lib/_constants/index.js +4 -4
  6. package/lib/_enums/data-model-type.enum.d.ts +12 -12
  7. package/lib/_enums/data-model-type.enum.js +16 -16
  8. package/lib/_enums/data-model-type.enum.js.map +1 -1
  9. package/lib/_enums/dynamo-nts-data-service-function.enum.d.ts +12 -12
  10. package/lib/_enums/dynamo-nts-data-service-function.enum.js +18 -18
  11. package/lib/_enums/dynamo-nts-data-service-function.enum.js.map +1 -1
  12. package/lib/_enums/dynamo-nts-route-security.enum.d.ts +11 -11
  13. package/lib/_enums/dynamo-nts-route-security.enum.js +15 -15
  14. package/lib/_enums/dynamo-nts-route-security.enum.js.map +1 -1
  15. package/lib/_enums/dynamo-nts-socket-security.enum.d.ts +10 -10
  16. package/lib/_enums/dynamo-nts-socket-security.enum.js +14 -14
  17. package/lib/_enums/dynamo-nts-socket-security.enum.js.map +1 -1
  18. package/lib/_enums/http/http-call-type.enum.d.ts +11 -11
  19. package/lib/_enums/http/http-call-type.enum.js +15 -15
  20. package/lib/_enums/http/http-call-type.enum.js.map +1 -1
  21. package/lib/_enums/http/http-response-type.enum.d.ts +6 -6
  22. package/lib/_enums/http/http-response-type.enum.js +10 -10
  23. package/lib/_enums/http/http-response-type.enum.js.map +1 -1
  24. package/lib/_enums/http/socket-event.enum.d.ts +9 -8
  25. package/lib/_enums/http/socket-event.enum.d.ts.map +1 -1
  26. package/lib/_enums/http/socket-event.enum.js +13 -12
  27. package/lib/_enums/http/socket-event.enum.js.map +1 -1
  28. package/lib/_enums/index.d.ts +8 -8
  29. package/lib/_enums/index.js +13 -13
  30. package/lib/_enums/predefined-data-types.enum.d.ts +10 -10
  31. package/lib/_enums/predefined-data-types.enum.js +14 -14
  32. package/lib/_enums/predefined-data-types.enum.js.map +1 -1
  33. package/lib/_interfaces/certification-settings.interface.d.ts +7 -0
  34. package/lib/_interfaces/certification-settings.interface.d.ts.map +1 -0
  35. package/lib/_interfaces/certification-settings.interface.js +3 -0
  36. package/lib/_interfaces/certification-settings.interface.js.map +1 -0
  37. package/lib/_interfaces/global-service-settings.interface.d.ts +18 -0
  38. package/lib/_interfaces/global-service-settings.interface.d.ts.map +1 -0
  39. package/lib/_interfaces/global-service-settings.interface.js +3 -0
  40. package/lib/_interfaces/global-service-settings.interface.js.map +1 -0
  41. package/lib/_interfaces/index.d.ts +1 -0
  42. package/lib/_interfaces/index.d.ts.map +1 -0
  43. package/lib/_interfaces/index.js +4 -0
  44. package/lib/_interfaces/index.js.map +1 -0
  45. package/lib/_interfaces/port-settings.interface.d.ts +5 -0
  46. package/lib/_interfaces/port-settings.interface.d.ts.map +1 -0
  47. package/lib/_interfaces/port-settings.interface.js +3 -0
  48. package/lib/_interfaces/port-settings.interface.js.map +1 -0
  49. package/lib/_models/dynamo-nts-api-call-params.d.ts +95 -95
  50. package/lib/_models/dynamo-nts-api-call-params.js +47 -47
  51. package/lib/_models/dynamo-nts-app-params.d.ts +49 -49
  52. package/lib/_models/dynamo-nts-app-params.js +17 -17
  53. package/lib/_models/dynamo-nts-endpoint-params.d.ts +80 -80
  54. package/lib/_models/dynamo-nts-endpoint-params.js +139 -139
  55. package/lib/_models/dynamo-nts-global-settings.d.ts +53 -53
  56. package/lib/_models/dynamo-nts-global-settings.js +2 -2
  57. package/lib/_models/dynamo-nts-routing-module-settings.d.ts +19 -19
  58. package/lib/_models/dynamo-nts-routing-module-settings.js +2 -2
  59. package/lib/_models/dynamo-nts-socket-event-params.d.ts +32 -30
  60. package/lib/_models/dynamo-nts-socket-event-params.d.ts.map +1 -1
  61. package/lib/_models/dynamo-nts-socket-event-params.js +80 -79
  62. package/lib/_models/dynamo-nts-socket-event-params.js.map +1 -1
  63. package/lib/_models/dynamo-nts-socket-presence.d.ts +21 -0
  64. package/lib/_models/dynamo-nts-socket-presence.d.ts.map +1 -0
  65. package/lib/_models/dynamo-nts-socket-presence.js +45 -0
  66. package/lib/_models/dynamo-nts-socket-presence.js.map +1 -0
  67. package/lib/_models/dynamo-nts-socket-service-params.d.ts +18 -18
  68. package/lib/_models/dynamo-nts-socket-service-params.d.ts.map +1 -1
  69. package/lib/_models/dynamo-nts-socket-service-params.js +26 -26
  70. package/lib/_models/dynamo-nts-socket-service-params.js.map +1 -1
  71. package/lib/_models/index.d.ts +7 -8
  72. package/lib/_models/index.d.ts.map +1 -1
  73. package/lib/_models/index.js +12 -12
  74. package/lib/_models/index.js.map +1 -1
  75. package/lib/_modules/api-service.index.d.ts +5 -5
  76. package/lib/_modules/api-service.index.js +11 -11
  77. package/lib/_modules/app-extended.index.d.ts +15 -12
  78. package/lib/_modules/app-extended.index.d.ts.map +1 -1
  79. package/lib/_modules/app-extended.index.js +23 -19
  80. package/lib/_modules/app-extended.index.js.map +1 -1
  81. package/lib/_modules/app.index.d.ts +13 -10
  82. package/lib/_modules/app.index.d.ts.map +1 -1
  83. package/lib/_modules/app.index.js +21 -17
  84. package/lib/_modules/app.index.js.map +1 -1
  85. package/lib/_modules/auth.index.d.ts +3 -3
  86. package/lib/_modules/auth.index.js +8 -8
  87. package/lib/_modules/constants.index.d.ts +1 -1
  88. package/lib/_modules/constants.index.js +4 -4
  89. package/lib/_modules/controller.index.d.ts +4 -4
  90. package/lib/_modules/controller.index.js +10 -10
  91. package/lib/_modules/custom-data/custom-data.controller.d.ts +5 -5
  92. package/lib/_modules/custom-data/custom-data.controller.js +55 -55
  93. package/lib/_modules/custom-data/custom-data.service.d.ts +5 -5
  94. package/lib/_modules/custom-data/custom-data.service.js +11 -11
  95. package/lib/_modules/custom-data/get-custom-data-routing-module.d.ts +3 -3
  96. package/lib/_modules/custom-data/get-custom-data-routing-module.js +17 -17
  97. package/lib/_modules/custom-data/index.d.ts +4 -4
  98. package/lib/_modules/custom-data/index.js +8 -8
  99. package/lib/_modules/custom-data-module.index.d.ts +1 -1
  100. package/lib/_modules/custom-data-module.index.js +4 -4
  101. package/lib/_modules/data-service.index.d.ts +5 -5
  102. package/lib/_modules/data-service.index.js +10 -10
  103. package/lib/_modules/email.index.d.ts +3 -3
  104. package/lib/_modules/email.index.js +8 -8
  105. package/lib/_modules/enums.index.d.ts +1 -1
  106. package/lib/_modules/enums.index.js +4 -4
  107. package/lib/_modules/models.index.d.ts +1 -1
  108. package/lib/_modules/models.index.js +4 -4
  109. package/lib/_modules/services.index.d.ts +1 -1
  110. package/lib/_modules/services.index.js +4 -4
  111. package/lib/_modules/test/get-test-routing-module.d.ts +3 -3
  112. package/lib/_modules/test/get-test-routing-module.js +17 -17
  113. package/lib/_modules/test/index.d.ts +3 -3
  114. package/lib/_modules/test/index.js +7 -7
  115. package/lib/_modules/test/test.controller.d.ts +5 -5
  116. package/lib/_modules/test/test.controller.js +104 -104
  117. package/lib/_modules/test-module.index.d.ts +1 -1
  118. package/lib/_modules/test-module.index.js +4 -4
  119. package/lib/_modules/usage/get-usage-routing-module.d.ts +3 -3
  120. package/lib/_modules/usage/get-usage-routing-module.js +17 -17
  121. package/lib/_modules/usage/index.d.ts +4 -4
  122. package/lib/_modules/usage/index.js +8 -8
  123. package/lib/_modules/usage/usage-controller.d.ts +6 -6
  124. package/lib/_modules/usage/usage-controller.js +88 -88
  125. package/lib/_modules/usage/usage.service.d.ts +16 -16
  126. package/lib/_modules/usage/usage.service.js +132 -132
  127. package/lib/_modules/usage-module.index.d.ts +1 -1
  128. package/lib/_modules/usage-module.index.js +4 -4
  129. package/lib/_services/dynamo-nts-api.service.d.ts +34 -34
  130. package/lib/_services/dynamo-nts-api.service.js +188 -188
  131. package/lib/_services/dynamo-nts-app-extended.d.ts +128 -128
  132. package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
  133. package/lib/_services/dynamo-nts-app-extended.js +212 -212
  134. package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
  135. package/lib/_services/dynamo-nts-app.d.ts +270 -278
  136. package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
  137. package/lib/_services/dynamo-nts-app.js +371 -371
  138. package/lib/_services/dynamo-nts-app.js.map +1 -1
  139. package/lib/_services/dynamo-nts-app.spec.d.ts +1 -0
  140. package/lib/_services/dynamo-nts-app.spec.d.ts.map +1 -0
  141. package/lib/_services/dynamo-nts-app.spec.js +10 -0
  142. package/lib/_services/dynamo-nts-app.spec.js.map +1 -0
  143. package/lib/_services/dynamo-nts-auth.service.d.ts +127 -127
  144. package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
  145. package/lib/_services/dynamo-nts-auth.service.js +53 -53
  146. package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
  147. package/lib/_services/dynamo-nts-controller.service.d.ts +105 -105
  148. package/lib/_services/dynamo-nts-controller.service.d.ts.map +1 -1
  149. package/lib/_services/dynamo-nts-controller.service.js +57 -57
  150. package/lib/_services/dynamo-nts-controller.service.js.map +1 -1
  151. package/lib/_services/dynamo-nts-data.service.d.ts +230 -229
  152. package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
  153. package/lib/_services/dynamo-nts-data.service.js +689 -686
  154. package/lib/_services/dynamo-nts-data.service.js.map +1 -1
  155. package/lib/_services/dynamo-nts-db-service-collection.service.d.ts +8 -8
  156. package/lib/_services/dynamo-nts-db-service-collection.service.js +10 -10
  157. package/lib/_services/dynamo-nts-db.service.d.ts +312 -312
  158. package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
  159. package/lib/_services/dynamo-nts-db.service.js +856 -856
  160. package/lib/_services/dynamo-nts-db.service.js.map +1 -1
  161. package/lib/_services/dynamo-nts-email-service-collection.service.d.ts +18 -18
  162. package/lib/_services/dynamo-nts-email-service-collection.service.js +20 -20
  163. package/lib/_services/dynamo-nts-email.service.d.ts +56 -56
  164. package/lib/_services/dynamo-nts-email.service.d.ts.map +1 -1
  165. package/lib/_services/dynamo-nts-email.service.js +203 -203
  166. package/lib/_services/dynamo-nts-email.service.js.map +1 -1
  167. package/lib/_services/dynamo-nts-global.service.d.ts +71 -84
  168. package/lib/_services/dynamo-nts-global.service.d.ts.map +1 -1
  169. package/lib/_services/dynamo-nts-global.service.js +156 -156
  170. package/lib/_services/dynamo-nts-global.service.js.map +1 -1
  171. package/lib/_services/dynamo-nts-routing-module.service.d.ts +76 -76
  172. package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
  173. package/lib/_services/dynamo-nts-routing-module.service.js +191 -191
  174. package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
  175. package/lib/_services/dynamo-nts-shared.service.d.ts +31 -31
  176. package/lib/_services/dynamo-nts-shared.service.d.ts.map +1 -1
  177. package/lib/_services/dynamo-nts-shared.service.js +70 -70
  178. package/lib/_services/dynamo-nts-shared.service.js.map +1 -1
  179. package/lib/_services/dynamo-nts-shared.service.spec.d.ts +2 -0
  180. package/lib/_services/dynamo-nts-shared.service.spec.d.ts.map +1 -0
  181. package/lib/_services/dynamo-nts-shared.service.spec.js +12 -0
  182. package/lib/_services/dynamo-nts-shared.service.spec.js.map +1 -0
  183. package/lib/_services/dynamo-nts-singleton.service.d.ts +8 -8
  184. package/lib/_services/dynamo-nts-singleton.service.js +18 -18
  185. package/lib/_services/dynamo-nts-singleton.service.js.map +1 -1
  186. package/lib/_services/dynamo-nts-socket-service-collection.service.d.ts +9 -9
  187. package/lib/_services/dynamo-nts-socket-service-collection.service.js +13 -13
  188. package/lib/_services/dynamo-nts-socket.service.d.ts +57 -45
  189. package/lib/_services/dynamo-nts-socket.service.d.ts.map +1 -1
  190. package/lib/_services/dynamo-nts-socket.service.js +188 -165
  191. package/lib/_services/dynamo-nts-socket.service.js.map +1 -1
  192. package/lib/_services/index.d.ts +14 -16
  193. package/lib/_services/index.d.ts.map +1 -1
  194. package/lib/_services/index.js +20 -20
  195. package/lib/_services/index.js.map +1 -1
  196. package/lib/index.d.ts +6 -6
  197. package/lib/index.js +14 -14
  198. package/lib/tsconfig.tsbuildinfo +1 -1
  199. package/package SAVE.json +216 -0
  200. package/package-NEW with test but not working.json +228 -0
  201. package/package.json +15 -8
  202. package/spec/support/jasmine.json +14 -0
  203. package/src/_enums/http/socket-event.enum.ts +2 -1
  204. package/src/_interfaces/certification-settings.interface.ts +7 -0
  205. package/src/_interfaces/global-service-settings.interface.ts +23 -0
  206. package/src/_interfaces/index.ts +5 -0
  207. package/src/_interfaces/port-settings.interface.ts +5 -0
  208. package/src/_models/dynamo-nts-socket-event-params.ts +23 -21
  209. package/src/_models/{dynamo-nts-socket-dictionary.ts → dynamo-nts-socket-presence.ts} +21 -5
  210. package/src/_models/dynamo-nts-socket-service-params.ts +1 -0
  211. package/src/_models/index.ts +2 -2
  212. package/src/_modules/app-extended.index.ts +7 -2
  213. package/src/_modules/app.index.ts +5 -0
  214. package/src/_services/dynamo-nts-app-extended.ts +6 -2
  215. package/src/_services/dynamo-nts-app.spec.ts +14 -0
  216. package/src/_services/dynamo-nts-app.ts +8 -14
  217. package/src/_services/dynamo-nts-auth.service.ts +1 -0
  218. package/src/_services/dynamo-nts-controller.service.ts +2 -1
  219. package/src/_services/dynamo-nts-data.service.ts +16 -10
  220. package/src/_services/dynamo-nts-db.service.ts +8 -5
  221. package/src/_services/dynamo-nts-email.service.ts +1 -0
  222. package/src/_services/dynamo-nts-global.service.ts +3 -18
  223. package/src/_services/dynamo-nts-routing-module.service.ts +1 -0
  224. package/src/_services/dynamo-nts-shared.service.spec.ts +10 -0
  225. package/src/_services/dynamo-nts-shared.service.ts +2 -1
  226. package/src/_services/dynamo-nts-socket.service.ts +80 -41
  227. package/src/_services/index.ts +2 -2
@@ -1,372 +1,372 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DynamoNTS_App = void 0;
4
- const tslib_1 = require("tslib");
5
- const Mongoose = require("mongoose");
6
- const Express = require("express");
7
- const Https = tslib_1.__importStar(require("https"));
8
- const FileSystem = tslib_1.__importStar(require("fs"));
9
- const BodyParser = tslib_1.__importStar(require("body-parser"));
10
- const dynamo_nts_singleton_service_1 = require("./dynamo-nts-singleton.service");
11
- const dynamo_nts_route_security_enum_1 = require("../_enums/dynamo-nts-route-security.enum");
12
- const _constants_1 = require("../_constants");
13
- const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
14
- const dynamo_nts_global_service_1 = require("./dynamo-nts-global.service");
15
- /**
16
- * This will be the MAIN service of our server project,
17
- * follow the types and type instructions while setting up your project
18
- *
19
- * In this service, there are abstract functions that you will need to implement,
20
- * where you need to set up the main params for your application.
21
- *
22
- * (after the example, you can find the list of services you can/should setup)
23
- *
24
- * @example
25
- * export class App extends DynamoNTS_AppExtended {
26
- *
27
- * ...
28
- *
29
- * // Setting up App params, and preparing project global settings
30
- * setupAppParams(): void {
31
- * this.params = new DynamoNTS_AppParams({
32
- * name: 'Warbots Server',
33
- * title: warbotsTitleLog,
34
- * version: version,
35
- * dbName: 'warbots',
36
- * });
37
- *
38
- * // dynamoNTS_GlobalSettings.logRequestsContent = false;
39
- * }
40
- *
41
- * ...
42
- *
43
- * // Setting up DBServices
44
- * setGlobalServiceCollection(): void {
45
- * DynamoNTS_GlobalService.setServices({
46
- * authService: AuthService.getInstance(),
47
- * emailServiceCollection: EmailServiceCollectionService.getInstance(),
48
- * dbModels: [
49
- * userModelParams,
50
- * userDataModelParams,
51
- * userOptionsModelParams,
52
- * userStatisticsModelParams,
53
- * userAchievementsModelParams,
54
- * userNotificationsModelParams,
55
- *
56
- * matchStatisticsModelParams,
57
- * matchDataModelParams,
58
-
59
- * usageSessionModelParams,
60
- * customDataModelParams,
61
- * ]
62
- * });
63
- * }
64
- *
65
- * ...
66
- *
67
- * // Setting up Routes
68
- * setupRoutingModules(): void {
69
- * this.httpPort = env.port;
70
-
71
- * this.routingModules = [
72
- * new DynamoNTS_RoutingModule({
73
- * route: '/user',
74
- * controllers: [
75
- * UserController.getInstance(),
76
- * UserDataController.getInstance(),
77
- * UserOptionsController.getInstance(),
78
- * UserStatisticsController.getInstance(),
79
- * UserAchievementsController.getInstance(),
80
- * UserNotificationsController.getInstance()
81
- * ]
82
- * }),
83
- * new DynamoNTS_RoutingModule({
84
- * route: '/match',
85
- * controllers: [
86
- * MatchController.getInstance(),
87
- * MatchDistributionController.getInstance(),
88
- * MatchStatisticsController.getInstance(),
89
- * ]
90
- * }),
91
- * new DynamoNTS_RoutingModule({
92
- * route: '/server',
93
- * controllers: [
94
- * ServerController.getInstance(),
95
- * ]
96
- * }),
97
-
98
- * getTestRoutingModule(),
99
- * getUsageRoutingModule()
100
- * ];
101
- * }
102
- * }
103
- *
104
- * //
105
- * // The Services available
106
- * //
107
- * // Authentication Service
108
- * // A commonly used basic service,
109
- * // which is necessary fur certain functions (such as registering call issuers)
110
- * //
111
- * // This will handle Authentication Token checking/refreshing, checking issuer's identifier and routeParams,
112
- * // handling JWT Token, or maybe with OAuth2 or other commonly used security procedures
113
- * //
114
- * // You can create one with this Dynamo Object:
115
- * //
116
- *
117
- * @example
118
- * // follow the instructions on the abstract class (DynamoNTS_AuthService)
119
- * export class AuthService extends DynamoNTS_AuthService {}
120
- *
121
- *
122
- *
123
- * //
124
- */
125
- class DynamoNTS_App extends dynamo_nts_singleton_service_1.DynamoNTS_SingletonService {
126
- constructor() {
127
- var _a;
128
- super();
129
- this.mongoose = Mongoose;
130
- try {
131
- this._params = this.getAppParams();
132
- if (this.overrideDynamoNTSGlobalSettings) {
133
- this.overrideDynamoNTSGlobalSettings();
134
- }
135
- dynamo_nts_global_service_1.DynamoNTS_GlobalService.setServices(this.getGlobalServiceCollection());
136
- dynamo_nts_global_service_1.DynamoNTS_GlobalService.setParams(this.params);
137
- this._ports = this.getPortSettings();
138
- if (this.getCertificationSettings) {
139
- this._cert = this.getCertificationSettings();
140
- }
141
- this._routingModules = this.getRoutingModules();
142
- if (this.createEntries) {
143
- this.createEntries();
144
- }
145
- console.log(`\n\n\nStarting ${this._params.name}... `);
146
- if (this._params.title) {
147
- console.log(this._params.title);
148
- }
149
- console.log(`\nVersion: ${this._params.version}`);
150
- this.startDB();
151
- this.getGlobalServiceCollection();
152
- this.debugLog = _constants_1.dynamoNTS_GlobalSettings.logSetup;
153
- this.getRoutingModules();
154
- this.setSecurity();
155
- if ((_a = this._routingModules) === null || _a === void 0 ? void 0 : _a.length) {
156
- this.initExpresses();
157
- this.startExpresses();
158
- if (this._security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
159
- this.mountOpenRoutes();
160
- }
161
- if (this._security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.open && this._cert) {
162
- this.mountSecureRoutes();
163
- }
164
- if (this.debugLog) {
165
- console.log(`\nRoutes mounted.... server using security: ${this._security}`);
166
- }
167
- }
168
- if (this.postProcess) {
169
- this.postProcess();
170
- }
171
- }
172
- catch (error) {
173
- fsm_dynamo_1.Dynamo_Log.error('\nApplication start failed.\n', error);
174
- }
175
- }
176
- get params() { return this._params; }
177
- get security() { return this._security; }
178
- get ports() { return this._ports; }
179
- get cert() { return this._cert; }
180
- get routingModules() { return this._routingModules; }
181
- /**
182
- *
183
- */
184
- startDB() {
185
- this.mongoose.connection
186
- .on('error', (error) => {
187
- fsm_dynamo_1.Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
188
- })
189
- .once('open', () => {
190
- fsm_dynamo_1.Dynamo_Log.success('\nConnected to MongoDB\n');
191
- });
192
- this.mongoose.connect(this._params.dbUri, {
193
- useNewUrlParser: true,
194
- useUnifiedTopology: true
195
- });
196
- }
197
- /**
198
- *
199
- */
200
- initExpresses() {
201
- if (this._security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
202
- if (!this._ports.httpPort) {
203
- let errorMsg = `\nYou have open routes, but httpPort is not set!` +
204
- `\nsecurity: ${this._security}` +
205
- `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
206
- errorMsg += '\n\nThe routes setted to use open server:';
207
- this._routingModules.forEach((module) => {
208
- if (module.security != dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
209
- errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using open sever:`;
210
- module.endpoints.forEach((endpoint) => {
211
- if (endpoint.security != dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
212
- errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
213
- }
214
- });
215
- }
216
- });
217
- fsm_dynamo_1.Dynamo_Log.error(errorMsg);
218
- let error = new Error('Open routes cannot be established!');
219
- let errorStack = error.stack.split('\n');
220
- errorStack.splice(1, 2);
221
- error.stack = errorStack.join('\n');
222
- throw error;
223
- }
224
- this.initOpenExpress();
225
- }
226
- if (this._security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.open) {
227
- if (!this._cert || !this._ports.httpsPort) {
228
- let errorMsg = `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
229
- `\nsecurity: ${this._security}` +
230
- `\nset...` +
231
- `\n httpsPort and` +
232
- `\n cert: {` +
233
- `\n keyPath: FileSystem.PathLike,` +
234
- `\n certPath: FileSystem.PathLike,` +
235
- `\n }` +
236
- `\nin DynamoBEServer - setupRoutingModules() to enable secure routes.`;
237
- errorMsg += '\n\nThe routes setted to use secure server:';
238
- this._routingModules.forEach((module) => {
239
- if (module.security != dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.open) {
240
- errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using secure sever:`;
241
- module.endpoints.forEach((endpoint) => {
242
- if (endpoint.security != dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.open) {
243
- errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
244
- }
245
- });
246
- }
247
- });
248
- fsm_dynamo_1.Dynamo_Log.error(errorMsg);
249
- let error = new Error('Secure routes cannot be established!');
250
- let errorStack = error.stack.split('\n');
251
- errorStack.splice(1, 2);
252
- error.stack = errorStack.join('\n');
253
- throw error;
254
- }
255
- this.initSecureExpress();
256
- }
257
- }
258
- /**
259
- *
260
- */
261
- initOpenExpress() {
262
- this.openExpress = Express();
263
- this.openExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
264
- this.openExpress.use(BodyParser.json({ limit: '50mb' }));
265
- }
266
- /**
267
- *
268
- */
269
- initSecureExpress() {
270
- this.secureExpress = Express();
271
- this.secureExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
272
- this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
273
- const options = {
274
- key: FileSystem.readFileSync(this._cert.keyPath),
275
- cert: FileSystem.readFileSync(this._cert.certPath),
276
- };
277
- this.httpsServer = Https.createServer(options, this.secureExpress);
278
- }
279
- /**
280
- *
281
- */
282
- startExpresses() {
283
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
284
- try {
285
- if (this._security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.open) {
286
- this.httpsServer
287
- .listen(this._ports.httpsPort, 'localhost', 0, () => {
288
- fsm_dynamo_1.Dynamo_Log.success(`\nHTTPS (secure) server is listening on port ${this._ports.httpsPort}\n`);
289
- })
290
- .on('error', (error) => {
291
- fsm_dynamo_1.Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
292
- })
293
- .on('uncaughtException', (ex) => {
294
- fsm_dynamo_1.Dynamo_Log.warn(`\nHTTPS (secure) server uncaughtException`, ex);
295
- });
296
- }
297
- if (this._security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
298
- this.openExpress
299
- .listen(this._ports.httpPort, () => {
300
- fsm_dynamo_1.Dynamo_Log.success(`\nHTTP (-open-) server is listening on port ${this._ports.httpPort}\n`);
301
- })
302
- .on('error', (error) => {
303
- fsm_dynamo_1.Dynamo_Log.error(`\nHTTP (-open-) server ERROR`, error);
304
- })
305
- .on('uncaughtException', (ex) => {
306
- fsm_dynamo_1.Dynamo_Log.warn(`\nHTTP (-open-) server uncaughtException`, ex);
307
- });
308
- }
309
- }
310
- catch (error) {
311
- fsm_dynamo_1.Dynamo_Log.error(`startExpresses failed...`, error);
312
- }
313
- });
314
- }
315
- /**
316
- *
317
- */
318
- mountSecureRoutes() {
319
- this._routingModules.forEach((module) => {
320
- if (module.security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.open) {
321
- if (this.debugLog) {
322
- console.log(`route mount (secure): ${module.route}`);
323
- }
324
- const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
325
- if (1 < existingRoutes.length) {
326
- let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
327
- let errorStack = error.stack.split('\n');
328
- errorStack.splice(1, 4);
329
- error.stack = errorStack.join('\n');
330
- throw error;
331
- }
332
- this.secureExpress.use(module.route, module.secureRouter);
333
- }
334
- });
335
- }
336
- /**
337
- *
338
- */
339
- mountOpenRoutes() {
340
- this._routingModules.forEach((module) => {
341
- if (module.security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
342
- if (this.debugLog) {
343
- console.log(`route mount (open): ${module.route}`);
344
- }
345
- const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
346
- if (1 < existingRoutes.length) {
347
- let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
348
- let errorStack = error.stack.split('\n');
349
- errorStack.splice(1, 4);
350
- error.stack = errorStack.join('\n');
351
- throw error;
352
- }
353
- this.openExpress.use(module.route, module.openRouter);
354
- }
355
- });
356
- }
357
- /**
358
- *
359
- */
360
- setSecurity() {
361
- this._routingModules.forEach((module) => {
362
- if (!this._security) {
363
- this._security = module.security;
364
- }
365
- else if (this._security !== module.security) {
366
- this._security = dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.both;
367
- }
368
- });
369
- }
370
- }
371
- exports.DynamoNTS_App = DynamoNTS_App;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DynamoNTS_App = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const Mongoose = require("mongoose");
6
+ const Express = require("express");
7
+ const Https = tslib_1.__importStar(require("https"));
8
+ const FileSystem = tslib_1.__importStar(require("fs"));
9
+ const BodyParser = tslib_1.__importStar(require("body-parser"));
10
+ const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
11
+ const dynamo_nts_singleton_service_1 = require("./dynamo-nts-singleton.service");
12
+ const dynamo_nts_route_security_enum_1 = require("../_enums/dynamo-nts-route-security.enum");
13
+ const dynamo_nts_global_service_1 = require("./dynamo-nts-global.service");
14
+ const dynamo_nts_global_settings_1 = require("../_constants/dynamo-nts-global-settings");
15
+ /**
16
+ * This will be the MAIN service of our server project,
17
+ * follow the types and type instructions while setting up your project
18
+ *
19
+ * In this service, there are abstract functions that you will need to implement,
20
+ * where you need to set up the main params for your application.
21
+ *
22
+ * (after the example, you can find the list of services you can/should setup)
23
+ *
24
+ * @example
25
+ * export class App extends DynamoNTS_AppExtended {
26
+ *
27
+ * ...
28
+ *
29
+ * // Setting up App params, and preparing project global settings
30
+ * setupAppParams(): void {
31
+ * this.params = new DynamoNTS_AppParams({
32
+ * name: 'Warbots Server',
33
+ * title: warbotsTitleLog,
34
+ * version: version,
35
+ * dbName: 'warbots',
36
+ * });
37
+ *
38
+ * // dynamoNTS_GlobalSettings.logRequestsContent = false;
39
+ * }
40
+ *
41
+ * ...
42
+ *
43
+ * // Setting up DBServices
44
+ * setGlobalServiceCollection(): void {
45
+ * DynamoNTS_GlobalService.setServices({
46
+ * authService: AuthService.getInstance(),
47
+ * emailServiceCollection: EmailServiceCollectionService.getInstance(),
48
+ * dbModels: [
49
+ * userModelParams,
50
+ * userDataModelParams,
51
+ * userOptionsModelParams,
52
+ * userStatisticsModelParams,
53
+ * userAchievementsModelParams,
54
+ * userNotificationsModelParams,
55
+ *
56
+ * matchStatisticsModelParams,
57
+ * matchDataModelParams,
58
+
59
+ * usageSessionModelParams,
60
+ * customDataModelParams,
61
+ * ]
62
+ * });
63
+ * }
64
+ *
65
+ * ...
66
+ *
67
+ * // Setting up Routes
68
+ * setupRoutingModules(): void {
69
+ * this.httpPort = env.port;
70
+
71
+ * this.routingModules = [
72
+ * new DynamoNTS_RoutingModule({
73
+ * route: '/user',
74
+ * controllers: [
75
+ * UserController.getInstance(),
76
+ * UserDataController.getInstance(),
77
+ * UserOptionsController.getInstance(),
78
+ * UserStatisticsController.getInstance(),
79
+ * UserAchievementsController.getInstance(),
80
+ * UserNotificationsController.getInstance()
81
+ * ]
82
+ * }),
83
+ * new DynamoNTS_RoutingModule({
84
+ * route: '/match',
85
+ * controllers: [
86
+ * MatchController.getInstance(),
87
+ * MatchDistributionController.getInstance(),
88
+ * MatchStatisticsController.getInstance(),
89
+ * ]
90
+ * }),
91
+ * new DynamoNTS_RoutingModule({
92
+ * route: '/server',
93
+ * controllers: [
94
+ * ServerController.getInstance(),
95
+ * ]
96
+ * }),
97
+
98
+ * getTestRoutingModule(),
99
+ * getUsageRoutingModule()
100
+ * ];
101
+ * }
102
+ * }
103
+ *
104
+ * //
105
+ * // The Services available
106
+ * //
107
+ * // Authentication Service
108
+ * // A commonly used basic service,
109
+ * // which is necessary fur certain functions (such as registering call issuers)
110
+ * //
111
+ * // This will handle Authentication Token checking/refreshing, checking issuer's identifier and routeParams,
112
+ * // handling JWT Token, or maybe with OAuth2 or other commonly used security procedures
113
+ * //
114
+ * // You can create one with this Dynamo Object:
115
+ * //
116
+ *
117
+ * @example
118
+ * // follow the instructions on the abstract class (DynamoNTS_AuthService)
119
+ * export class AuthService extends DynamoNTS_AuthService {}
120
+ *
121
+ *
122
+ *
123
+ * //
124
+ */
125
+ class DynamoNTS_App extends dynamo_nts_singleton_service_1.DynamoNTS_SingletonService {
126
+ get params() { return this._params; }
127
+ get security() { return this._security; }
128
+ get ports() { return this._ports; }
129
+ get cert() { return this._cert; }
130
+ get routingModules() { return this._routingModules; }
131
+ constructor() {
132
+ var _a;
133
+ super();
134
+ this.mongoose = Mongoose;
135
+ try {
136
+ this._params = this.getAppParams();
137
+ if (this.overrideDynamoNTSGlobalSettings) {
138
+ this.overrideDynamoNTSGlobalSettings();
139
+ }
140
+ dynamo_nts_global_service_1.DynamoNTS_GlobalService.setServices(this.getGlobalServiceCollection());
141
+ dynamo_nts_global_service_1.DynamoNTS_GlobalService.setParams(this.params);
142
+ this._ports = this.getPortSettings();
143
+ if (this.getCertificationSettings) {
144
+ this._cert = this.getCertificationSettings();
145
+ }
146
+ this._routingModules = this.getRoutingModules();
147
+ if (this.createEntries) {
148
+ this.createEntries();
149
+ }
150
+ console.log(`\n\n\nStarting ${this._params.name}... `);
151
+ if (this._params.title) {
152
+ console.log(this._params.title);
153
+ }
154
+ console.log(`\nVersion: ${this._params.version}`);
155
+ this.startDB();
156
+ this.getGlobalServiceCollection();
157
+ this.debugLog = dynamo_nts_global_settings_1.dynamoNTS_GlobalSettings.logSetup;
158
+ this.getRoutingModules();
159
+ this.setSecurity();
160
+ if ((_a = this._routingModules) === null || _a === void 0 ? void 0 : _a.length) {
161
+ this.initExpresses();
162
+ this.startExpresses();
163
+ if (this._security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
164
+ this.mountOpenRoutes();
165
+ }
166
+ if (this._security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.open && this._cert) {
167
+ this.mountSecureRoutes();
168
+ }
169
+ if (this.debugLog) {
170
+ console.log(`\nRoutes mounted.... server using security: ${this._security}`);
171
+ }
172
+ }
173
+ if (this.postProcess) {
174
+ this.postProcess();
175
+ }
176
+ }
177
+ catch (error) {
178
+ fsm_dynamo_1.Dynamo_Log.error('\nApplication start failed.\n', error);
179
+ }
180
+ }
181
+ /**
182
+ *
183
+ */
184
+ startDB() {
185
+ this.mongoose.connection
186
+ .on('error', (error) => {
187
+ fsm_dynamo_1.Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
188
+ })
189
+ .once('open', () => {
190
+ fsm_dynamo_1.Dynamo_Log.success('\nConnected to MongoDB\n');
191
+ });
192
+ this.mongoose.connect(this._params.dbUri, {
193
+ useNewUrlParser: true,
194
+ useUnifiedTopology: true
195
+ });
196
+ }
197
+ /**
198
+ *
199
+ */
200
+ initExpresses() {
201
+ if (this._security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
202
+ if (!this._ports.httpPort) {
203
+ let errorMsg = `\nYou have open routes, but httpPort is not set!` +
204
+ `\nsecurity: ${this._security}` +
205
+ `\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
206
+ errorMsg += '\n\nThe routes setted to use open server:';
207
+ this._routingModules.forEach((module) => {
208
+ if (module.security != dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
209
+ errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using open sever:`;
210
+ module.endpoints.forEach((endpoint) => {
211
+ if (endpoint.security != dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
212
+ errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
213
+ }
214
+ });
215
+ }
216
+ });
217
+ fsm_dynamo_1.Dynamo_Log.error(errorMsg);
218
+ let error = new Error('Open routes cannot be established!');
219
+ let errorStack = error.stack.split('\n');
220
+ errorStack.splice(1, 2);
221
+ error.stack = errorStack.join('\n');
222
+ throw error;
223
+ }
224
+ this.initOpenExpress();
225
+ }
226
+ if (this._security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.open) {
227
+ if (!this._cert || !this._ports.httpsPort) {
228
+ let errorMsg = `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
229
+ `\nsecurity: ${this._security}` +
230
+ `\nset...` +
231
+ `\n httpsPort and` +
232
+ `\n cert: {` +
233
+ `\n keyPath: FileSystem.PathLike,` +
234
+ `\n certPath: FileSystem.PathLike,` +
235
+ `\n }` +
236
+ `\nin DynamoBEServer - setupRoutingModules() to enable secure routes.`;
237
+ errorMsg += '\n\nThe routes setted to use secure server:';
238
+ this._routingModules.forEach((module) => {
239
+ if (module.security != dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.open) {
240
+ errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using secure sever:`;
241
+ module.endpoints.forEach((endpoint) => {
242
+ if (endpoint.security != dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.open) {
243
+ errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
244
+ }
245
+ });
246
+ }
247
+ });
248
+ fsm_dynamo_1.Dynamo_Log.error(errorMsg);
249
+ let error = new Error('Secure routes cannot be established!');
250
+ let errorStack = error.stack.split('\n');
251
+ errorStack.splice(1, 2);
252
+ error.stack = errorStack.join('\n');
253
+ throw error;
254
+ }
255
+ this.initSecureExpress();
256
+ }
257
+ }
258
+ /**
259
+ *
260
+ */
261
+ initOpenExpress() {
262
+ this.openExpress = Express();
263
+ this.openExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
264
+ this.openExpress.use(BodyParser.json({ limit: '50mb' }));
265
+ }
266
+ /**
267
+ *
268
+ */
269
+ initSecureExpress() {
270
+ this.secureExpress = Express();
271
+ this.secureExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
272
+ this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
273
+ const options = {
274
+ key: FileSystem.readFileSync(this._cert.keyPath),
275
+ cert: FileSystem.readFileSync(this._cert.certPath),
276
+ };
277
+ this.httpsServer = Https.createServer(options, this.secureExpress);
278
+ }
279
+ /**
280
+ *
281
+ */
282
+ startExpresses() {
283
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
284
+ try {
285
+ if (this._security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.open) {
286
+ this.httpsServer
287
+ .listen(this._ports.httpsPort, 'localhost', 0, () => {
288
+ fsm_dynamo_1.Dynamo_Log.success(`\nHTTPS (secure) server is listening on port ${this._ports.httpsPort}\n`);
289
+ })
290
+ .on('error', (error) => {
291
+ fsm_dynamo_1.Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
292
+ })
293
+ .on('uncaughtException', (ex) => {
294
+ fsm_dynamo_1.Dynamo_Log.warn(`\nHTTPS (secure) server uncaughtException`, ex);
295
+ });
296
+ }
297
+ if (this._security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
298
+ this.openExpress
299
+ .listen(this._ports.httpPort, () => {
300
+ fsm_dynamo_1.Dynamo_Log.success(`\nHTTP (-open-) server is listening on port ${this._ports.httpPort}\n`);
301
+ })
302
+ .on('error', (error) => {
303
+ fsm_dynamo_1.Dynamo_Log.error(`\nHTTP (-open-) server ERROR`, error);
304
+ })
305
+ .on('uncaughtException', (ex) => {
306
+ fsm_dynamo_1.Dynamo_Log.warn(`\nHTTP (-open-) server uncaughtException`, ex);
307
+ });
308
+ }
309
+ }
310
+ catch (error) {
311
+ fsm_dynamo_1.Dynamo_Log.error(`startExpresses failed...`, error);
312
+ }
313
+ });
314
+ }
315
+ /**
316
+ *
317
+ */
318
+ mountSecureRoutes() {
319
+ this._routingModules.forEach((module) => {
320
+ if (module.security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.open) {
321
+ if (this.debugLog) {
322
+ console.log(`route mount (secure): ${module.route}`);
323
+ }
324
+ const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
325
+ if (1 < existingRoutes.length) {
326
+ let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
327
+ let errorStack = error.stack.split('\n');
328
+ errorStack.splice(1, 4);
329
+ error.stack = errorStack.join('\n');
330
+ throw error;
331
+ }
332
+ this.secureExpress.use(module.route, module.secureRouter);
333
+ }
334
+ });
335
+ }
336
+ /**
337
+ *
338
+ */
339
+ mountOpenRoutes() {
340
+ this._routingModules.forEach((module) => {
341
+ if (module.security !== dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
342
+ if (this.debugLog) {
343
+ console.log(`route mount (open): ${module.route}`);
344
+ }
345
+ const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
346
+ if (1 < existingRoutes.length) {
347
+ let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
348
+ let errorStack = error.stack.split('\n');
349
+ errorStack.splice(1, 4);
350
+ error.stack = errorStack.join('\n');
351
+ throw error;
352
+ }
353
+ this.openExpress.use(module.route, module.openRouter);
354
+ }
355
+ });
356
+ }
357
+ /**
358
+ *
359
+ */
360
+ setSecurity() {
361
+ this._routingModules.forEach((module) => {
362
+ if (!this._security) {
363
+ this._security = module.security;
364
+ }
365
+ else if (this._security !== module.security) {
366
+ this._security = dynamo_nts_route_security_enum_1.DynamoNTS_RouteSecurity.both;
367
+ }
368
+ });
369
+ }
370
+ }
371
+ exports.DynamoNTS_App = DynamoNTS_App;
372
372
  //# sourceMappingURL=dynamo-nts-app.js.map