@futdevpro/nts-dynamo 1.9.31 → 1.9.33
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/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 +125 -96
- package/build/_modules/socket/_services/app-extended.server.js.map +1 -1
- package/build/_modules/socket/_services/app-extended.server.spec.js +2 -0
- package/build/_modules/socket/_services/app-extended.server.spec.js.map +1 -1
- package/build/_services/core/email.service.d.ts +3 -1
- package/build/_services/core/email.service.d.ts.map +1 -1
- package/build/_services/core/email.service.js +48 -27
- package/build/_services/core/email.service.js.map +1 -1
- package/build/_services/core/global.service.d.ts +4 -0
- package/build/_services/core/global.service.d.ts.map +1 -1
- package/build/_services/core/global.service.js +67 -14
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +352 -291
- package/build/_services/server/app.server.js.map +1 -1
- package/package.json +2 -2
- package/src/_models/control-models/endpoint-params.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 +5 -0
- package/src/_modules/socket/_services/app-extended.server.ts +165 -124
- package/src/_services/core/email.service.ts +71 -40
- package/src/_services/core/global.service.ts +82 -24
- package/src/_services/server/app.server.ts +479 -402
|
@@ -8,6 +8,8 @@ import { Options as MailOptions, Attachment } from 'nodemailer/lib/mailer';
|
|
|
8
8
|
import {
|
|
9
9
|
DyFM_AnyError, DyFM_Array, DyFM_Error, DyFM_Error_Settings, DyFM_Log
|
|
10
10
|
} from '@futdevpro/fsm-dynamo';
|
|
11
|
+
import { DyNTS_SingletonService } from '../base/singleton.service';
|
|
12
|
+
import { DyNTS_global_settings } from '../../_collections/global-settings.const';
|
|
11
13
|
|
|
12
14
|
export interface DyNTS_EmailService_Settings {
|
|
13
15
|
host: string,
|
|
@@ -58,7 +60,7 @@ export interface DyNTS_SendEmail_Settings<T = { [propertyKey: string]: string; }
|
|
|
58
60
|
/**
|
|
59
61
|
*
|
|
60
62
|
*/
|
|
61
|
-
export class DyNTS_EmailService {
|
|
63
|
+
export class DyNTS_EmailService /* extends DyNTS_SingletonService */ {
|
|
62
64
|
serviceName: string;
|
|
63
65
|
|
|
64
66
|
private nmTransporter: NodeMailer.Transporter;
|
|
@@ -75,8 +77,8 @@ export class DyNTS_EmailService {
|
|
|
75
77
|
|
|
76
78
|
private readonly styleLimitWarning: number = 16;
|
|
77
79
|
|
|
78
|
-
defaultErrorUserMsg =
|
|
79
|
-
`We encountered an
|
|
80
|
+
readonly defaultErrorUserMsg =
|
|
81
|
+
`We encountered an uncaught Email Service Error, ` +
|
|
80
82
|
`\nplease contact the responsible development team.`;
|
|
81
83
|
|
|
82
84
|
constructor (
|
|
@@ -169,7 +171,7 @@ export class DyNTS_EmailService {
|
|
|
169
171
|
});
|
|
170
172
|
}
|
|
171
173
|
|
|
172
|
-
content = this.compileTemplateComponent(
|
|
174
|
+
content = await this.compileTemplateComponent(
|
|
173
175
|
set.templateComponentName,
|
|
174
176
|
set.templateProperties,
|
|
175
177
|
issuer
|
|
@@ -215,11 +217,11 @@ export class DyNTS_EmailService {
|
|
|
215
217
|
}
|
|
216
218
|
}
|
|
217
219
|
|
|
218
|
-
private compileTemplateComponent<T>(
|
|
220
|
+
private async compileTemplateComponent<T>(
|
|
219
221
|
componentName: string,
|
|
220
222
|
componentProperties:T,
|
|
221
223
|
issuer: string
|
|
222
|
-
): string {
|
|
224
|
+
): Promise<string> {
|
|
223
225
|
try {
|
|
224
226
|
if (!this.componentsByName[componentName]) {
|
|
225
227
|
throw new DyFM_Error({
|
|
@@ -231,7 +233,7 @@ export class DyNTS_EmailService {
|
|
|
231
233
|
|
|
232
234
|
errorCode: 'NTS-ES0-SC1',
|
|
233
235
|
additionalContent: {
|
|
234
|
-
|
|
236
|
+
availableComponents: Object.keys(this.componentsByName),
|
|
235
237
|
},
|
|
236
238
|
});
|
|
237
239
|
}
|
|
@@ -240,20 +242,23 @@ export class DyNTS_EmailService {
|
|
|
240
242
|
let template: string = this.compileHTMLMainFrame(component);
|
|
241
243
|
|
|
242
244
|
template = template.replace('<nts-content>', '');
|
|
243
|
-
template = this.compileComponentProperties<T>(
|
|
245
|
+
template = await this.compileComponentProperties<T>(
|
|
244
246
|
component,
|
|
245
247
|
componentProperties,
|
|
246
248
|
template,
|
|
247
249
|
issuer
|
|
248
250
|
);
|
|
249
251
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
await DyFM_Array.asyncForEach(
|
|
253
|
+
component.subComponentSelectors,
|
|
254
|
+
async (subComponentSelector: string): Promise<void> => {
|
|
255
|
+
while (template.includes(`<nts-${subComponentSelector}`)) {
|
|
256
|
+
template = await this.compileSubComponent<T>(
|
|
257
|
+
subComponentSelector, componentProperties, template, issuer
|
|
258
|
+
);
|
|
259
|
+
}
|
|
255
260
|
}
|
|
256
|
-
|
|
261
|
+
);
|
|
257
262
|
|
|
258
263
|
template = this.templateTrim(template);
|
|
259
264
|
|
|
@@ -323,9 +328,9 @@ export class DyNTS_EmailService {
|
|
|
323
328
|
|
|
324
329
|
/** trims all rows and remove everything between /*...*\/ */
|
|
325
330
|
private styleTrim(style: string): string {
|
|
326
|
-
let result: string = style
|
|
331
|
+
let result: string = style?.split('\n').map((row: string): string => row.trim()).join('');
|
|
327
332
|
|
|
328
|
-
while (result
|
|
333
|
+
while (result?.includes('/*')) {
|
|
329
334
|
const start = result.indexOf('/*');
|
|
330
335
|
const end = result.indexOf('*/', start) + 2;
|
|
331
336
|
|
|
@@ -356,44 +361,53 @@ export class DyNTS_EmailService {
|
|
|
356
361
|
return b / 1024;
|
|
357
362
|
}
|
|
358
363
|
|
|
359
|
-
private compileComponentProperties<T>(
|
|
364
|
+
private async compileComponentProperties<T>(
|
|
360
365
|
component: DyNTS_EmailTemplateComponent,
|
|
361
366
|
componentProperties: T,
|
|
362
367
|
template: string,
|
|
363
368
|
issuer: string
|
|
364
|
-
): string {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
369
|
+
): Promise<string> {
|
|
370
|
+
try {
|
|
371
|
+
component.properties.forEach((propertyKey: string): void => {
|
|
372
|
+
if (!componentProperties[propertyKey]) {
|
|
373
|
+
throw new DyFM_Error({
|
|
374
|
+
...this._getDefaultErrorSettings(
|
|
375
|
+
'setupComponent',
|
|
376
|
+
new Error(
|
|
377
|
+
`ComponentProperty missing from input! '${propertyKey}' for ${component.name}`
|
|
378
|
+
),
|
|
379
|
+
issuer
|
|
372
380
|
),
|
|
373
|
-
issuer
|
|
374
|
-
),
|
|
375
381
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
+
errorCode: 'NTS-ES0-SC4',
|
|
383
|
+
additionalContent: {
|
|
384
|
+
componentProperties: Object.keys(componentProperties),
|
|
385
|
+
},
|
|
386
|
+
});
|
|
387
|
+
}
|
|
382
388
|
|
|
383
|
-
|
|
389
|
+
const propReg = new RegExp(`{{${propertyKey}}}`, 'g');
|
|
384
390
|
|
|
385
|
-
|
|
386
|
-
|
|
391
|
+
template = template.replace(propReg, componentProperties[propertyKey]);
|
|
392
|
+
});
|
|
387
393
|
|
|
388
|
-
|
|
394
|
+
return template;
|
|
395
|
+
} catch (error) {
|
|
396
|
+
throw new DyFM_Error({
|
|
397
|
+
...this._getDefaultErrorSettings('setupComponent', error, issuer),
|
|
398
|
+
|
|
399
|
+
errorCode: 'NTS-ES0-SC3',
|
|
400
|
+
});
|
|
401
|
+
}
|
|
389
402
|
}
|
|
390
403
|
|
|
391
|
-
private compileSubComponent<T>(
|
|
404
|
+
private async compileSubComponent<T>(
|
|
392
405
|
subComponentSelector: string,
|
|
393
406
|
componentProperties: T,
|
|
394
407
|
template: string,
|
|
395
408
|
issuer: string
|
|
396
|
-
): string {
|
|
409
|
+
): Promise<string> {
|
|
410
|
+
|
|
397
411
|
const subComponent: DyNTS_EmailTemplateComponent =
|
|
398
412
|
this.componentsBySelector[subComponentSelector];
|
|
399
413
|
|
|
@@ -426,7 +440,7 @@ export class DyNTS_EmailService {
|
|
|
426
440
|
const contentReg = new RegExp(`<nts-content>`, 'g');
|
|
427
441
|
|
|
428
442
|
subComponentTemplate = subComponentTemplate.replace(contentReg, componentContent);
|
|
429
|
-
subComponentTemplate = this.compileComponentProperties<T>(
|
|
443
|
+
subComponentTemplate = await this.compileComponentProperties<T>(
|
|
430
444
|
subComponent,
|
|
431
445
|
componentProperties,
|
|
432
446
|
subComponentTemplate,
|
|
@@ -677,4 +691,21 @@ export class DyNTS_EmailService {
|
|
|
677
691
|
error: error,
|
|
678
692
|
};
|
|
679
693
|
}
|
|
694
|
+
|
|
695
|
+
protected getDefaultErrorSettings(
|
|
696
|
+
fnName: string,
|
|
697
|
+
error: DyFM_AnyError,
|
|
698
|
+
issuer: string
|
|
699
|
+
): DyFM_Error_Settings {
|
|
700
|
+
return {
|
|
701
|
+
status: (error as DyFM_Error)?.___status ?? 500,
|
|
702
|
+
message: (error as Error)?.message ??
|
|
703
|
+
`${fnName} was UNSUCCESSFUL (${DyNTS_global_settings.systemShortCodeName})`,
|
|
704
|
+
addECToUserMsg: !(error as DyFM_Error)?.__userMessage,
|
|
705
|
+
userMessage: (error as DyFM_Error)?.__userMessage ?? this.defaultErrorUserMsg,
|
|
706
|
+
issuer: issuer,
|
|
707
|
+
issuerService: this.constructor?.name,
|
|
708
|
+
error: error,
|
|
709
|
+
};
|
|
710
|
+
}
|
|
680
711
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import { DyNTS_App_Params } from '../../_models/control-models/app-params.control-model';
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
|
+
DyNTS_GlobalErrorHandlerFn,
|
|
12
13
|
DyNTS_GlobalService_Settings
|
|
13
14
|
} from '../../_models/interfaces/global-service-settings.interface';
|
|
14
15
|
|
|
@@ -62,14 +63,32 @@ export class DyNTS_GlobalService extends DyNTS_SingletonService {
|
|
|
62
63
|
static async setServices(set: DyNTS_GlobalService_Settings): Promise<void> {
|
|
63
64
|
this.getInstance();
|
|
64
65
|
|
|
66
|
+
try {
|
|
67
|
+
await this.setDBServices(set?.dbModels);
|
|
68
|
+
|
|
69
|
+
await this.setAuthService(set?.authService);
|
|
70
|
+
|
|
71
|
+
await this.setEmailServices(set?.emailServiceCollection);
|
|
72
|
+
|
|
73
|
+
await this.setErrorHandler(set?.errorHandler);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
throw new DyFM_Error({
|
|
76
|
+
message: `Failed to setServices on DyNTS_GlobalService.`,
|
|
77
|
+
error: error,
|
|
78
|
+
errorCode: 'NTS-GS0-SS0',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private static async setDBServices(dbModels?: DyFM_DataModel_Params[]): Promise<void> {
|
|
65
84
|
try {
|
|
66
85
|
this.instance.dbServiceCollection = {};
|
|
67
|
-
|
|
86
|
+
dbModels?.forEach((dbModel: DyFM_DataModel_Params): void => {
|
|
68
87
|
if (!dbModel.constructed) {
|
|
69
88
|
throw new DyFM_Error({
|
|
70
89
|
message: `DyNTS_GlobalService.setServices failed, ` +
|
|
71
90
|
`ERROR: dbModel is not constructed!`,
|
|
72
|
-
errorCode: 'NTS-GS0-
|
|
91
|
+
errorCode: 'NTS-GS0-SDBS1',
|
|
73
92
|
additionalContent: {
|
|
74
93
|
dbModel: dbModel,
|
|
75
94
|
},
|
|
@@ -91,14 +110,36 @@ export class DyNTS_GlobalService extends DyNTS_SingletonService {
|
|
|
91
110
|
});
|
|
92
111
|
}
|
|
93
112
|
});
|
|
113
|
+
} catch (error) {
|
|
114
|
+
throw new DyFM_Error({
|
|
115
|
+
message: `Failed to set dbServiceCollections on DyNTS_GlobalService.`,
|
|
116
|
+
error: error,
|
|
117
|
+
errorCode: 'NTS-GS0-SDBS0',
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
94
121
|
|
|
95
|
-
|
|
122
|
+
private static async setAuthService(authService?: DyNTS_AuthService): Promise<void> {
|
|
123
|
+
try {
|
|
124
|
+
if (!authService) {
|
|
96
125
|
DyFM_Log.warn(`Authentication Service missing!`);
|
|
97
126
|
} else {
|
|
98
|
-
this.instance.authService =
|
|
127
|
+
this.instance.authService = authService;
|
|
99
128
|
}
|
|
129
|
+
} catch (error) {
|
|
130
|
+
throw new DyFM_Error({
|
|
131
|
+
message: `Failed to set authService on DyNTS_GlobalService.`,
|
|
132
|
+
error: error,
|
|
133
|
+
errorCode: 'NTS-GS0-SAS0',
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
100
137
|
|
|
101
|
-
|
|
138
|
+
private static async setEmailServices(
|
|
139
|
+
emailServiceCollection?: DyNTS_Service_Collection<DyNTS_EmailService>
|
|
140
|
+
): Promise<void> {
|
|
141
|
+
try {
|
|
142
|
+
this.instance.emailServiceCollection = emailServiceCollection ?? {};
|
|
102
143
|
await DyFM_Array.asyncForEach(
|
|
103
144
|
Object.keys(this.instance.emailServiceCollection),
|
|
104
145
|
async (key: string): Promise<void> => {
|
|
@@ -107,34 +148,51 @@ export class DyNTS_GlobalService extends DyNTS_SingletonService {
|
|
|
107
148
|
).asyncPostConstruct();
|
|
108
149
|
}
|
|
109
150
|
);
|
|
110
|
-
|
|
151
|
+
} catch (error) {
|
|
152
|
+
throw new DyFM_Error({
|
|
153
|
+
message: `Failed to set emailServiceCollections on DyNTS_GlobalService.`,
|
|
154
|
+
error: error,
|
|
155
|
+
errorCode: 'NTS-GS0-SS4',
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private static async setErrorHandler(errorHandler?: DyNTS_GlobalErrorHandlerFn): Promise<void> {
|
|
161
|
+
try {
|
|
111
162
|
DyNTS_GlobalService.globalErrorHandler =
|
|
112
|
-
|
|
163
|
+
errorHandler ??
|
|
113
164
|
(async (error: any): Promise<void> => {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
DyNTS_global_settings.log_settings.highDetailedLogs ||
|
|
121
|
-
!(error instanceof DyFM_Error)
|
|
122
|
-
) {
|
|
123
|
-
DyFM_Log.H_error(
|
|
124
|
-
`Error caught by globalErrorHandler.`,
|
|
125
|
-
`\n ERROR:`, error
|
|
165
|
+
try {
|
|
166
|
+
DyFM_Log.warn(
|
|
167
|
+
`globalErrorHandler not set! (set in app.getGlobalServiceCollection)`,
|
|
168
|
+
'\nwill use default-logging',
|
|
126
169
|
);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
170
|
+
|
|
171
|
+
if (
|
|
172
|
+
DyNTS_global_settings.log_settings.highDetailedLogs ||
|
|
173
|
+
!(error instanceof DyFM_Error)
|
|
174
|
+
) {
|
|
175
|
+
DyFM_Log.H_error(
|
|
176
|
+
`Error caught by globalErrorHandler.`,
|
|
177
|
+
`\n ERROR:`, error
|
|
178
|
+
);
|
|
179
|
+
} else {
|
|
180
|
+
error.logSimple(
|
|
181
|
+
`Error caught by globalErrorHandler.`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
} catch (error) {
|
|
185
|
+
DyFM_Log.error(
|
|
186
|
+
`NTS GLOBAL MULTILEVEL ERROR: \nFailed to handle error on globalErrorHandler.`,
|
|
187
|
+
error
|
|
130
188
|
);
|
|
131
189
|
}
|
|
132
190
|
});
|
|
133
191
|
} catch (error) {
|
|
134
192
|
throw new DyFM_Error({
|
|
135
|
-
message: `Failed to
|
|
193
|
+
message: `Failed to set errorHandler on DyNTS_GlobalService.`,
|
|
136
194
|
error: error,
|
|
137
|
-
errorCode: 'NTS-GS0-
|
|
195
|
+
errorCode: 'NTS-GS0-SEH0',
|
|
138
196
|
});
|
|
139
197
|
}
|
|
140
198
|
}
|