@platform-x/hep-notification-client 1.0.0

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.
@@ -0,0 +1,458 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __importDefault = (this && this.__importDefault) || function (mod) {
45
+ return (mod && mod.__esModule) ? mod : { "default": mod };
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.EmailHandler = void 0;
49
+ const emailDataSource_1 = require("../dataSource/emailDataSource");
50
+ const node_html_parser_1 = require("node-html-parser");
51
+ const style_1 = require("../constants/style");
52
+ const config_1 = __importDefault(require("../../config"));
53
+ const constants_1 = require("../constants");
54
+ const lodash_1 = require("lodash");
55
+ const emailTemplate_1 = require("./emailTemplate");
56
+ const moment = require('moment-timezone');
57
+ const sgMail = require('@sendgrid/mail');
58
+ const sgHelpers = require('@sendgrid/helpers');
59
+ const ejs = __importStar(require("ejs"));
60
+ // import DOMPurify from 'dompurify'; // Include DOMPurify for sanitization
61
+ const formBuilder_dao_1 = __importDefault(require("../database/dao/formBuilder.dao"));
62
+ const dompurify_1 = __importDefault(require("dompurify"));
63
+ const jsdom_1 = require("jsdom");
64
+ const logger_1 = require("../../common/util/logger");
65
+ const window = new jsdom_1.JSDOM('').window;
66
+ const DOMPurify = (0, dompurify_1.default)(window);
67
+ // NOSONAR-NEXT-LINE
68
+ class EmailHandler {
69
+ constructor() { } // NOSONAR
70
+ /**
71
+ * post - handler to do emails triggering
72
+ * @param emailConfig
73
+ * @returns
74
+ */
75
+ sendEmail(emailConfig) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ logger_1.Logger.info('EmailHandler: Reached sendEmail method', 'sendEmail');
78
+ sgMail.setApiKey(config_1.default.SENDGRID_API_KEY);
79
+ const msg = {
80
+ personalizations: [
81
+ {
82
+ to: [{ email: emailConfig.email }],
83
+ // cc: emailCC,
84
+ },
85
+ ],
86
+ from: { email: config_1.default.EMAIL_FROM },
87
+ html: emailConfig.emailTemplate,
88
+ subject: emailConfig.subject,
89
+ };
90
+ logger_1.Logger.debug('Before sending email', 'sendEmail', msg);
91
+ return new Promise((resolve, reject) => {
92
+ sgMail
93
+ .send(msg)
94
+ .then((response) => {
95
+ logger_1.Logger.info('EmailHandler: Successfull Response', 'sendEmail');
96
+ resolve(response[0]);
97
+ })
98
+ .catch((error) => {
99
+ logger_1.Logger.error('EmailHandler: Error in sendEmail', 'sendEmail', error);
100
+ reject(error);
101
+ // throw error;
102
+ });
103
+ });
104
+ });
105
+ }
106
+ prepareEmailRequest(reqBody, emailType) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ var _a, _b;
109
+ logger_1.Logger.info('Reached prepareEmailRequest', 'prepareEmailRequest');
110
+ try {
111
+ let dataSource = new emailDataSource_1.EmailDataSource();
112
+ logger_1.Logger.debug('Before preparing email request', 'prepareEmailRequest', dataSource);
113
+ let response = yield dataSource.fetchPageModel(emailType);
114
+ logger_1.Logger.debug('Response for preparing email request', 'prepareEmailRequest', response);
115
+ const start = moment.tz(reqBody.dateTime, 'UTC'); // original timezone
116
+ let curentTimeZone = start
117
+ .tz(reqBody.timezoneOffset)
118
+ .format('Do MMMM YYYY, h:mm a');
119
+ const root = (0, node_html_parser_1.parse)((_a = response[0]) === null || _a === void 0 ? void 0 : _a.hclplatformx_Body);
120
+ root.querySelector('#1_dynamic_text').textContent = ` ${reqBody.userName}`;
121
+ root.querySelector('#2_dynamic_text').textContent = DOMPurify.sanitize(`<b> ${reqBody.pageTitle} </b>`);
122
+ root.querySelector('#3_dynamic_text').textContent = DOMPurify.sanitize(`<b>${curentTimeZone}</b>`);
123
+ root.querySelector('#dynamic_contentType').textContent = DOMPurify.sanitize(`<b>${reqBody.contentType}</b>`);
124
+ root.querySelector('#dynamic_event').textContent = DOMPurify.sanitize(`<b>${reqBody.event[0] + reqBody.event.slice(1)}</b>`);
125
+ if (((_b = reqBody === null || reqBody === void 0 ? void 0 : reqBody.event) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'published') {
126
+ root
127
+ .querySelector('.dynamic_links_btn')
128
+ .setAttribute('href', reqBody.publishPageUrl);
129
+ }
130
+ else {
131
+ root.querySelector('#viewButton').setAttribute('style', 'display:none');
132
+ }
133
+ const append = root.querySelector('head');
134
+ append.insertAdjacentHTML('beforeend', DOMPurify.sanitize(style_1.style));
135
+ let emailConfiguration = {
136
+ email: reqBody.emailTo,
137
+ emailTemplate: root.toString(),
138
+ subject: DOMPurify.sanitize(response[0].hclplatformx_Subject.replace('{{pageType}}', reqBody.contentType[0] + reqBody.contentType.slice(1))
139
+ .replace('{{publishOrUnpublish}}', reqBody.event[0] + reqBody.event.slice(1))),
140
+ };
141
+ logger_1.Logger.debug('Reached prepareEmailRequest - emailConfiguration', 'prepareEmailRequest', emailConfiguration);
142
+ let emailResponse = yield this.pushEmails(emailConfiguration);
143
+ logger_1.Logger.debug('Reached prepareEmailRequest - emailResponse', 'prepareEmailRequest', emailResponse);
144
+ return emailResponse;
145
+ }
146
+ catch (error) {
147
+ logger_1.Logger.error('EmailHandler: Error in preparing email Request', 'prepareEmailRequest', error);
148
+ throw error;
149
+ }
150
+ });
151
+ }
152
+ /**
153
+ *
154
+ * @param reqBody
155
+ * @param emailType
156
+ * @returns
157
+ */
158
+ prepareSendEmailRequest(reqBody, emailType) {
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ var _a, _b, _c, _d;
161
+ logger_1.Logger.info('Reached prepareSendEmailRequest in emailHandler', 'prepareSendEmailRequest');
162
+ try {
163
+ let dataSource = new emailDataSource_1.EmailDataSource();
164
+ // disable SOLR because of connectivity issue
165
+ let templateData = yield dataSource.fetchPageModel(emailType);
166
+ if ((reqBody === null || reqBody === void 0 ? void 0 : reqBody.replacement_variables) && (templateData === null || templateData === void 0 ? void 0 : templateData.length)) {
167
+ for (const key in reqBody.replacement_variables) {
168
+ if (key) {
169
+ templateData[0].hclplatformx_Body =
170
+ (_b = (_a = templateData[0]) === null || _a === void 0 ? void 0 : _a.hclplatformx_Body) === null || _b === void 0 ? void 0 : _b.replace(`{{${key}}}`, reqBody.replacement_variables[key]);
171
+ }
172
+ }
173
+ }
174
+ const root = (0, node_html_parser_1.parse)((_c = templateData[0]) === null || _c === void 0 ? void 0 : _c.hclplatformx_Body);
175
+ let emailConfiguration = {
176
+ email: (_d = reqBody.replacement_variables) === null || _d === void 0 ? void 0 : _d.EMAIL,
177
+ emailTemplate: root ? root.toString() : '',
178
+ subject: constants_1.CREATE_USER_EMAIL_TEMPLATE[0].subject,
179
+ };
180
+ logger_1.Logger.debug('Reached prepareSendEmailRequest - emailConfiguration', 'prepareSendEmailRequest', emailConfiguration);
181
+ let emailResponse = yield this.pushEmails(emailConfiguration);
182
+ logger_1.Logger.debug('Reached prepareSendEmailRequest - emailResponse END', 'prepareSendEmailRequest', emailResponse);
183
+ return emailResponse;
184
+ }
185
+ catch (error) {
186
+ logger_1.Logger.error('EmailHandler: Error in preparing email Request', 'prepareEmailRequest', error);
187
+ throw error;
188
+ }
189
+ });
190
+ }
191
+ /**
192
+ *
193
+ * @param emailConfiguration
194
+ * @returns
195
+ */
196
+ pushEmails(emailConfiguration) {
197
+ return __awaiter(this, void 0, void 0, function* () {
198
+ logger_1.Logger.info('Reached pushEmails in emailHandler', 'pushEmails');
199
+ return yield this.sendEmail(emailConfiguration).then((response) => __awaiter(this, void 0, void 0, function* () {
200
+ if ((response === null || response === void 0 ? void 0 : response.statusCode) === '202' || response.statusCode === 202) {
201
+ response.msg =
202
+ 'Thanks for getting in touch with us. We shall contact you soon.';
203
+ return response;
204
+ }
205
+ else {
206
+ logger_1.Logger.error('solrResolver: Error in sendEmail resolver', 'sendEmail', response);
207
+ throw new Error('Error Sending in Email');
208
+ }
209
+ }));
210
+ });
211
+ }
212
+ /**
213
+ * Function to send email with personalize data using sendgrid
214
+ * @param emailConfig
215
+ * @returns
216
+ */
217
+ sendEmailWithPersonalizations(emailConfig, isCFF) {
218
+ return __awaiter(this, void 0, void 0, function* () {
219
+ logger_1.Logger.info(`EmailHandler: Reached sendEmailWithPersonalizations method with emailConfig: ${JSON.stringify(emailConfig)}`, 'sendEmailWithPersonalizations');
220
+ const Mail = sgHelpers.classes.Mail;
221
+ let email_from = isCFF ? config_1.default === null || config_1.default === void 0 ? void 0 : config_1.default.CFF_MAIL_FROM : config_1.default === null || config_1.default === void 0 ? void 0 : config_1.default.EMAIL_FROM;
222
+ logger_1.Logger.info('sendEmailWithPersonalizations : Email From:', JSON.stringify(email_from));
223
+ const Personalization = sgHelpers.classes.Personalization;
224
+ sgMail.setApiKey(config_1.default.SENDGRID_API_KEY);
225
+ const mail = new Mail();
226
+ mail.setFrom(email_from);
227
+ mail.setSubject(emailConfig.subject);
228
+ mail.addTextContent(emailConfig.emailTemplate);
229
+ mail.addHtmlContent(emailConfig.emailTemplate);
230
+ // Set personalizations as per the emailConfig
231
+ if ((emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.personalizations) &&
232
+ (emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.personalizations.to.length)) {
233
+ const { to } = emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.personalizations;
234
+ to === null || to === void 0 ? void 0 : to.forEach((toData) => {
235
+ const personalization = new Personalization();
236
+ personalization.addTo(toData.to);
237
+ if (toData === null || toData === void 0 ? void 0 : toData.substitutions) {
238
+ for (const key in toData === null || toData === void 0 ? void 0 : toData.substitutions) {
239
+ if (key) {
240
+ personalization === null || personalization === void 0 ? void 0 : personalization.addSubstitution(key, toData === null || toData === void 0 ? void 0 : toData.substitutions[key]);
241
+ }
242
+ }
243
+ }
244
+ mail.addPersonalization(personalization);
245
+ });
246
+ if ((emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.attachments) && Array.isArray(emailConfig.attachments)) {
247
+ emailConfig.attachments.forEach((attachment) => {
248
+ mail.addAttachment({
249
+ content: attachment.base64, // base64 string
250
+ filename: attachment.filename,
251
+ type: attachment.type || 'application/octet-stream',
252
+ disposition: 'attachment',
253
+ });
254
+ });
255
+ logger_1.Logger.info('sendEmailWithPersonalizations: Email Request:', JSON.stringify(emailConfig));
256
+ }
257
+ }
258
+ else {
259
+ // set to email for non personalized email
260
+ const personalization = new Personalization();
261
+ personalization.addTo(emailConfig.email);
262
+ logger_1.Logger.info('sendEmailWithPersonalizations : Email personalizations:', JSON.stringify(personalization));
263
+ mail.addPersonalization(personalization);
264
+ }
265
+ return new Promise((resolve, reject) => {
266
+ sgMail
267
+ .send(mail)
268
+ .then((response) => {
269
+ logger_1.Logger.info(`EmailHandler: Successful Response from sendEmailWithPersonalizations: ${JSON.stringify(response)}`, 'sendEmailWithPersonalizations');
270
+ resolve(response[0]);
271
+ })
272
+ .catch((error) => {
273
+ logger_1.Logger.error(`EmailHandler: Error in sendEmailWithPersonalizations: ${JSON.stringify(error)}`, 'sendEmail', error);
274
+ reject(error);
275
+ });
276
+ });
277
+ });
278
+ }
279
+ /**
280
+ * prepare personalize email request to send email through sendgrid
281
+ * @param reqBody
282
+ * @returns
283
+ */
284
+ sendPersonalizeEmailRequest(reqBody) {
285
+ return __awaiter(this, void 0, void 0, function* () {
286
+ var _a, _b;
287
+ try {
288
+ let { email_type, replacement_variables, recipients, isCFF = false } = reqBody;
289
+ logger_1.Logger.info(`EmailHandler: reached in sendPersonalizeEmailRequest with emailType: ${email_type}`, 'sendPersonalizeEmailRequest');
290
+ // disable SOLR because of connectivity issue
291
+ logger_1.Logger.debug('Reached sendPersonalizeEmailRequest in emailHandler', 'sendPersonalizeEmailRequest');
292
+ let templateData = yield this.fetchEmailTemplateData(reqBody);
293
+ logger_1.Logger.debug('Reached sendPersonalizeEmailRequest in emailHandler', 'sendPersonalizeEmailRequest', templateData);
294
+ let recipientsData = {};
295
+ if ((0, lodash_1.isArray)(recipients)) {
296
+ const to = [];
297
+ recipients.forEach((recipient) => {
298
+ const substitutions = Object.assign(Object.assign({}, replacement_variables), { recipient_name: recipient === null || recipient === void 0 ? void 0 : recipient.name });
299
+ to.push({
300
+ to: recipient === null || recipient === void 0 ? void 0 : recipient.email,
301
+ substitutions,
302
+ });
303
+ });
304
+ recipientsData = {
305
+ to,
306
+ };
307
+ }
308
+ if (templateData && ((_a = Object.keys(templateData)) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
309
+ const root = (0, node_html_parser_1.parse)(templateData === null || templateData === void 0 ? void 0 : templateData.body);
310
+ const emailConfiguration = {
311
+ email: (_b = reqBody.replacement_variables) === null || _b === void 0 ? void 0 : _b.EMAIL,
312
+ emailTemplate: root ? root.toString() : '',
313
+ subject: templateData === null || templateData === void 0 ? void 0 : templateData.subject,
314
+ personalizations: recipientsData,
315
+ attachments: reqBody === null || reqBody === void 0 ? void 0 : reqBody.attachments,
316
+ };
317
+ let is_cff = (isCFF && isCFF === true) ? true : false;
318
+ logger_1.Logger.info(`sendPersonalizeEmailRequest -${JSON.stringify(emailConfiguration)}`, 'sendPersonalizeEmailRequest');
319
+ return yield this.sendEmailWithPersonalizations(emailConfiguration, is_cff).then((response) => __awaiter(this, void 0, void 0, function* () {
320
+ if (response.statusCode === 202) {
321
+ response.msg =
322
+ 'Thanks for getting in touch with us. We shall contact you soon.';
323
+ console.log('>>>>>>>>>>>>>>>>>>>>>>>>>.RES', response);
324
+ return response;
325
+ }
326
+ else {
327
+ logger_1.Logger.error(`EmailHandler: Error in sendEmailWithPersonalizations response - ${JSON.stringify(response)}`, 'sendEmailWithPersonalizations', response);
328
+ throw new Error('Error Sending in Email');
329
+ }
330
+ }));
331
+ }
332
+ }
333
+ catch (error) {
334
+ logger_1.Logger.error('EmailHandler: Error in preparing email Request', 'prepareEmailRequest', error);
335
+ throw error;
336
+ }
337
+ });
338
+ }
339
+ sendPlaceOrderEmail(reqBody) {
340
+ return __awaiter(this, void 0, void 0, function* () {
341
+ logger_1.Logger.info('Redached sendPlaceOrderEmail', 'sendPlaceOrderEmail');
342
+ try {
343
+ let dataSource = new emailDataSource_1.EmailDataSource();
344
+ yield dataSource.fetchPageModel('orderPlaced');
345
+ const start = moment.tz(reqBody.dateTime, 'UTC'); // original timezone
346
+ start.tz(reqBody.timezoneOffset).format('Do MMMM YYYY, h:mm a');
347
+ let str = yield emailTemplate_1.EmailTemplateHandler.prepareEmailTemplate(reqBody);
348
+ let root = (0, node_html_parser_1.parse)(str);
349
+ root.querySelector('#1_dynamic_text').textContent = `${reqBody.userName}`;
350
+ root.querySelector('#2_dynamic_text').textContent = DOMPurify.sanitize(`<b> ${reqBody.total_price} </b>`);
351
+ root.querySelector('#3_dynamic_text').textContent = DOMPurify.sanitize(`<b>${reqBody.currency_code}</b>`);
352
+ root.querySelector('#4_dynamic_text').textContent = DOMPurify.sanitize(`<b>${reqBody.shipping_address.streetName} ${reqBody.shipping_address.city} ${reqBody.shipping_address.state} ${reqBody.shipping_address.country}${reqBody.shipping_address.postalCode} </b>`);
353
+ root.querySelector('#5_dynamic_text').textContent = DOMPurify.sanitize(`<b>${reqBody.total_tax}</b>`);
354
+ root.querySelector('#6_dynamic_text').textContent = DOMPurify.sanitize(`<b>${reqBody.orderNumber}</b>`);
355
+ const apeend = root.querySelector('head');
356
+ apeend.insertAdjacentHTML('beforeend', DOMPurify.sanitize(style_1.style));
357
+ let emailConfiguration = {
358
+ email: reqBody.emailTo,
359
+ emailTemplate: root.toString(),
360
+ subject: 'Order Confirmation',
361
+ };
362
+ let emailResponse = yield this.pushEmails(emailConfiguration);
363
+ return emailResponse;
364
+ }
365
+ catch (error) {
366
+ logger_1.Logger.error('EmailHandler: Error in preparing email Request', 'prepareEmailRequest', error);
367
+ throw error;
368
+ }
369
+ });
370
+ }
371
+ sendPlaceOrderEmailv1(reqBody) {
372
+ return __awaiter(this, void 0, void 0, function* () {
373
+ logger_1.Logger.info('Redached sendPlaceOrderEmailv1', 'sendPlaceOrderEmailv1');
374
+ try {
375
+ let dataSource = new emailDataSource_1.EmailDataSource();
376
+ yield dataSource.fetchPageModel('orderPlaced');
377
+ const start = moment.tz(reqBody.dateTime, 'UTC'); // original timezone
378
+ let curentTimeZone = start;
379
+ curentTimeZone.tz(reqBody.timezoneOffset).format('Do MMMM YYYY, h:mm a');
380
+ let emailTemplate = 'templates/orderPlaced.ejs';
381
+ let billingStr = '';
382
+ billingStr +=
383
+ Object.keys(reqBody.billing_address).length !== 0
384
+ ? `${reqBody.billing_address.street_name}` ||
385
+ '' + `${reqBody.billing_address.city}` ||
386
+ '' + `${reqBody.billing_address.state}` ||
387
+ '' + `${reqBody.billing_address.country}` ||
388
+ '' + `${reqBody.billing_address.postal_code}` ||
389
+ ''
390
+ : '';
391
+ let shippingStr = '';
392
+ shippingStr +=
393
+ Object.keys(reqBody.shipping_address).length !== 0
394
+ ? `${reqBody.shipping_address.street_name}` ||
395
+ '' + `${reqBody.shipping_address.city}` ||
396
+ '' + ` ${reqBody.shipping_address.state}` ||
397
+ '' + ` ${reqBody.shipping_address.country}` ||
398
+ '' + `${reqBody.shipping_address.postal_code}` ||
399
+ ''
400
+ : '';
401
+ let templateData = yield ejs.renderFile(emailTemplate, {
402
+ userName: reqBody.userName,
403
+ orderNumber: reqBody.orderNumber,
404
+ completeAddressStr: billingStr || shippingStr,
405
+ total_tax: `${reqBody.total_tax}`,
406
+ total_price: `${reqBody.total_price}`,
407
+ data: reqBody.line_item,
408
+ });
409
+ if (templateData) {
410
+ let emailConfiguration = {
411
+ email: reqBody.emailTo,
412
+ emailTemplate: templateData,
413
+ subject: 'Order Confirmation',
414
+ };
415
+ let emailResponse = yield this.pushEmails(emailConfiguration);
416
+ return emailResponse;
417
+ }
418
+ else {
419
+ return 'Error while rendering template';
420
+ }
421
+ }
422
+ catch (error) {
423
+ logger_1.Logger.error('EmailHandler: Error in preparing email Request', 'prepareEmailRequest', error);
424
+ throw error;
425
+ }
426
+ });
427
+ }
428
+ fetchEmailTemplateData(reqBody) {
429
+ return __awaiter(this, void 0, void 0, function* () {
430
+ var _a, _b, _c, _d;
431
+ try {
432
+ logger_1.Logger.info('EmailHandler: Reached fetchEmailTemplateData', 'fetchEmailTemplateData');
433
+ let { email_type } = reqBody;
434
+ let dataSource = new emailDataSource_1.EmailDataSource();
435
+ let templateData = {};
436
+ if ((config_1.default === null || config_1.default === void 0 ? void 0 : config_1.default.MULTISITE_WITH_SOLR) === 'true') {
437
+ let templateSolrRes = yield dataSource.fetchPageModel(email_type);
438
+ if ((templateSolrRes === null || templateSolrRes === void 0 ? void 0 : templateSolrRes.length) > 0) {
439
+ templateData.body = ((_a = templateSolrRes === null || templateSolrRes === void 0 ? void 0 : templateSolrRes[0]) === null || _a === void 0 ? void 0 : _a.hclplatformx_Body) || '';
440
+ templateData.subject = ((_b = templateSolrRes === null || templateSolrRes === void 0 ? void 0 : templateSolrRes[0]) === null || _b === void 0 ? void 0 : _b.hclplatformx_Subject) || '';
441
+ }
442
+ }
443
+ else {
444
+ let templateRes = yield new formBuilder_dao_1.default().fetch('email_templates', { name: email_type });
445
+ templateData.body = (_c = templateRes === null || templateRes === void 0 ? void 0 : templateRes[0]) === null || _c === void 0 ? void 0 : _c.body;
446
+ templateData.subject = (_d = templateRes === null || templateRes === void 0 ? void 0 : templateRes[0]) === null || _d === void 0 ? void 0 : _d.subject;
447
+ }
448
+ return templateData;
449
+ }
450
+ catch (error) {
451
+ logger_1.Logger.error('EmailHandler: Error in fetchEmailTemplateData', 'fetchEmailTemplateData', error);
452
+ throw error;
453
+ }
454
+ });
455
+ }
456
+ }
457
+ exports.EmailHandler = EmailHandler;
458
+ //# sourceMappingURL=emailHandler.js.map
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EmailTemplateHandler = void 0;
13
+ class EmailTemplateHandler {
14
+ constructor() { }
15
+ static prepareEmailTemplate(reqBody) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ let str = `<!DOCTYPE html>\r\n
18
+ <html>
19
+ \r\n
20
+ <head>\r\n </head>
21
+ \r\n
22
+ <body>
23
+ \r\n
24
+ <div>
25
+ \r\n
26
+ <div class=\"main_div\">
27
+ \r\n
28
+ <table>
29
+ \r\n
30
+ <tr>
31
+ \r\n
32
+ <td>
33
+ \r\n
34
+ <div class=\"table_div\">
35
+ \r\n
36
+ <table class=\"table_2\">
37
+ \r\n
38
+ <tr>
39
+ \r\n
40
+ <td valign=\"top\" class=\"w-400\">\r\n <img\r\n src=\"https://storage.googleapis.com/platx/dev/Setting/platform-x-logo-color%402x.png\"\r\n alt=\"logo\"\r\n class=\"w_h_30\"\r\n />\r\n </td>
41
+ \r\n
42
+ </tr>
43
+ \r\n
44
+ </table>
45
+ \r\n
46
+ <p class=\"username\">Hi <span id=\"1_dynamic_text\">{{username}}</span>,</p>
47
+ \r\n
48
+ <p class=\"main_text\">Your order <span id=\"6_dynamic_text\"><b>{{ordernumber}}</b></span> has been successfully placed for amount <span id=\"2_dynamic_text\"><b>{{totalAmt}}</b></span><span id=\"3_dynamic_text\"><b>{{currency}}</b></span>.</p>
49
+ \r\n
50
+ <p class=\"main_text\">Address Details<span id=\"4_dynamic_text\"><b>{{addressStr}}</b></span></p>
51
+ \r\n
52
+ <p class=\"main_text\">Calculated Tax on your order is <span id=\"5_dynamic_text\"><b>{{totaltax}}</b></span>
53
+ <div class=\"border\">
54
+ </div>
55
+ \r\n
56
+ <div>
57
+ \r\n
58
+ <p class=\"sub_text\">This emailer is copyright to Platform-X. All rights reserved.</p>
59
+ \r\n
60
+ </div>
61
+ \r\n
62
+ </div>
63
+ \r\n
64
+ </td>
65
+ \r\n
66
+ </tr>
67
+ \r\n
68
+ </table>
69
+ \r\n
70
+ </div>
71
+ \r\n
72
+ </div>
73
+ \r\n
74
+ </body>
75
+ \r\n
76
+ </html>`;
77
+ return str;
78
+ });
79
+ }
80
+ }
81
+ exports.EmailTemplateHandler = EmailTemplateHandler;
82
+ //# sourceMappingURL=emailTemplate.js.map
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.SolrHttpDataSource = void 0;
16
+ const solrConnector_1 = require("../../../common/util/solrConnector");
17
+ const quick_lru_1 = __importDefault(require("@alloc/quick-lru"));
18
+ class SolrHttpDataSource {
19
+ // private loader: DataLoader<unknown, unknown, unknown>;
20
+ constructor() {
21
+ this.solr = new solrConnector_1.SolrClient();
22
+ this.memoizedResults = new quick_lru_1.default({
23
+ // The maximum number of items before evicting the least recently used items.
24
+ maxSize: 50,
25
+ // The maximum number of milliseconds an item should remain in cache.
26
+ // By default maxAge will be Infinity, which means that items will never expire.
27
+ maxAge: 10000,
28
+ });
29
+ // this.loader = new DataLoader(ids => dbClient.getByIds(ids))
30
+ }
31
+ // initialize({ context, cache }:any = {}) {
32
+ // this.context = context;
33
+ // this.cache = cache || new InMemoryLRUCache();
34
+ // }
35
+ // didEncounterError(error:any) {
36
+ // throw error;
37
+ // }
38
+ cacheKey(id) {
39
+ return `solr-${id}`;
40
+ }
41
+ memoizedCacheKey() {
42
+ var _a;
43
+ // return (
44
+ // JSON.parse(JSON.stringify(this.solr.getQuery())) as any
45
+ // )?.parameters?.join('&');
46
+ const data = JSON.parse(JSON.stringify(this.solr.getQuery()));
47
+ return (_a = data === null || data === void 0 ? void 0 : data.parameters) === null || _a === void 0 ? void 0 : _a.join('&');
48
+ }
49
+ createQuery(queryRequest) {
50
+ let { query, pagination, filter, sort, filterQuery } = queryRequest;
51
+ let solrQuery = this.solr.createQuery();
52
+ solrQuery.query(query); // q
53
+ solrQuery.paginate(pagination === null || pagination === void 0 ? void 0 : pagination.start, pagination === null || pagination === void 0 ? void 0 : pagination.rows); // start, rows
54
+ solrQuery.filterList(filter); // fl
55
+ solrQuery.sort(sort); // sort
56
+ solrQuery.filterQuery(filterQuery); // fq
57
+ }
58
+ executeSearch() {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ let response;
61
+ let cacheKey = this.memoizedCacheKey();
62
+ if (this.memoizedResults.has(cacheKey)) {
63
+ response = yield this.memoizedResults.get(cacheKey); // NOSONAR
64
+ return response;
65
+ }
66
+ else {
67
+ response = yield this.solr.executeSearch();
68
+ this.memoizedResults.set(cacheKey, response);
69
+ return response;
70
+ }
71
+ });
72
+ }
73
+ }
74
+ exports.SolrHttpDataSource = SolrHttpDataSource;
75
+ //# sourceMappingURL=SolrHttpDataSource.js.map