@futdevpro/nts-dynamo 1.6.19 → 1.6.21
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 +41 -0
- package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -0
- package/lib/_constants/mocks/app-extended-server.mock.js +168 -0
- package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -0
- package/lib/_constants/mocks/app-server.mock.d.ts +1 -1
- package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/app-server.mock.js +12 -5
- package/lib/_constants/mocks/app-server.mock.js.map +1 -1
- package/lib/_constants/mocks/data-model.mock.d.ts +27 -0
- package/lib/_constants/mocks/data-model.mock.d.ts.map +1 -0
- package/lib/_constants/mocks/data-model.mock.js +57 -0
- package/lib/_constants/mocks/data-model.mock.js.map +1 -0
- package/lib/_constants/mocks/email-service-collection.mock.d.ts +7 -0
- package/lib/_constants/mocks/email-service-collection.mock.d.ts.map +1 -0
- package/lib/_constants/mocks/email-service-collection.mock.js +16 -0
- package/lib/_constants/mocks/email-service-collection.mock.js.map +1 -0
- package/lib/_constants/mocks/email-service.mock.d.ts +5 -0
- package/lib/_constants/mocks/email-service.mock.d.ts.map +1 -0
- package/lib/_constants/mocks/email-service.mock.js +21 -0
- package/lib/_constants/mocks/email-service.mock.js.map +1 -0
- package/lib/_constants/mocks/socket-client.mock.d.ts +9 -0
- package/lib/_constants/mocks/socket-client.mock.d.ts.map +1 -0
- package/lib/_constants/mocks/socket-client.mock.js +39 -0
- package/lib/_constants/mocks/socket-client.mock.js.map +1 -0
- package/lib/_constants/mocks/socket-server.mock.d.ts +1 -0
- package/lib/_constants/mocks/socket-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.js +4 -1
- package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model copy.d.ts +7 -0
- package/lib/_models/control-models/app-system-controls.control-model copy.d.ts.map +1 -0
- package/lib/_models/control-models/app-system-controls.control-model copy.js +13 -0
- package/lib/_models/control-models/app-system-controls.control-model copy.js.map +1 -0
- package/lib/_models/control-models/app-system-controls.control-model.d.ts +8 -0
- package/lib/_models/control-models/app-system-controls.control-model.d.ts.map +1 -0
- package/lib/_models/control-models/app-system-controls.control-model.js +14 -0
- package/lib/_models/control-models/app-system-controls.control-model.js.map +1 -0
- package/lib/_models/control-models/system-control.control-model.d.ts +6 -0
- package/lib/_models/control-models/system-control.control-model.d.ts.map +1 -0
- package/lib/_models/control-models/system-control.control-model.js +15 -0
- package/lib/_models/control-models/system-control.control-model.js.map +1 -0
- package/lib/_services/base/db.service.d.ts +1 -2
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +23 -15
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/core/email.service.d.ts.map +1 -1
- package/lib/_services/core/email.service.js +0 -1
- package/lib/_services/core/email.service.js.map +1 -1
- package/lib/_services/server/app-extended.server.d.ts +9 -0
- package/lib/_services/server/app-extended.server.d.ts.map +1 -1
- package/lib/_services/server/app-extended.server.js +228 -81
- package/lib/_services/server/app-extended.server.js.map +1 -1
- package/lib/_services/server/app-extended.server.spec.d.ts +2 -0
- package/lib/_services/server/app-extended.server.spec.d.ts.map +1 -0
- package/lib/_services/server/app-extended.server.spec.js +55 -0
- package/lib/_services/server/app-extended.server.spec.js.map +1 -0
- package/lib/_services/server/app.server.d.ts +17 -17
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +382 -258
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/server/app.server.spec.js +17 -5
- package/lib/_services/server/app.server.spec.js.map +1 -1
- package/lib/_services/shared.service.spec.js +7 -1
- package/lib/_services/shared.service.spec.js.map +1 -1
- package/lib/_services/socket/socket-server.service.d.ts +5 -3
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +32 -7
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/_constants/mocks/app-extended-server.mock.ts +191 -0
- package/src/_constants/mocks/app-server.mock.ts +10 -5
- package/src/_constants/mocks/data-model.mock.ts +83 -0
- package/src/_constants/mocks/email-service-collection.mock.ts +12 -0
- package/src/_constants/mocks/email-service.mock.ts +19 -0
- package/src/_constants/mocks/email-template.mock.html +15 -0
- package/src/_constants/mocks/socket-client.mock.ts +42 -0
- package/src/_constants/mocks/socket-server.mock.ts +5 -1
- package/src/_models/control-models/app-system-controls.control-model copy.ts +9 -0
- package/src/_models/control-models/app-system-controls.control-model.ts +9 -0
- package/src/_models/control-models/system-control.control-model.ts +13 -0
- package/src/_services/base/db.service.ts +25 -15
- package/src/_services/core/email.service.ts +0 -1
- package/src/_services/server/app-extended.server.spec.ts +66 -0
- package/src/_services/server/app-extended.server.ts +205 -41
- package/src/_services/server/app.server.spec.ts +17 -7
- package/src/_services/server/app.server.ts +284 -165
- package/src/_services/shared.service.spec.ts +10 -1
- package/src/_services/socket/socket-server.service.ts +36 -12
|
@@ -12,6 +12,7 @@ const singleton_service_1 = require("../base/singleton.service");
|
|
|
12
12
|
const route_security_enum_1 = require("../../_enums/route-security.enum");
|
|
13
13
|
const global_service_1 = require("../core/global.service");
|
|
14
14
|
const global_settings_const_1 = require("../../_constants/global-settings.const");
|
|
15
|
+
const app_system_controls_control_model_1 = require("../../_models/control-models/app-system-controls.control-model");
|
|
15
16
|
/**
|
|
16
17
|
* This will be the MAIN service of our server project,
|
|
17
18
|
* follow the types and type instructions while setting up your project
|
|
@@ -168,160 +169,213 @@ const global_settings_const_1 = require("../../_constants/global-settings.const"
|
|
|
168
169
|
*
|
|
169
170
|
*/
|
|
170
171
|
class DynamoNTS_App extends singleton_service_1.DynamoNTS_SingletonService {
|
|
172
|
+
get started() { return this.systemControls.app.started; }
|
|
173
|
+
get superStarted() { return this.systemControls.app.started; }
|
|
171
174
|
get serverName() { return this.params.name; }
|
|
172
175
|
get params() { return this._params; }
|
|
173
176
|
get security() { return this._security; }
|
|
174
177
|
get ports() { return this._ports; }
|
|
175
178
|
get cert() { return this._cert; }
|
|
176
|
-
constructor() {
|
|
177
|
-
var _a;
|
|
179
|
+
constructor(extended) {
|
|
178
180
|
super();
|
|
179
|
-
this.
|
|
180
|
-
this.initDone = false;
|
|
181
|
-
this.haveMongoose = false;
|
|
182
|
-
this.mongooseStarted = false;
|
|
183
|
-
this.haveHttpServer = false;
|
|
184
|
-
this.httpServerStarted = false;
|
|
185
|
-
this.haveHttpsServer = false;
|
|
186
|
-
this.httpsServerStarted = false;
|
|
181
|
+
this.systemControls = new app_system_controls_control_model_1.DynamoNTS_AppSystemControls();
|
|
187
182
|
this.constructErrors = [];
|
|
188
183
|
this.mongoose = Mongoose;
|
|
189
184
|
this._routingModules = [];
|
|
190
185
|
/* protected get routingModules(): DynamoNTS_RoutingModule[] { return this._routingModules; } */
|
|
191
186
|
this._rootServices = [];
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
this.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
this.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
if (this.getRoutingModules) {
|
|
207
|
-
this._routingModules = this.getRoutingModules();
|
|
208
|
-
}
|
|
209
|
-
if (this.createEntries) {
|
|
210
|
-
this.createEntries();
|
|
211
|
-
}
|
|
212
|
-
console.log(`\n\n\nStarting ${this._params.name}... `);
|
|
213
|
-
if (this._params.title) {
|
|
214
|
-
console.log(this._params.title);
|
|
215
|
-
}
|
|
216
|
-
console.log(`Version: ${this._params.version}\n`);
|
|
217
|
-
this.startDB();
|
|
218
|
-
this.getGlobalServiceCollection();
|
|
219
|
-
this.debugLog = global_settings_const_1.dynamoNTS_globalSettings.logSetup;
|
|
220
|
-
this.setSecurity();
|
|
221
|
-
if ((_a = this._routingModules) === null || _a === void 0 ? void 0 : _a.length) {
|
|
222
|
-
this.initExpresses();
|
|
223
|
-
this.startExpresses();
|
|
224
|
-
if (this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
225
|
-
this.mountOpenRoutes();
|
|
187
|
+
this.asyncConstruct(extended);
|
|
188
|
+
}
|
|
189
|
+
asyncConstruct(extended) {
|
|
190
|
+
var _a;
|
|
191
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
if (this.logFn && this.deepLog)
|
|
193
|
+
console.log('\nfn:. asyncConstruct');
|
|
194
|
+
try {
|
|
195
|
+
this.systemControls.app.init = true;
|
|
196
|
+
this.logSetup = global_settings_const_1.dynamoNTS_globalSettings.logSetup;
|
|
197
|
+
this._params = this.getAppParams();
|
|
198
|
+
if (this.overrideDynamoNTSGlobalSettings) {
|
|
199
|
+
this.overrideDynamoNTSGlobalSettings();
|
|
226
200
|
}
|
|
227
|
-
|
|
228
|
-
|
|
201
|
+
this.globalService = global_service_1.DynamoNTS_GlobalService.getInstance();
|
|
202
|
+
global_service_1.DynamoNTS_GlobalService.setServices(this.getGlobalServiceCollection());
|
|
203
|
+
global_service_1.DynamoNTS_GlobalService.setParams(this.params);
|
|
204
|
+
if (this.getPortSettings) {
|
|
205
|
+
this._ports = this.getPortSettings();
|
|
229
206
|
}
|
|
230
|
-
if (this.
|
|
231
|
-
|
|
207
|
+
if (this.getCertificationSettings) {
|
|
208
|
+
this._cert = this.getCertificationSettings();
|
|
209
|
+
}
|
|
210
|
+
if (this.getRoutingModules) {
|
|
211
|
+
this._routingModules = this.getRoutingModules();
|
|
212
|
+
}
|
|
213
|
+
if (this.createEntries) {
|
|
214
|
+
yield this.createEntries();
|
|
215
|
+
}
|
|
216
|
+
console.log(`\n\n\nStarting ${this._params.name}... `);
|
|
217
|
+
if (this._params.title) {
|
|
218
|
+
console.log(this._params.title);
|
|
219
|
+
}
|
|
220
|
+
console.log(`Version: ${this._params.version}\n`);
|
|
221
|
+
yield this.startDB();
|
|
222
|
+
this.setSecurity();
|
|
223
|
+
if ((_a = this._routingModules) === null || _a === void 0 ? void 0 : _a.length) {
|
|
224
|
+
yield this.initExpresses();
|
|
225
|
+
yield this.startExpresses();
|
|
226
|
+
if (this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
227
|
+
yield this.mountOpenRoutes();
|
|
228
|
+
}
|
|
229
|
+
if (this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open && this._cert) {
|
|
230
|
+
yield this.mountSecureRoutes();
|
|
231
|
+
}
|
|
232
|
+
if (this.logSetup) {
|
|
233
|
+
console.log(`\nRoutes mounted.... server using security: ${this._security}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (this.getRootServices) {
|
|
237
|
+
this._rootServices = yield this.getRootServices();
|
|
238
|
+
}
|
|
239
|
+
if (this.postProcess) {
|
|
240
|
+
yield this.postProcess();
|
|
241
|
+
}
|
|
242
|
+
if (!extended) {
|
|
243
|
+
yield this.ready();
|
|
244
|
+
fsm_dynamo_1.Dynamo_Log.test(`${this._params.name} started successfully.`);
|
|
232
245
|
}
|
|
233
246
|
}
|
|
234
|
-
|
|
235
|
-
this.
|
|
236
|
-
|
|
237
|
-
if (this.postProcess) {
|
|
238
|
-
this.postProcess();
|
|
247
|
+
catch (error) {
|
|
248
|
+
this.constructErrors.push(error);
|
|
249
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nApplication: ${this._params.name} start failed.\n`, error);
|
|
239
250
|
}
|
|
240
|
-
|
|
241
|
-
this.ready();
|
|
242
|
-
}
|
|
243
|
-
catch (error) {
|
|
244
|
-
this.constructErrors.push(error);
|
|
245
|
-
fsm_dynamo_1.Dynamo_Log.error('\nApplication start failed.\n', error);
|
|
246
|
-
}
|
|
251
|
+
});
|
|
247
252
|
}
|
|
248
253
|
ready(timeout = 4 * fsm_dynamo_1.second) {
|
|
254
|
+
var _a, _b;
|
|
249
255
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
256
|
+
if (this.logFn)
|
|
257
|
+
console.log('\nfn:. ready');
|
|
258
|
+
let ready = false;
|
|
259
|
+
const start = +new Date();
|
|
260
|
+
if (this.constructErrors.length) {
|
|
261
|
+
fsm_dynamo_1.Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
|
|
262
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
263
|
+
message: `${this._params.name} start failed. ERRORS`,
|
|
264
|
+
additionalContent: this.constructErrors.length === 1 ? this.constructErrors[0] : { errors: this.constructErrors },
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
while (!ready && +new Date() - start < timeout) {
|
|
268
|
+
if (this.systemControls.app.init) {
|
|
269
|
+
ready = (this.systemControls.mongoose.getReady() &&
|
|
270
|
+
this.systemControls.httpServer.getReady() &&
|
|
271
|
+
this.systemControls.httpsServer.getReady());
|
|
266
272
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
273
|
+
yield (0, fsm_dynamo_1.wait)(100);
|
|
274
|
+
}
|
|
275
|
+
if (timeout < +new Date() - start) {
|
|
276
|
+
fsm_dynamo_1.Dynamo_Log.error(`${this._params.name} start failed. TIMEOUT`, this.constructErrors);
|
|
277
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
278
|
+
message: `${this._params.name} start failed. TIMEOUT`,
|
|
279
|
+
additionalContent: {
|
|
280
|
+
constructErrors: this.constructErrors,
|
|
281
|
+
systemControls: this.systemControls,
|
|
282
|
+
systemReadies: {
|
|
283
|
+
mongoose: this.systemControls.mongoose.getReady(),
|
|
284
|
+
httpServer: this.systemControls.httpServer.getReady(),
|
|
285
|
+
httpsServer: this.systemControls.httpsServer.getReady(),
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
if (this.constructErrors.length) {
|
|
291
|
+
fsm_dynamo_1.Dynamo_Log.error(`${this._params.name} start failed. ERROR`, this.constructErrors);
|
|
292
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
293
|
+
message: `${this._params.name} start failed. ERROR`,
|
|
294
|
+
additionalContent: this.constructErrors,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
if (ready) {
|
|
298
|
+
this.systemControls.app.started = true;
|
|
299
|
+
if (this.logFn && this.deepLog)
|
|
300
|
+
console.log('\nfn:. ready: return');
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
this.systemControls.app.started = false;
|
|
305
|
+
let msg = `${this._params.name} start failed. UNKNOWN`;
|
|
306
|
+
if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
|
|
307
|
+
msg += `\nMongoose start failed.`;
|
|
272
308
|
}
|
|
273
|
-
if (
|
|
274
|
-
|
|
275
|
-
resolve();
|
|
309
|
+
if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
|
|
310
|
+
msg += `\nHTTP Server start failed.`;
|
|
276
311
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
let msg = 'Application start failed. TIMEOUT';
|
|
280
|
-
if (this.haveMongoose && !this.mongooseStarted) {
|
|
281
|
-
msg += '\nMongoose start failed.';
|
|
282
|
-
}
|
|
283
|
-
if (this.haveHttpServer && !this.httpServerStarted) {
|
|
284
|
-
msg += '\nHTTP Server start failed.';
|
|
285
|
-
}
|
|
286
|
-
if (this.haveHttpsServer && !this.httpsServerStarted) {
|
|
287
|
-
msg += '\nHTTPS Server start failed.';
|
|
288
|
-
}
|
|
289
|
-
reject({
|
|
290
|
-
message: 'Application start failed. TIMEOUT',
|
|
291
|
-
errors: this.constructErrors
|
|
292
|
-
});
|
|
312
|
+
if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
|
|
313
|
+
msg += `\nHTTPS Server start failed.`;
|
|
293
314
|
}
|
|
294
|
-
|
|
315
|
+
fsm_dynamo_1.Dynamo_Log.error(msg, this.constructErrors);
|
|
316
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
317
|
+
errorCode: 'NTS-AS0-110',
|
|
318
|
+
message: msg,
|
|
319
|
+
additionalContent: {
|
|
320
|
+
constructErrors: this.constructErrors,
|
|
321
|
+
systemControls: this.systemControls,
|
|
322
|
+
systemReadies: {
|
|
323
|
+
app: this.systemControls.app.getReady(),
|
|
324
|
+
mongoose: this.systemControls.mongoose.getReady(),
|
|
325
|
+
httpServer: this.systemControls.httpServer.getReady(),
|
|
326
|
+
httpsServer: this.systemControls.httpsServer.getReady(),
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
error: (_b = (_a = this.constructErrors) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : new Error(),
|
|
330
|
+
});
|
|
331
|
+
}
|
|
295
332
|
});
|
|
296
333
|
}
|
|
297
|
-
stop() {
|
|
334
|
+
stop(dontLog) {
|
|
298
335
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
336
|
+
if (this.logFn)
|
|
337
|
+
console.log('\nfn:. stop');
|
|
299
338
|
if (this.started) {
|
|
300
|
-
if (this.
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
339
|
+
if (this.systemControls.mongoose.init) {
|
|
340
|
+
this.systemControls.mongoose.started = false;
|
|
341
|
+
if (this.mongoose) {
|
|
342
|
+
yield fsm_dynamo_1.Dynamo_Array.asyncForEach(Object.keys(this.mongoose.models), (modelName) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
343
|
+
yield this.mongoose.deleteModel(modelName);
|
|
344
|
+
}));
|
|
345
|
+
yield this.mongoose.disconnect();
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nMongoose not found.`);
|
|
349
|
+
}
|
|
350
|
+
this.systemControls.mongoose.init = false;
|
|
304
351
|
}
|
|
305
|
-
if (this.
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
352
|
+
if (this.systemControls.httpServer.init) {
|
|
353
|
+
this.systemControls.httpServer.started = false;
|
|
354
|
+
if (this.httpServer) {
|
|
355
|
+
yield new Promise((resolve) => {
|
|
356
|
+
this.httpServer.close(resolve);
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nHTTP Server not found.`);
|
|
361
|
+
}
|
|
362
|
+
this.systemControls.httpServer.init = false;
|
|
309
363
|
}
|
|
310
|
-
if (this.
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
364
|
+
if (this.systemControls.httpsServer.init) {
|
|
365
|
+
this.systemControls.httpsServer.started = false;
|
|
366
|
+
if (this.httpsServer) {
|
|
367
|
+
yield new Promise((resolve) => {
|
|
368
|
+
this.httpsServer.close(resolve);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nHTTPS Server not found.`);
|
|
373
|
+
}
|
|
374
|
+
this.systemControls.httpsServer.init = false;
|
|
375
|
+
}
|
|
376
|
+
if (!dontLog) {
|
|
377
|
+
fsm_dynamo_1.Dynamo_Log.test(`${this._params.name} stopped successfully.`);
|
|
315
378
|
}
|
|
316
|
-
this.initDone = false;
|
|
317
|
-
this.haveHttpServer = false;
|
|
318
|
-
this.haveHttpsServer = false;
|
|
319
|
-
this.haveMongoose = false;
|
|
320
|
-
this.mongooseStarted = false;
|
|
321
|
-
this.httpServerStarted = false;
|
|
322
|
-
this.httpsServerStarted = false;
|
|
323
|
-
this.started = false;
|
|
324
|
-
fsm_dynamo_1.Dynamo_Log.success('\nServer stopped.\n');
|
|
325
379
|
}
|
|
326
380
|
});
|
|
327
381
|
}
|
|
@@ -329,140 +383,190 @@ class DynamoNTS_App extends singleton_service_1.DynamoNTS_SingletonService {
|
|
|
329
383
|
*
|
|
330
384
|
*/
|
|
331
385
|
startDB() {
|
|
332
|
-
this
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
this
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
386
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
387
|
+
if (this.logFn && this.deepLog)
|
|
388
|
+
console.log('\nfn:. startDB');
|
|
389
|
+
yield new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
390
|
+
this.systemControls.mongoose.init = true;
|
|
391
|
+
this.mongoose.connection
|
|
392
|
+
.on('error', (error) => {
|
|
393
|
+
this.systemControls.mongoose.started = false;
|
|
394
|
+
this.constructErrors.push(error);
|
|
395
|
+
fsm_dynamo_1.Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
|
|
396
|
+
reject(new fsm_dynamo_1.Dynamo_Error({
|
|
397
|
+
errorCode: 'NTS-AS0-100',
|
|
398
|
+
message: `Unable to connect to MongoDB server, ERROR: ${error}`,
|
|
399
|
+
error: error,
|
|
400
|
+
}));
|
|
401
|
+
})
|
|
402
|
+
.once('open', () => {
|
|
403
|
+
this.systemControls.mongoose.started = true;
|
|
404
|
+
fsm_dynamo_1.Dynamo_Log.success('\nConnected to MongoDB\n');
|
|
405
|
+
resolve();
|
|
406
|
+
});
|
|
407
|
+
this.mongoose.connect(this._params.dbUri, {
|
|
408
|
+
useNewUrlParser: true,
|
|
409
|
+
useUnifiedTopology: true
|
|
410
|
+
});
|
|
411
|
+
}));
|
|
346
412
|
});
|
|
347
413
|
}
|
|
348
414
|
/**
|
|
349
415
|
*
|
|
350
416
|
*/
|
|
351
417
|
initExpresses() {
|
|
352
|
-
|
|
353
|
-
if (
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
418
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
419
|
+
if (this.logFn && this.deepLog)
|
|
420
|
+
console.log('\nfn:. initExpresses');
|
|
421
|
+
if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
422
|
+
if (!this._ports.httpPort) {
|
|
423
|
+
let errorMsg = `\nYou have open routes, but httpPort is not set!` +
|
|
424
|
+
`\nsecurity: ${this._security}` +
|
|
425
|
+
`\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
|
|
426
|
+
errorMsg += '\n\nThe routes setted to use open server:';
|
|
427
|
+
this._routingModules.forEach((module) => {
|
|
428
|
+
if (module.security != route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
429
|
+
errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using open sever:`;
|
|
430
|
+
module.endpoints.forEach((endpoint) => {
|
|
431
|
+
if (endpoint.security != route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
432
|
+
errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
fsm_dynamo_1.Dynamo_Log.error(errorMsg);
|
|
438
|
+
let error = new Error('Open routes cannot be established!');
|
|
439
|
+
let errorStack = error.stack.split('\n');
|
|
440
|
+
errorStack.splice(1, 2);
|
|
441
|
+
error.stack = errorStack.join('\n');
|
|
442
|
+
throw error;
|
|
443
|
+
}
|
|
444
|
+
yield this.initOpenExpress();
|
|
374
445
|
}
|
|
375
|
-
this.
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
446
|
+
if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
|
|
447
|
+
if (!this._cert || !this._ports.httpsPort) {
|
|
448
|
+
let errorMsg = `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
|
|
449
|
+
`\nsecurity: ${this._security}` +
|
|
450
|
+
`\nset...` +
|
|
451
|
+
`\n httpsPort and` +
|
|
452
|
+
`\n cert: {` +
|
|
453
|
+
`\n keyPath: FileSystem.PathLike,` +
|
|
454
|
+
`\n certPath: FileSystem.PathLike,` +
|
|
455
|
+
`\n }` +
|
|
456
|
+
`\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
|
|
457
|
+
errorMsg += '\n\nThe routes setted to use secure server:';
|
|
458
|
+
this._routingModules.forEach((module) => {
|
|
459
|
+
if (module.security && module.security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
|
|
460
|
+
errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using secure sever:`;
|
|
461
|
+
module.endpoints.forEach((endpoint) => {
|
|
462
|
+
if (endpoint.security && endpoint.security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
|
|
463
|
+
errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
fsm_dynamo_1.Dynamo_Log.error(errorMsg);
|
|
469
|
+
let error = new Error('Secure routes cannot be established!');
|
|
470
|
+
let errorStack = error.stack.split('\n');
|
|
471
|
+
errorStack.splice(1, 2);
|
|
472
|
+
error.stack = errorStack.join('\n');
|
|
473
|
+
throw error;
|
|
474
|
+
}
|
|
475
|
+
yield this.initSecureExpress();
|
|
405
476
|
}
|
|
406
|
-
|
|
407
|
-
}
|
|
477
|
+
});
|
|
408
478
|
}
|
|
409
479
|
/**
|
|
410
480
|
*
|
|
411
481
|
*/
|
|
412
482
|
initOpenExpress() {
|
|
413
|
-
this
|
|
414
|
-
|
|
415
|
-
|
|
483
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
484
|
+
if (this.logFn)
|
|
485
|
+
console.log('\nfn:. initOpenExpress');
|
|
486
|
+
this.openExpress = Express();
|
|
487
|
+
this.openExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
|
|
488
|
+
this.openExpress.use(BodyParser.json({ limit: '50mb' }));
|
|
489
|
+
});
|
|
416
490
|
}
|
|
417
491
|
/**
|
|
418
492
|
*
|
|
419
493
|
*/
|
|
420
494
|
initSecureExpress() {
|
|
421
|
-
this
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
495
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
496
|
+
if (this.logFn)
|
|
497
|
+
console.log('\nfn:. initSecureExpress');
|
|
498
|
+
this.secureExpress = Express();
|
|
499
|
+
this.secureExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
|
|
500
|
+
this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
|
|
501
|
+
const options = {
|
|
502
|
+
key: FileSystem.readFileSync(this._cert.keyPath),
|
|
503
|
+
cert: FileSystem.readFileSync(this._cert.certPath),
|
|
504
|
+
};
|
|
505
|
+
this.httpsServer = Https.createServer(options, this.secureExpress);
|
|
506
|
+
});
|
|
429
507
|
}
|
|
430
508
|
/**
|
|
431
509
|
*
|
|
432
510
|
*/
|
|
433
511
|
startExpresses() {
|
|
434
512
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
513
|
+
if (this.logFn && this.deepLog)
|
|
514
|
+
console.log('\nfn:. startExpresses');
|
|
435
515
|
try {
|
|
436
516
|
if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
517
|
+
yield new Promise((resolve, reject) => {
|
|
518
|
+
this.systemControls.httpsServer.init = true;
|
|
519
|
+
this.httpsServer
|
|
520
|
+
.listen(this._ports.httpsPort, 'localhost', 0, () => {
|
|
521
|
+
this.systemControls.httpsServer.started = true;
|
|
522
|
+
fsm_dynamo_1.Dynamo_Log.success(`\nHTTPS (secure) server is listening on port ${this._ports.httpsPort}`);
|
|
523
|
+
resolve();
|
|
524
|
+
})
|
|
525
|
+
.on('error', (error) => {
|
|
526
|
+
this.systemControls.httpsServer.started = false;
|
|
527
|
+
this.constructErrors.push(error);
|
|
528
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
|
|
529
|
+
reject(new fsm_dynamo_1.Dynamo_Error({
|
|
530
|
+
errorCode: 'NTS-AS0-001',
|
|
531
|
+
message: `HTTPS (secure) server ERROR`,
|
|
532
|
+
error: error,
|
|
533
|
+
}));
|
|
534
|
+
})
|
|
535
|
+
.on('uncaughtException', (ex) => {
|
|
536
|
+
fsm_dynamo_1.Dynamo_Log.warn(`\nHTTPS (secure) server uncaughtException`, new fsm_dynamo_1.Dynamo_Error({
|
|
537
|
+
errorCode: 'NTS-AS0-002',
|
|
538
|
+
message: `HTTPS (secure) server uncaughtException`,
|
|
539
|
+
error: ex,
|
|
540
|
+
}));
|
|
541
|
+
});
|
|
450
542
|
});
|
|
451
543
|
}
|
|
452
544
|
if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
453
|
-
this.
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
545
|
+
this.systemControls.httpServer.init = true;
|
|
546
|
+
yield new Promise((resolve, reject) => {
|
|
547
|
+
this.httpServer = this.openExpress
|
|
548
|
+
.listen(this._ports.httpPort, () => {
|
|
549
|
+
this.systemControls.httpServer.started = true;
|
|
550
|
+
fsm_dynamo_1.Dynamo_Log.success(`\nHTTP (open) server is listening on port ${this._ports.httpPort}`);
|
|
551
|
+
resolve();
|
|
552
|
+
})
|
|
553
|
+
.on('error', (error) => {
|
|
554
|
+
this.systemControls.httpServer.started = false;
|
|
555
|
+
this.constructErrors.push(error);
|
|
556
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
|
|
557
|
+
reject(new fsm_dynamo_1.Dynamo_Error({
|
|
558
|
+
errorCode: 'NTS-AS0-003',
|
|
559
|
+
message: `HTTP (open) server ERROR`,
|
|
560
|
+
error: error,
|
|
561
|
+
}));
|
|
562
|
+
})
|
|
563
|
+
.on('uncaughtException', (ex) => {
|
|
564
|
+
fsm_dynamo_1.Dynamo_Log.warn(`\nHTTP (open) server uncaughtException`, new fsm_dynamo_1.Dynamo_Error({
|
|
565
|
+
errorCode: 'NTS-AS0-004',
|
|
566
|
+
message: `HTTP (open) server uncaughtException`,
|
|
567
|
+
error: ex
|
|
568
|
+
}));
|
|
569
|
+
});
|
|
466
570
|
});
|
|
467
571
|
}
|
|
468
572
|
}
|
|
@@ -475,48 +579,68 @@ class DynamoNTS_App extends singleton_service_1.DynamoNTS_SingletonService {
|
|
|
475
579
|
*
|
|
476
580
|
*/
|
|
477
581
|
mountSecureRoutes() {
|
|
478
|
-
|
|
479
|
-
if (
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
582
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
583
|
+
if (this.logFn && this.deepLog)
|
|
584
|
+
console.log('\nfn:. mountSecureRoutes');
|
|
585
|
+
yield fsm_dynamo_1.Dynamo_Array.asyncForEach(this._routingModules, (module) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
586
|
+
if (module.security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
|
|
587
|
+
if (this.logSetup) {
|
|
588
|
+
console.log(`route mount (secure): ${module.route}`);
|
|
589
|
+
}
|
|
590
|
+
const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
|
|
591
|
+
if (1 < existingRoutes.length) {
|
|
592
|
+
let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
593
|
+
let errorStack = error.stack.split('\n');
|
|
594
|
+
errorStack.splice(1, 4);
|
|
595
|
+
error.stack = errorStack.join('\n');
|
|
596
|
+
fsm_dynamo_1.Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
|
|
597
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
598
|
+
errorCode: 'NTS-AS0-005',
|
|
599
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
600
|
+
error: error,
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
this.secureExpress.use(module.route, module.secureRouter);
|
|
490
604
|
}
|
|
491
|
-
|
|
492
|
-
}
|
|
605
|
+
}));
|
|
493
606
|
});
|
|
494
607
|
}
|
|
495
608
|
/**
|
|
496
609
|
*
|
|
497
610
|
*/
|
|
498
611
|
mountOpenRoutes() {
|
|
499
|
-
|
|
500
|
-
if (
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
612
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
613
|
+
if (this.logFn && this.deepLog)
|
|
614
|
+
console.log('\nfn:. mountOpenRoutes');
|
|
615
|
+
yield fsm_dynamo_1.Dynamo_Array.asyncForEach(this._routingModules, (module) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
616
|
+
if (module.security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
617
|
+
if (this.logSetup) {
|
|
618
|
+
console.log(`route mount (open): ${module.route}`);
|
|
619
|
+
}
|
|
620
|
+
const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
|
|
621
|
+
if (1 < existingRoutes.length) {
|
|
622
|
+
let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
623
|
+
let errorStack = error.stack.split('\n');
|
|
624
|
+
errorStack.splice(1, 4);
|
|
625
|
+
error.stack = errorStack.join('\n');
|
|
626
|
+
fsm_dynamo_1.Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
|
|
627
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
628
|
+
errorCode: 'NTS-AS0-006',
|
|
629
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
630
|
+
error: error,
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
this.openExpress.use(module.route, module.openRouter);
|
|
511
634
|
}
|
|
512
|
-
|
|
513
|
-
}
|
|
635
|
+
}));
|
|
514
636
|
});
|
|
515
637
|
}
|
|
516
638
|
/**
|
|
517
639
|
*
|
|
518
640
|
*/
|
|
519
641
|
setSecurity() {
|
|
642
|
+
if (this.logFn && this.deepLog)
|
|
643
|
+
console.log('\nfn:. setSecurity');
|
|
520
644
|
this._routingModules.forEach((module) => {
|
|
521
645
|
if (!module.security) {
|
|
522
646
|
fsm_dynamo_1.Dynamo_Log.error(`RoutingModule security is not set for ${module.route}\n`);
|
|
@@ -535,7 +659,7 @@ class DynamoNTS_App extends singleton_service_1.DynamoNTS_SingletonService {
|
|
|
535
659
|
msg += `\n ${module.route} (security: ${module.security})`;
|
|
536
660
|
});
|
|
537
661
|
if (this._routingModules.length === 0) {
|
|
538
|
-
msg += '\n
|
|
662
|
+
msg += '\n - no RoutingModule found -\n';
|
|
539
663
|
}
|
|
540
664
|
fsm_dynamo_1.Dynamo_Log.warn(msg);
|
|
541
665
|
}
|