@futdevpro/nts-dynamo 1.9.32 → 1.9.34
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/build/_models/control-models/endpoint-params.control-model.js +1 -1
- package/build/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/build/_models/control-models/system-control.control-model.d.ts +1 -1
- package/build/_models/control-models/system-control.control-model.d.ts.map +1 -1
- package/build/_models/control-models/system-control.control-model.js +1 -1
- package/build/_models/control-models/system-control.control-model.js.map +1 -1
- package/build/_models/interfaces/global-service-settings.interface.d.ts +2 -1
- package/build/_models/interfaces/global-service-settings.interface.d.ts.map +1 -1
- package/build/_modules/socket/_services/app-extended.server.d.ts +1 -0
- package/build/_modules/socket/_services/app-extended.server.d.ts.map +1 -1
- package/build/_modules/socket/_services/app-extended.server.js +136 -105
- package/build/_modules/socket/_services/app-extended.server.js.map +1 -1
- package/build/_modules/socket/_services/app-extended.server.spec.js +51 -12
- package/build/_modules/socket/_services/app-extended.server.spec.js.map +1 -1
- package/build/_services/core/email.service.d.ts.map +1 -1
- package/build/_services/core/email.service.js +39 -34
- package/build/_services/core/email.service.js.map +1 -1
- package/build/_services/core/global.service.d.ts +18 -4
- package/build/_services/core/global.service.d.ts.map +1 -1
- package/build/_services/core/global.service.js +130 -20
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts +2 -0
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +362 -297
- package/build/_services/server/app.server.js.map +1 -1
- package/build/_services/server/app.server.spec.js +21 -6
- package/build/_services/server/app.server.spec.js.map +1 -1
- package/package.json +2 -2
- package/src/_models/control-models/endpoint-params.control-model.ts +1 -1
- package/src/_models/control-models/system-control.control-model.ts +1 -1
- package/src/_models/interfaces/global-service-settings.interface.ts +3 -1
- package/src/_modules/socket/_services/app-extended.server.spec.ts +60 -16
- package/src/_modules/socket/_services/app-extended.server.ts +179 -132
- package/src/_services/core/email.service.ts +61 -51
- package/src/_services/core/global.service.ts +116 -37
- package/src/_services/server/app.server.spec.ts +26 -7
- package/src/_services/server/app.server.ts +483 -447
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
import * as SocketIO from 'socket.io';
|
|
3
3
|
import * as Http from 'http';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
DyFM_Array, DyFM_Error, DyFM_Log, second, DyFM_wait, DyFM_AnyError, DyFM_Error_Settings,
|
|
7
|
+
DyFM_ErrorLevel,
|
|
8
|
+
DyFM_delay
|
|
9
|
+
} from '@futdevpro/fsm-dynamo';
|
|
6
10
|
|
|
7
11
|
import { DyNTS_App } from '../../../_services/server/app.server';
|
|
8
12
|
import { DyNTS_RouteSecurity } from '../../../_enums/route-security.enum';
|
|
@@ -160,6 +164,7 @@ export abstract class DyNTS_AppExtended extends DyNTS_App {
|
|
|
160
164
|
|
|
161
165
|
private async asyncConstructExt(): Promise<void> {
|
|
162
166
|
if (this.fnLogs && this.deepLog) console.log('\nfn:. asyncConstruct-extended');
|
|
167
|
+
|
|
163
168
|
try {
|
|
164
169
|
this.systemControlsExt.appExtended.init = true;
|
|
165
170
|
|
|
@@ -186,7 +191,7 @@ export abstract class DyNTS_AppExtended extends DyNTS_App {
|
|
|
186
191
|
console.log(this.params.title);
|
|
187
192
|
console.log(`Version: ${this.params.version}`);
|
|
188
193
|
}
|
|
189
|
-
DyFM_Log.H_success(
|
|
194
|
+
DyFM_Log.H_success(`"${this.params.name}" started successfully.`);
|
|
190
195
|
|
|
191
196
|
} catch (error) {
|
|
192
197
|
if (
|
|
@@ -211,127 +216,143 @@ export abstract class DyNTS_AppExtended extends DyNTS_App {
|
|
|
211
216
|
systemControls: this.systemControls,
|
|
212
217
|
systemControlsExt: this.systemControlsExt,
|
|
213
218
|
systemReadies: {
|
|
214
|
-
app: this.systemControls.app.
|
|
215
|
-
appExtended: this.systemControlsExt.appExtended.
|
|
216
|
-
mongoose: this.systemControls.mongoose.
|
|
217
|
-
httpServer: this.systemControls.httpServer.
|
|
218
|
-
httpsServer: this.systemControls.httpsServer.
|
|
219
|
-
httpSocketServer: this.systemControlsExt.httpSocketServer.
|
|
220
|
-
httpsSocketServer: this.systemControlsExt.httpsSocketServer.
|
|
219
|
+
app: this.systemControls.app.getIsReady(),
|
|
220
|
+
appExtended: this.systemControlsExt.appExtended.getIsReady(),
|
|
221
|
+
mongoose: this.systemControls.mongoose.getIsReady(),
|
|
222
|
+
httpServer: this.systemControls.httpServer.getIsReady(),
|
|
223
|
+
httpsServer: this.systemControls.httpsServer.getIsReady(),
|
|
224
|
+
httpSocketServer: this.systemControlsExt.httpSocketServer.getIsReady(),
|
|
225
|
+
httpsSocketServer: this.systemControlsExt.httpsSocketServer.getIsReady(),
|
|
221
226
|
},
|
|
222
227
|
},
|
|
223
228
|
});
|
|
224
229
|
}
|
|
225
230
|
}
|
|
226
231
|
|
|
227
|
-
override async ready(timeout: number =
|
|
232
|
+
override async ready(timeout: number = this.defaultReadyTimeout): Promise<void> {
|
|
228
233
|
if (this.fnLogs) console.log('\nfn:. ready-extended');
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
234
|
+
|
|
235
|
+
try {
|
|
236
|
+
await super.ready(timeout);
|
|
237
|
+
|
|
238
|
+
let ready: boolean = false;
|
|
239
|
+
const start: number = +new Date();
|
|
240
|
+
|
|
241
|
+
if (this.constructErrors.length) {
|
|
242
|
+
if (this.deepLog) {
|
|
243
|
+
if (DyNTS_global_settings.log_settings.highDetailedLogs) {
|
|
244
|
+
DyFM_Log.H_error(
|
|
245
|
+
`Extended Application: "${this.params.name}" start failed. ` +
|
|
246
|
+
`(ready; constructErrors check +1)`,
|
|
247
|
+
`\n construct ERRORS:`, this.constructErrors
|
|
248
|
+
);
|
|
241
249
|
} else {
|
|
242
|
-
|
|
250
|
+
DyFM_Log.H_error(
|
|
251
|
+
`Extended Application: "${this.params.name}" start failed. ` +
|
|
252
|
+
`(ready; constructErrors check +1)`,
|
|
253
|
+
`\n construct ERRORS:`, this.getSimplifiedConstructErrors(),
|
|
254
|
+
);
|
|
243
255
|
}
|
|
244
|
-
}
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
throw new DyFM_Error({
|
|
248
|
-
message: `${this.params?.name} start failed.`,
|
|
249
|
-
additionalContent: this.constructErrors,
|
|
250
|
-
error: this.constructErrors?.[0] ?? new Error(),
|
|
251
|
-
});
|
|
252
|
-
}
|
|
256
|
+
}
|
|
253
257
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
this.
|
|
258
|
-
|
|
259
|
-
this.systemControlsExt.httpsSocketServer.getReady()
|
|
260
|
-
);
|
|
261
|
-
} else {
|
|
262
|
-
DyFM_Log.error(`${this.params.name} APP NOT INITIALIZED while trying to get ready.`);
|
|
258
|
+
throw new DyFM_Error({
|
|
259
|
+
message: `${this.params?.name} start failed.`,
|
|
260
|
+
additionalContent: this.constructErrors,
|
|
261
|
+
error: this.constructErrors?.[0] ?? new Error(),
|
|
262
|
+
});
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
while (!ready && +new Date() - start < timeout) {
|
|
266
|
+
if (this.systemControlsExt.appExtended.init) {
|
|
267
|
+
ready = (
|
|
268
|
+
this.superStarted &&
|
|
269
|
+
this.systemControlsExt.httpSocketServer.getIsReady() &&
|
|
270
|
+
this.systemControlsExt.httpsSocketServer.getIsReady()
|
|
271
|
+
);
|
|
272
|
+
} else {
|
|
273
|
+
DyFM_Log.error(`"${this.params.name}" APP NOT INITIALIZED while trying to get ready.`);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (!ready) {
|
|
277
|
+
await DyFM_wait(100);
|
|
278
|
+
}
|
|
267
279
|
}
|
|
268
|
-
}
|
|
269
280
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
281
|
+
if (this.constructErrors.length) {
|
|
282
|
+
if (this.deepLog) {
|
|
283
|
+
if (DyNTS_global_settings.log_settings.highDetailedLogs) {
|
|
284
|
+
DyFM_Log.H_error(
|
|
285
|
+
`Extended Application: "${this.params.name}" start failed. (ready; TIMEOUT check +2)`,
|
|
286
|
+
`\n construct ERRORS:`, this.constructErrors
|
|
287
|
+
);
|
|
277
288
|
} else {
|
|
278
|
-
|
|
289
|
+
DyFM_Log.H_error(
|
|
290
|
+
`Extended Application: "${this.params.name}" start failed. (ready; TIMEOUT check +2)`,
|
|
291
|
+
`\n construct ERRORS:`, this.getSimplifiedConstructErrors(),
|
|
292
|
+
);
|
|
279
293
|
}
|
|
280
|
-
}
|
|
281
|
-
);
|
|
282
|
-
|
|
283
|
-
throw new DyFM_Error({
|
|
284
|
-
message: `${this.params?.name} start failed. TIMEOUT`,
|
|
285
|
-
additionalContent: this.constructErrors,
|
|
286
|
-
error: this.constructErrors?.[0] ?? new Error(),
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (ready) {
|
|
291
|
-
this.systemControlsExt.appExtended.started = true;
|
|
292
|
-
|
|
293
|
-
if (this.fnLogs && this.deepLog) console.log('\nfn:. ready-extended: return');
|
|
294
|
-
|
|
295
|
-
return;
|
|
296
|
-
} else {
|
|
297
|
-
this.systemControlsExt.appExtended.started = false;
|
|
298
|
-
|
|
299
|
-
let msg: string = `${this.params?.name} start failed. UNKNOWN`;
|
|
294
|
+
}
|
|
300
295
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
296
|
+
throw new DyFM_Error({
|
|
297
|
+
message: `${this.params?.name} start failed. TIMEOUT`,
|
|
298
|
+
additionalContent: this.constructErrors,
|
|
299
|
+
error: this.constructErrors?.[0] ?? new Error(),
|
|
300
|
+
});
|
|
306
301
|
}
|
|
307
302
|
|
|
308
|
-
if (
|
|
309
|
-
this.systemControlsExt.
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
msg += '\nhttpsSocketServer start failed.';
|
|
313
|
-
}
|
|
303
|
+
if (ready) {
|
|
304
|
+
this.systemControlsExt.appExtended.started = true;
|
|
305
|
+
|
|
306
|
+
if (this.fnLogs && this.deepLog) console.log('\nfn:. ready-extended: return');
|
|
314
307
|
|
|
315
|
-
|
|
308
|
+
return;
|
|
309
|
+
} else {
|
|
310
|
+
this.systemControlsExt.appExtended.started = false;
|
|
311
|
+
|
|
312
|
+
let msg: string = `${this.params?.name} start failed. UNKNOWN`;
|
|
313
|
+
|
|
314
|
+
if (
|
|
315
|
+
this.systemControlsExt.httpSocketServer.init &&
|
|
316
|
+
!this.systemControlsExt.httpSocketServer.started
|
|
317
|
+
) {
|
|
318
|
+
msg += '\nhttpSocketServer start failed.';
|
|
319
|
+
}
|
|
316
320
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
321
|
+
if (
|
|
322
|
+
this.systemControlsExt.httpsSocketServer.init &&
|
|
323
|
+
!this.systemControlsExt.httpsSocketServer.started
|
|
324
|
+
) {
|
|
325
|
+
msg += '\nhttpsSocketServer start failed.';
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
DyFM_Log.error(msg, this.constructErrors, '\n');
|
|
329
|
+
|
|
330
|
+
throw new DyFM_Error({
|
|
331
|
+
errorCode: 'NTS-AES-110',
|
|
332
|
+
message: msg,
|
|
333
|
+
additionalContent: {
|
|
334
|
+
constructErrors: this.constructErrors,
|
|
335
|
+
systemControls: this.systemControls,
|
|
336
|
+
systemControlsExt: this.systemControlsExt,
|
|
337
|
+
systemReadies: {
|
|
338
|
+
app: this.systemControls.app.getIsReady(),
|
|
339
|
+
appExtended: this.systemControlsExt.appExtended.getIsReady(),
|
|
340
|
+
mongoose: this.systemControls.mongoose.getIsReady(),
|
|
341
|
+
httpServer: this.systemControls.httpServer.getIsReady(),
|
|
342
|
+
httpsServer: this.systemControls.httpsServer.getIsReady(),
|
|
343
|
+
httpSocketServer: this.systemControlsExt.httpSocketServer.getIsReady(),
|
|
344
|
+
httpsSocketServer: this.systemControlsExt.httpsSocketServer.getIsReady(),
|
|
345
|
+
},
|
|
332
346
|
},
|
|
333
|
-
|
|
334
|
-
|
|
347
|
+
error: this.constructErrors?.[0] ?? new Error(),
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
} catch (error) {
|
|
351
|
+
throw new DyFM_Error({
|
|
352
|
+
...this.__getDefaultErrorSettings('ready', error),
|
|
353
|
+
|
|
354
|
+
errorCode: 'NTS-AES-111',
|
|
355
|
+
error: error,
|
|
335
356
|
});
|
|
336
357
|
}
|
|
337
358
|
}
|
|
@@ -339,37 +360,47 @@ export abstract class DyNTS_AppExtended extends DyNTS_App {
|
|
|
339
360
|
override async stop(): Promise<void> {
|
|
340
361
|
if (this.fnLogs) console.log('\nfn:. stop-extended');
|
|
341
362
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
363
|
+
try {
|
|
364
|
+
if (this.started) {
|
|
365
|
+
await super.stop(true);
|
|
366
|
+
|
|
367
|
+
this.systemControlsExt.httpSocketServer.started = false;
|
|
368
|
+
this.systemControlsExt.httpsSocketServer.started = false;
|
|
369
|
+
await DyFM_Array.asyncForEach(
|
|
370
|
+
this.allSocketServers,
|
|
371
|
+
async (socketServer: SocketIO.Server): Promise<void> => {
|
|
372
|
+
await new Promise<void>((resolve, reject): void => {
|
|
373
|
+
socketServer.disconnectSockets(true);
|
|
374
|
+
socketServer.close((err): void => {
|
|
375
|
+
if (err) {
|
|
376
|
+
DyFM_Log.error(`\nHTTP socket server close error`, err);
|
|
377
|
+
reject(
|
|
378
|
+
new DyFM_Error({
|
|
379
|
+
errorCode: 'NTS-AES-120',
|
|
380
|
+
message: `SocketServer close failed.`,
|
|
381
|
+
error: err,
|
|
382
|
+
})
|
|
383
|
+
);
|
|
384
|
+
} else {
|
|
385
|
+
resolve();
|
|
386
|
+
}
|
|
387
|
+
});
|
|
365
388
|
});
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
389
|
+
}
|
|
390
|
+
);
|
|
391
|
+
this.systemControlsExt.httpSocketServer.init = false;
|
|
392
|
+
this.systemControlsExt.httpsSocketServer.init = false;
|
|
393
|
+
|
|
394
|
+
await DyFM_delay(100);
|
|
371
395
|
|
|
372
|
-
|
|
396
|
+
DyFM_Log.H_info(`"${this.params.name}" stopped successfully.`);
|
|
397
|
+
}
|
|
398
|
+
} catch (error) {
|
|
399
|
+
throw new DyFM_Error({
|
|
400
|
+
...this.__getDefaultErrorSettings('stop', error),
|
|
401
|
+
|
|
402
|
+
errorCode: 'NTS-AES-121',
|
|
403
|
+
});
|
|
373
404
|
}
|
|
374
405
|
}
|
|
375
406
|
|
|
@@ -378,6 +409,7 @@ export abstract class DyNTS_AppExtended extends DyNTS_App {
|
|
|
378
409
|
*/
|
|
379
410
|
private setSocketSecurity(): void {
|
|
380
411
|
if (this.fnLogs) console.log('\nfn:. setSocketSecurity');
|
|
412
|
+
|
|
381
413
|
this.socketServices.forEach((service: DyNTS_SocketServerService<any>): void => {
|
|
382
414
|
if (!this.socketSecurity) {
|
|
383
415
|
this.socketSecurity = DyNTS_RouteSecurity[service.security];
|
|
@@ -457,7 +489,7 @@ export abstract class DyNTS_AppExtended extends DyNTS_App {
|
|
|
457
489
|
this.portSettings.httpsPort === service.port
|
|
458
490
|
) {
|
|
459
491
|
const error = new Error(`PORT DUPLICATION: ${service.port}`);
|
|
460
|
-
const errorStack: string[] = error.stack
|
|
492
|
+
const errorStack: string[] = error.stack?.split('\n');
|
|
461
493
|
|
|
462
494
|
errorStack.splice(1, 4);
|
|
463
495
|
error.stack = errorStack.join('\n');
|
|
@@ -513,7 +545,7 @@ export abstract class DyNTS_AppExtended extends DyNTS_App {
|
|
|
513
545
|
const error = new Error(
|
|
514
546
|
`INVALID Socket Service security: ${service.security} on ${service?.name}`
|
|
515
547
|
);
|
|
516
|
-
const errorStack: string[] = error.stack
|
|
548
|
+
const errorStack: string[] = error.stack?.split('\n');
|
|
517
549
|
|
|
518
550
|
errorStack.splice(1, 4);
|
|
519
551
|
error.stack = errorStack.join('\n');
|
|
@@ -548,4 +580,19 @@ export abstract class DyNTS_AppExtended extends DyNTS_App {
|
|
|
548
580
|
* MISSING Description (TODO)
|
|
549
581
|
*/
|
|
550
582
|
abstract getSocketServices(): DyNTS_SocketServerService<any>[];
|
|
583
|
+
|
|
584
|
+
private __getDefaultErrorSettings(
|
|
585
|
+
fnName: string,
|
|
586
|
+
error: DyFM_AnyError
|
|
587
|
+
): DyFM_Error_Settings {
|
|
588
|
+
return {
|
|
589
|
+
status: (error as DyFM_Error)?.___status ?? 500,
|
|
590
|
+
message: (error as Error)?.message ?? `${fnName} was UNSUCCESSFUL (NTS)`,
|
|
591
|
+
userMessage: (error as DyFM_Error)?.__userMessage ?? this.defaultErrorUserMsg,
|
|
592
|
+
addECToUserMsg: !(error as DyFM_Error)?.__userMessage,
|
|
593
|
+
issuerService: `${this?.constructor?.name}-DyNTS_AppExtended`,
|
|
594
|
+
level: DyFM_ErrorLevel.fatal,
|
|
595
|
+
error: error,
|
|
596
|
+
};
|
|
597
|
+
}
|
|
551
598
|
}
|
|
@@ -118,9 +118,6 @@ export class DyNTS_EmailService /* extends DyNTS_SingletonService */ {
|
|
|
118
118
|
...this._getDefaultErrorSettings('asyncPostConstruct', error, 'SYSTEM'),
|
|
119
119
|
|
|
120
120
|
errorCode: 'NTS-ES0-APC0',
|
|
121
|
-
message:
|
|
122
|
-
`\nDynamoBEEmailService ERROR, ` +
|
|
123
|
-
`\nThe emailService construction failed for ${this.serviceName}.`,
|
|
124
121
|
});
|
|
125
122
|
}
|
|
126
123
|
}
|
|
@@ -144,9 +141,7 @@ export class DyNTS_EmailService /* extends DyNTS_SingletonService */ {
|
|
|
144
141
|
throw new DyFM_Error({
|
|
145
142
|
...this._getDefaultErrorSettings(
|
|
146
143
|
'sendEmail',
|
|
147
|
-
new Error(
|
|
148
|
-
`No email template component is given!`
|
|
149
|
-
),
|
|
144
|
+
new Error(`No email template component is given!`),
|
|
150
145
|
issuer
|
|
151
146
|
),
|
|
152
147
|
|
|
@@ -171,7 +166,7 @@ export class DyNTS_EmailService /* extends DyNTS_SingletonService */ {
|
|
|
171
166
|
});
|
|
172
167
|
}
|
|
173
168
|
|
|
174
|
-
content = this.compileTemplateComponent(
|
|
169
|
+
content = await this.compileTemplateComponent(
|
|
175
170
|
set.templateComponentName,
|
|
176
171
|
set.templateProperties,
|
|
177
172
|
issuer
|
|
@@ -217,11 +212,11 @@ export class DyNTS_EmailService /* extends DyNTS_SingletonService */ {
|
|
|
217
212
|
}
|
|
218
213
|
}
|
|
219
214
|
|
|
220
|
-
private compileTemplateComponent<T>(
|
|
215
|
+
private async compileTemplateComponent<T>(
|
|
221
216
|
componentName: string,
|
|
222
217
|
componentProperties:T,
|
|
223
218
|
issuer: string
|
|
224
|
-
): string {
|
|
219
|
+
): Promise<string> {
|
|
225
220
|
try {
|
|
226
221
|
if (!this.componentsByName[componentName]) {
|
|
227
222
|
throw new DyFM_Error({
|
|
@@ -233,7 +228,7 @@ export class DyNTS_EmailService /* extends DyNTS_SingletonService */ {
|
|
|
233
228
|
|
|
234
229
|
errorCode: 'NTS-ES0-SC1',
|
|
235
230
|
additionalContent: {
|
|
236
|
-
|
|
231
|
+
availableComponents: Object.keys(this.componentsByName),
|
|
237
232
|
},
|
|
238
233
|
});
|
|
239
234
|
}
|
|
@@ -242,20 +237,23 @@ export class DyNTS_EmailService /* extends DyNTS_SingletonService */ {
|
|
|
242
237
|
let template: string = this.compileHTMLMainFrame(component);
|
|
243
238
|
|
|
244
239
|
template = template.replace('<nts-content>', '');
|
|
245
|
-
template = this.compileComponentProperties<T>(
|
|
240
|
+
template = await this.compileComponentProperties<T>(
|
|
246
241
|
component,
|
|
247
242
|
componentProperties,
|
|
248
243
|
template,
|
|
249
244
|
issuer
|
|
250
245
|
);
|
|
251
246
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
247
|
+
await DyFM_Array.asyncForEach(
|
|
248
|
+
component.subComponentSelectors,
|
|
249
|
+
async (subComponentSelector: string): Promise<void> => {
|
|
250
|
+
while (template.includes(`<nts-${subComponentSelector}`)) {
|
|
251
|
+
template = await this.compileSubComponent<T>(
|
|
252
|
+
subComponentSelector, componentProperties, template, issuer
|
|
253
|
+
);
|
|
254
|
+
}
|
|
257
255
|
}
|
|
258
|
-
|
|
256
|
+
);
|
|
259
257
|
|
|
260
258
|
template = this.templateTrim(template);
|
|
261
259
|
|
|
@@ -325,9 +323,9 @@ export class DyNTS_EmailService /* extends DyNTS_SingletonService */ {
|
|
|
325
323
|
|
|
326
324
|
/** trims all rows and remove everything between /*...*\/ */
|
|
327
325
|
private styleTrim(style: string): string {
|
|
328
|
-
let result: string = style
|
|
326
|
+
let result: string = style?.split('\n').map((row: string): string => row.trim()).join('');
|
|
329
327
|
|
|
330
|
-
while (result
|
|
328
|
+
while (result?.includes('/*')) {
|
|
331
329
|
const start = result.indexOf('/*');
|
|
332
330
|
const end = result.indexOf('*/', start) + 2;
|
|
333
331
|
|
|
@@ -358,44 +356,53 @@ export class DyNTS_EmailService /* extends DyNTS_SingletonService */ {
|
|
|
358
356
|
return b / 1024;
|
|
359
357
|
}
|
|
360
358
|
|
|
361
|
-
private compileComponentProperties<T>(
|
|
359
|
+
private async compileComponentProperties<T>(
|
|
362
360
|
component: DyNTS_EmailTemplateComponent,
|
|
363
361
|
componentProperties: T,
|
|
364
362
|
template: string,
|
|
365
363
|
issuer: string
|
|
366
|
-
): string {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
364
|
+
): Promise<string> {
|
|
365
|
+
try {
|
|
366
|
+
component.properties.forEach((propertyKey: string): void => {
|
|
367
|
+
if (!componentProperties[propertyKey]) {
|
|
368
|
+
throw new DyFM_Error({
|
|
369
|
+
...this._getDefaultErrorSettings(
|
|
370
|
+
'setupComponent',
|
|
371
|
+
new Error(
|
|
372
|
+
`ComponentProperty missing from input! '${propertyKey}' for ${component.name}`
|
|
373
|
+
),
|
|
374
|
+
issuer
|
|
374
375
|
),
|
|
375
|
-
issuer
|
|
376
|
-
),
|
|
377
376
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
377
|
+
errorCode: 'NTS-ES0-SC4',
|
|
378
|
+
additionalContent: {
|
|
379
|
+
componentProperties: Object.keys(componentProperties),
|
|
380
|
+
},
|
|
381
|
+
});
|
|
382
|
+
}
|
|
384
383
|
|
|
385
|
-
|
|
384
|
+
const propReg = new RegExp(`{{${propertyKey}}}`, 'g');
|
|
386
385
|
|
|
387
|
-
|
|
388
|
-
|
|
386
|
+
template = template.replace(propReg, componentProperties[propertyKey]);
|
|
387
|
+
});
|
|
389
388
|
|
|
390
|
-
|
|
389
|
+
return template;
|
|
390
|
+
} catch (error) {
|
|
391
|
+
throw new DyFM_Error({
|
|
392
|
+
...this._getDefaultErrorSettings('setupComponent', error, issuer),
|
|
393
|
+
|
|
394
|
+
errorCode: 'NTS-ES0-SC3',
|
|
395
|
+
});
|
|
396
|
+
}
|
|
391
397
|
}
|
|
392
398
|
|
|
393
|
-
private compileSubComponent<T>(
|
|
399
|
+
private async compileSubComponent<T>(
|
|
394
400
|
subComponentSelector: string,
|
|
395
401
|
componentProperties: T,
|
|
396
402
|
template: string,
|
|
397
403
|
issuer: string
|
|
398
|
-
): string {
|
|
404
|
+
): Promise<string> {
|
|
405
|
+
|
|
399
406
|
const subComponent: DyNTS_EmailTemplateComponent =
|
|
400
407
|
this.componentsBySelector[subComponentSelector];
|
|
401
408
|
|
|
@@ -428,7 +435,7 @@ export class DyNTS_EmailService /* extends DyNTS_SingletonService */ {
|
|
|
428
435
|
const contentReg = new RegExp(`<nts-content>`, 'g');
|
|
429
436
|
|
|
430
437
|
subComponentTemplate = subComponentTemplate.replace(contentReg, componentContent);
|
|
431
|
-
subComponentTemplate = this.compileComponentProperties<T>(
|
|
438
|
+
subComponentTemplate = await this.compileComponentProperties<T>(
|
|
432
439
|
subComponent,
|
|
433
440
|
componentProperties,
|
|
434
441
|
subComponentTemplate,
|
|
@@ -458,20 +465,23 @@ export class DyNTS_EmailService /* extends DyNTS_SingletonService */ {
|
|
|
458
465
|
private async loadComponent(component: DyNTS_EmailTemplateComponent): Promise<void> {
|
|
459
466
|
try {
|
|
460
467
|
if (this.componentsBySelector[component.selector]) {
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
errorCode: 'NTS-ES0-LC1',
|
|
465
|
-
message: `Template already loaded! (${component.name})`,
|
|
466
|
-
});
|
|
468
|
+
DyFM_Log.warn('Email component already loaded! (it will be skipped)', component.selector);
|
|
469
|
+
|
|
470
|
+
return;
|
|
467
471
|
}
|
|
468
472
|
|
|
469
473
|
if (!component.templatePath && !component.template) {
|
|
470
474
|
throw new DyFM_Error({
|
|
471
|
-
...this._getDefaultErrorSettings(
|
|
475
|
+
...this._getDefaultErrorSettings(
|
|
476
|
+
'loadComponent',
|
|
477
|
+
new Error(`Component missing template and templatePath! (${component.name})`),
|
|
478
|
+
'SYSTEM'
|
|
479
|
+
),
|
|
472
480
|
|
|
473
481
|
errorCode: 'NTS-ES0-LC2',
|
|
474
|
-
|
|
482
|
+
additionalContent: {
|
|
483
|
+
component: component,
|
|
484
|
+
},
|
|
475
485
|
});
|
|
476
486
|
}
|
|
477
487
|
|