@platform-x/hep-push-notification-client 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/src/common/service/requestService.d.ts +26 -0
  2. package/dist/src/common/service/requestService.js +96 -0
  3. package/dist/src/common/service/secretKeyManager.services.d.ts +0 -0
  4. package/dist/src/common/service/secretKeyManager.services.js +38 -0
  5. package/dist/src/common/service/twilioService.d.ts +19 -0
  6. package/dist/src/common/service/twilioService.js +63 -0
  7. package/dist/src/common/util/solrConnector.d.ts +35 -0
  8. package/dist/src/common/util/solrConnector.js +157 -0
  9. package/dist/src/platform-x/constants/index.d.ts +21 -15
  10. package/dist/src/platform-x/constants/index.js +21 -15
  11. package/dist/src/platform-x/constants/style.d.ts +1 -0
  12. package/dist/src/platform-x/constants/style.js +103 -0
  13. package/dist/src/platform-x/dataSource/emailDataSource.d.ts +5 -0
  14. package/dist/src/platform-x/dataSource/emailDataSource.js +36 -0
  15. package/dist/src/platform-x/database/connection.d.ts +10 -10
  16. package/dist/src/platform-x/database/connection.js +78 -78
  17. package/dist/src/platform-x/database/dao/formBuilder.dao.d.ts +9 -0
  18. package/dist/src/platform-x/database/dao/formBuilder.dao.js +51 -0
  19. package/dist/src/platform-x/database/dao/site_domain.dao.d.ts +8 -8
  20. package/dist/src/platform-x/database/dao/site_domain.dao.js +44 -44
  21. package/dist/src/platform-x/database/index.d.ts +10 -10
  22. package/dist/src/platform-x/database/index.js +9 -9
  23. package/dist/src/platform-x/database/interfaces/site_domain.interface.d.ts +33 -33
  24. package/dist/src/platform-x/database/interfaces/site_domain.interface.js +2 -2
  25. package/dist/src/platform-x/database/models/formBuilder.model.d.ts +34 -0
  26. package/dist/src/platform-x/database/models/formBuilder.model.js +35 -0
  27. package/dist/src/platform-x/database/models/site_domain.model.d.ts +2 -2
  28. package/dist/src/platform-x/database/models/site_domain.model.js +47 -47
  29. package/dist/src/platform-x/services/fcmservices.js +6 -6
  30. package/dist/src/platform-x/util/emailHandler.d.ts +62 -0
  31. package/dist/src/platform-x/util/emailHandler.js +524 -0
  32. package/dist/src/platform-x/util/emailTemplate.d.ts +4 -0
  33. package/dist/src/platform-x/util/emailTemplate.js +82 -0
  34. package/dist/src/platform-x/util/solr-data-source/SolrHttpDataSource.d.ts +26 -0
  35. package/dist/src/platform-x/util/solr-data-source/SolrHttpDataSource.js +75 -0
  36. package/dist/templates/orderPlaced.ejs +173 -0
  37. package/dist/templates/orderPlaced.html +190 -0
  38. package/package.json +1 -1
@@ -0,0 +1,524 @@
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 HTMLParser = __importStar(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 path_1 = __importDefault(require("path"));
66
+ const __1 = require("../..");
67
+ const window = new jsdom_1.JSDOM('').window;
68
+ const DOMPurify = (0, dompurify_1.default)(window);
69
+ // NOSONAR-NEXT-LINE
70
+ class EmailHandler {
71
+ constructor() { } // NOSONAR
72
+ /**
73
+ * post - handler to do emails triggering
74
+ * @param emailConfig
75
+ * @returns
76
+ */
77
+ sendEmail(emailConfig) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ logger_1.Logger.info('EmailHandler: Reached sendEmail method', 'sendEmail');
80
+ const secrets = yield (0, __1.getIAMSecrets)();
81
+ sgMail.setApiKey(secrets === null || secrets === void 0 ? void 0 : secrets[constants_1.DynamicValues === null || constants_1.DynamicValues === void 0 ? void 0 : constants_1.DynamicValues.SENDGRID_API_KEY]);
82
+ // Build personalization object
83
+ const personalization = {
84
+ to: [{ email: emailConfig.email }],
85
+ };
86
+ // Add CC emails if provided
87
+ if (emailConfig.cc) {
88
+ const ccEmails = Array.isArray(emailConfig.cc) ? emailConfig.cc : [emailConfig.cc];
89
+ personalization.cc = ccEmails.map((email) => ({ email }));
90
+ logger_1.Logger.info(`Adding CC emails to non-personalized email: ${ccEmails.join(', ')}`, 'sendEmail');
91
+ }
92
+ // Add BCC if provided
93
+ if (emailConfig.bcc) {
94
+ personalization.bcc = [{ email: emailConfig.bcc }];
95
+ }
96
+ const msg = {
97
+ personalizations: [personalization],
98
+ from: { email: config_1.default.EMAIL_FROM },
99
+ html: emailConfig.emailTemplate,
100
+ subject: emailConfig.subject,
101
+ };
102
+ logger_1.Logger.debug('Before sending email', 'sendEmail', msg);
103
+ return new Promise((resolve, reject) => {
104
+ sgMail
105
+ .send(msg)
106
+ .then((response) => {
107
+ logger_1.Logger.info('EmailHandler: Successfull Response', 'sendEmail');
108
+ resolve(response[0]);
109
+ })
110
+ .catch((error) => {
111
+ logger_1.Logger.error('EmailHandler: Error in sendEmail', 'sendEmail', error);
112
+ reject(error);
113
+ // throw error;
114
+ });
115
+ });
116
+ });
117
+ }
118
+ prepareEmailRequest(reqBody, emailType) {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ var _a, _b;
121
+ logger_1.Logger.info('Reached prepareEmailRequest', 'prepareEmailRequest');
122
+ try {
123
+ let dataSource = new emailDataSource_1.EmailDataSource();
124
+ logger_1.Logger.debug('Before preparing email request', 'prepareEmailRequest', dataSource);
125
+ let response = yield dataSource.fetchPageModel(emailType);
126
+ logger_1.Logger.debug('Response for preparing email request', 'prepareEmailRequest', response);
127
+ const start = moment.tz(reqBody.dateTime, 'UTC'); // original timezone
128
+ let curentTimeZone = start
129
+ .tz(reqBody.timezoneOffset)
130
+ .format('Do MMMM YYYY, h:mm a');
131
+ const root = HTMLParser.parse((_a = response[0]) === null || _a === void 0 ? void 0 : _a.hclplatformx_Body);
132
+ root.querySelector('#1_dynamic_text').textContent = ` ${reqBody.userName}`;
133
+ root.querySelector('#2_dynamic_text').textContent = DOMPurify.sanitize(`<b> ${reqBody.pageTitle} </b>`);
134
+ root.querySelector('#3_dynamic_text').textContent = DOMPurify.sanitize(`<b>${curentTimeZone}</b>`);
135
+ root.querySelector('#dynamic_contentType').textContent = DOMPurify.sanitize(`<b>${reqBody.contentType}</b>`);
136
+ root.querySelector('#dynamic_event').textContent = DOMPurify.sanitize(`<b>${reqBody.event[0] + reqBody.event.slice(1)}</b>`);
137
+ if (((_b = reqBody === null || reqBody === void 0 ? void 0 : reqBody.event) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'published') {
138
+ root
139
+ .querySelector('.dynamic_links_btn')
140
+ .setAttribute('href', reqBody.publishPageUrl);
141
+ }
142
+ else {
143
+ root.querySelector('#viewButton').setAttribute('style', 'display:none');
144
+ }
145
+ const append = root.querySelector('head');
146
+ append.insertAdjacentHTML('beforeend', DOMPurify.sanitize(style_1.style));
147
+ let emailConfiguration = {
148
+ email: reqBody.emailTo,
149
+ emailTemplate: root.toString(),
150
+ subject: DOMPurify.sanitize(response[0].hclplatformx_Subject.replace('{{pageType}}', reqBody.contentType[0] + reqBody.contentType.slice(1))
151
+ .replace('{{publishOrUnpublish}}', reqBody.event[0] + reqBody.event.slice(1))),
152
+ };
153
+ logger_1.Logger.debug('Reached prepareEmailRequest - emailConfiguration', 'prepareEmailRequest', emailConfiguration);
154
+ let emailResponse = yield this.pushEmails(emailConfiguration);
155
+ logger_1.Logger.debug('Reached prepareEmailRequest - emailResponse', 'prepareEmailRequest', emailResponse);
156
+ return emailResponse;
157
+ }
158
+ catch (error) {
159
+ logger_1.Logger.error('EmailHandler: Error in preparing email Request', 'prepareEmailRequest', error);
160
+ throw error;
161
+ }
162
+ });
163
+ }
164
+ /**
165
+ *
166
+ * @param reqBody
167
+ * @param emailType
168
+ * @returns
169
+ */
170
+ prepareSendEmailRequest(reqBody, emailType) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ var _a, _b, _c, _d;
173
+ logger_1.Logger.info('Reached prepareSendEmailRequest in emailHandler', 'prepareSendEmailRequest');
174
+ try {
175
+ let dataSource = new emailDataSource_1.EmailDataSource();
176
+ // disable SOLR because of connectivity issue
177
+ let templateData = yield dataSource.fetchPageModel(emailType);
178
+ if ((reqBody === null || reqBody === void 0 ? void 0 : reqBody.replacement_variables) && (templateData === null || templateData === void 0 ? void 0 : templateData.length)) {
179
+ for (const key in reqBody.replacement_variables) {
180
+ if (key) {
181
+ templateData[0].hclplatformx_Body =
182
+ (_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]);
183
+ }
184
+ }
185
+ }
186
+ const root = HTMLParser.parse((_c = templateData[0]) === null || _c === void 0 ? void 0 : _c.hclplatformx_Body);
187
+ let emailConfiguration = {
188
+ email: (_d = reqBody.replacement_variables) === null || _d === void 0 ? void 0 : _d.EMAIL,
189
+ emailTemplate: root ? root.toString() : '',
190
+ subject: constants_1.CREATE_USER_EMAIL_TEMPLATE[0].subject,
191
+ };
192
+ logger_1.Logger.debug('Reached prepareSendEmailRequest - emailConfiguration', 'prepareSendEmailRequest', emailConfiguration);
193
+ let emailResponse = yield this.pushEmails(emailConfiguration);
194
+ logger_1.Logger.debug('Reached prepareSendEmailRequest - emailResponse END', 'prepareSendEmailRequest', emailResponse);
195
+ return emailResponse;
196
+ }
197
+ catch (error) {
198
+ logger_1.Logger.error('EmailHandler: Error in preparing email Request', 'prepareEmailRequest', error);
199
+ throw error;
200
+ }
201
+ });
202
+ }
203
+ /**
204
+ *
205
+ * @param emailConfiguration
206
+ * @returns
207
+ */
208
+ pushEmails(emailConfiguration) {
209
+ return __awaiter(this, void 0, void 0, function* () {
210
+ logger_1.Logger.info('Reached pushEmails in emailHandler', 'pushEmails');
211
+ return yield this.sendEmail(emailConfiguration).then((response) => __awaiter(this, void 0, void 0, function* () {
212
+ if ((response === null || response === void 0 ? void 0 : response.statusCode) === '202' || response.statusCode === 202) {
213
+ response.msg =
214
+ 'Thanks for getting in touch with us. We shall contact you soon.';
215
+ return response;
216
+ }
217
+ else {
218
+ logger_1.Logger.error('solrResolver: Error in sendEmail resolver', 'sendEmail', response);
219
+ throw new Error('Error Sending in Email');
220
+ }
221
+ }));
222
+ });
223
+ }
224
+ /**
225
+ * Function to send email with personalize data using sendgrid
226
+ * @param emailConfig
227
+ * @returns
228
+ */
229
+ sendEmailWithPersonalizations(emailConfig, email_from) {
230
+ return __awaiter(this, void 0, void 0, function* () {
231
+ logger_1.Logger.info(`EmailHandler: Reached sendEmailWithPersonalizations method with emailConfig: ${JSON.stringify(emailConfig)}`, 'sendEmailWithPersonalizations');
232
+ logger_1.Logger.info(`EMAIL_FROM-------> ${email_from}`, 'sendEmailWithPersonalizations');
233
+ const Mail = sgHelpers.classes.Mail;
234
+ // let email_from = isCFF ? config?.CFF_MAIL_FROM : config?.EMAIL_FROM;
235
+ logger_1.Logger.info('sendEmailWithPersonalizations : Email From:', JSON.stringify(email_from));
236
+ const Personalization = sgHelpers.classes.Personalization;
237
+ const secrets = yield (0, __1.getIAMSecrets)();
238
+ sgMail.setApiKey(secrets === null || secrets === void 0 ? void 0 : secrets[constants_1.DynamicValues === null || constants_1.DynamicValues === void 0 ? void 0 : constants_1.DynamicValues.SENDGRID_API_KEY]);
239
+ const mail = new Mail();
240
+ mail.setFrom(email_from);
241
+ mail.setSubject(emailConfig.subject);
242
+ mail.addTextContent(emailConfig.emailTemplate);
243
+ mail.addHtmlContent(emailConfig.emailTemplate);
244
+ // Set personalizations as per the emailConfig
245
+ if ((emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.personalizations) &&
246
+ (emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.personalizations.to.length)) {
247
+ const { to, cc } = emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.personalizations;
248
+ // Create separate personalization for each TO recipient with their unique substitutions
249
+ to.forEach((toData, index) => {
250
+ const personalization = new Personalization();
251
+ personalization.addTo(toData.to);
252
+ // Add CC emails to EACH personalization (CC gets email for each TO recipient)
253
+ if (cc && cc.length > 0) {
254
+ cc.forEach((ccData) => {
255
+ personalization.addCc(ccData.to);
256
+ logger_1.Logger.info(`Adding CC email ${ccData.to} to personalization ${index + 1} for TO: ${toData.to}`, 'sendEmailWithPersonalizations');
257
+ });
258
+ }
259
+ // Add unique substitutions for each TO recipient
260
+ if (toData === null || toData === void 0 ? void 0 : toData.substitutions) {
261
+ for (const key in toData === null || toData === void 0 ? void 0 : toData.substitutions) {
262
+ if (key) {
263
+ personalization === null || personalization === void 0 ? void 0 : personalization.addSubstitution(key, toData === null || toData === void 0 ? void 0 : toData.substitutions[key]);
264
+ }
265
+ }
266
+ }
267
+ mail.addPersonalization(personalization);
268
+ logger_1.Logger.info(`Personalization ${index + 1} created for TO: ${toData.to} with ${(cc === null || cc === void 0 ? void 0 : cc.length) || 0} CC recipients`, 'sendEmailWithPersonalizations');
269
+ });
270
+ // Handle attachments
271
+ if ((emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.attachments) && Array.isArray(emailConfig.attachments)) {
272
+ emailConfig.attachments.forEach((attachment) => {
273
+ mail.addAttachment({
274
+ content: attachment.base64, // base64 string
275
+ filename: attachment.filename,
276
+ type: attachment.type || 'application/octet-stream',
277
+ disposition: 'attachment',
278
+ });
279
+ });
280
+ logger_1.Logger.info('sendEmailWithPersonalizations: Email Request:', JSON.stringify(emailConfig));
281
+ }
282
+ }
283
+ else {
284
+ // set to email for non personalized email with CC support
285
+ const personalization = new Personalization();
286
+ personalization.addTo(emailConfig.email);
287
+ // Add CC emails if provided in non-personalized mode
288
+ if (emailConfig.cc) {
289
+ const ccEmails = Array.isArray(emailConfig.cc) ? emailConfig.cc : [emailConfig.cc];
290
+ ccEmails.forEach((ccEmail) => {
291
+ personalization.addCc(ccEmail);
292
+ logger_1.Logger.info(`Adding CC email to non-personalized email: ${ccEmail}`, 'sendEmailWithPersonalizations');
293
+ });
294
+ }
295
+ logger_1.Logger.info('sendEmailWithPersonalizations : Email personalizations:', JSON.stringify(personalization));
296
+ mail.addPersonalization(personalization);
297
+ }
298
+ return new Promise((resolve, reject) => {
299
+ sgMail
300
+ .send(mail)
301
+ .then((response) => {
302
+ logger_1.Logger.info(`EmailHandler: Successful Response from sendEmailWithPersonalizations: ${JSON.stringify(response)}`, 'sendEmailWithPersonalizations');
303
+ resolve(response[0]);
304
+ })
305
+ .catch((error) => {
306
+ logger_1.Logger.error(`EmailHandler: Error in sendEmailWithPersonalizations: ${JSON.stringify(error)}`, 'sendEmail', error);
307
+ reject(error);
308
+ });
309
+ });
310
+ });
311
+ }
312
+ /**
313
+ * Utility method to prepare CC emails in standardized format
314
+ * @param ccEmails - Can be string, array of strings, or Recipients array
315
+ * @returns Array of email strings
316
+ */
317
+ prepareCCEmails(ccEmails) {
318
+ if (!ccEmails)
319
+ return [];
320
+ if (typeof ccEmails === 'string') {
321
+ return [ccEmails];
322
+ }
323
+ if (Array.isArray(ccEmails)) {
324
+ return ccEmails.map((cc) => {
325
+ if (typeof cc === 'string')
326
+ return cc;
327
+ if (cc.email)
328
+ return cc.email; // Recipients object
329
+ return cc.to || cc; // ToWithSubstitutions object
330
+ }).filter(email => email && typeof email === 'string');
331
+ }
332
+ return [];
333
+ }
334
+ /**
335
+ * prepare personalize email request to send email through sendgrid
336
+ * @param reqBody
337
+ * @returns
338
+ */
339
+ sendPersonalizeEmailRequest(reqBody) {
340
+ return __awaiter(this, void 0, void 0, function* () {
341
+ var _a, _b;
342
+ try {
343
+ let { email_type, replacement_variables, recipients, cc_recipients, isCFF = config_1.default === null || config_1.default === void 0 ? void 0 : config_1.default.EMAIL_FROM } = reqBody;
344
+ logger_1.Logger.info(`EmailHandler: reached in sendPersonalizeEmailRequest with emailType: ${email_type} and ${isCFF}`, 'sendPersonalizeEmailRequest');
345
+ // disable SOLR because of connectivity issue
346
+ logger_1.Logger.debug('Reached sendPersonalizeEmailRequest in emailHandler', 'sendPersonalizeEmailRequest');
347
+ let templateData = yield this.fetchEmailTemplateData(reqBody);
348
+ logger_1.Logger.debug('Reached sendPersonalizeEmailRequest in emailHandler', 'sendPersonalizeEmailRequest', templateData);
349
+ let recipientsData = {};
350
+ if ((0, lodash_1.isArray)(recipients)) {
351
+ const to = [];
352
+ recipients.forEach((recipient) => {
353
+ const substitutions = Object.assign(Object.assign({}, replacement_variables), { recipient_name: recipient === null || recipient === void 0 ? void 0 : recipient.name });
354
+ to.push({
355
+ to: recipient === null || recipient === void 0 ? void 0 : recipient.email,
356
+ substitutions,
357
+ });
358
+ });
359
+ recipientsData = {
360
+ to,
361
+ };
362
+ // Add CC recipients if they exist
363
+ if (cc_recipients && (0, lodash_1.isArray)(cc_recipients)) {
364
+ const cc = [];
365
+ cc_recipients.forEach((ccRecipient) => {
366
+ cc.push({
367
+ to: ccRecipient === null || ccRecipient === void 0 ? void 0 : ccRecipient.email,
368
+ });
369
+ });
370
+ recipientsData.cc = cc;
371
+ }
372
+ }
373
+ if (templateData && ((_a = Object.keys(templateData)) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
374
+ const root = HTMLParser.parse(templateData === null || templateData === void 0 ? void 0 : templateData.body);
375
+ const emailConfiguration = {
376
+ email: (_b = reqBody.replacement_variables) === null || _b === void 0 ? void 0 : _b.EMAIL,
377
+ emailTemplate: root ? root.toString() : '',
378
+ subject: templateData === null || templateData === void 0 ? void 0 : templateData.subject,
379
+ personalizations: recipientsData,
380
+ attachments: reqBody === null || reqBody === void 0 ? void 0 : reqBody.attachments,
381
+ };
382
+ // let is_cff: boolean = (isCFF && isCFF === true) ? true : false;
383
+ logger_1.Logger.info(`sendPersonalizeEmailRequest -${JSON.stringify(emailConfiguration)}`, 'sendPersonalizeEmailRequest');
384
+ return yield this.sendEmailWithPersonalizations(emailConfiguration, isCFF).then((response) => __awaiter(this, void 0, void 0, function* () {
385
+ if (response.statusCode === 202) {
386
+ response.msg =
387
+ 'Thanks for getting in touch with us. We shall contact you soon.';
388
+ console.log('>>>>>>>>>>>>>>>>>>>>>>>>>.RES', response);
389
+ return response;
390
+ }
391
+ else {
392
+ logger_1.Logger.error(`EmailHandler: Error in sendEmailWithPersonalizations response - ${JSON.stringify(response)}`, 'sendEmailWithPersonalizations', response);
393
+ throw new Error('Error Sending in Email');
394
+ }
395
+ }));
396
+ }
397
+ }
398
+ catch (error) {
399
+ logger_1.Logger.error('EmailHandler: Error in preparing email Request', 'prepareEmailRequest', error);
400
+ throw error;
401
+ }
402
+ });
403
+ }
404
+ sendPlaceOrderEmail(reqBody) {
405
+ return __awaiter(this, void 0, void 0, function* () {
406
+ logger_1.Logger.info('Redached sendPlaceOrderEmail', 'sendPlaceOrderEmail');
407
+ try {
408
+ let dataSource = new emailDataSource_1.EmailDataSource();
409
+ yield dataSource.fetchPageModel('orderPlaced');
410
+ const start = moment.tz(reqBody.dateTime, 'UTC'); // original timezone
411
+ start.tz(reqBody.timezoneOffset).format('Do MMMM YYYY, h:mm a');
412
+ let str = yield emailTemplate_1.EmailTemplateHandler.prepareEmailTemplate(reqBody);
413
+ let root = HTMLParser.parse(str);
414
+ root.querySelector('#1_dynamic_text').textContent = `${reqBody.userName}`;
415
+ root.querySelector('#2_dynamic_text').textContent = DOMPurify.sanitize(`<b> ${reqBody.total_price} </b>`);
416
+ root.querySelector('#3_dynamic_text').textContent = DOMPurify.sanitize(`<b>${reqBody.currency_code}</b>`);
417
+ 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>`);
418
+ root.querySelector('#5_dynamic_text').textContent = DOMPurify.sanitize(`<b>${reqBody.total_tax}</b>`);
419
+ root.querySelector('#6_dynamic_text').textContent = DOMPurify.sanitize(`<b>${reqBody.orderNumber}</b>`);
420
+ const apeend = root.querySelector('head');
421
+ apeend.insertAdjacentHTML('beforeend', DOMPurify.sanitize(style_1.style));
422
+ let emailConfiguration = {
423
+ email: reqBody.emailTo,
424
+ emailTemplate: root.toString(),
425
+ subject: 'Order Confirmation',
426
+ };
427
+ let emailResponse = yield this.pushEmails(emailConfiguration);
428
+ return emailResponse;
429
+ }
430
+ catch (error) {
431
+ logger_1.Logger.error('EmailHandler: Error in preparing email Request', 'prepareEmailRequest', error);
432
+ throw error;
433
+ }
434
+ });
435
+ }
436
+ sendPlaceOrderEmailv1(reqBody) {
437
+ return __awaiter(this, void 0, void 0, function* () {
438
+ logger_1.Logger.info('Redached sendPlaceOrderEmailv1', 'sendPlaceOrderEmailv1');
439
+ try {
440
+ let dataSource = new emailDataSource_1.EmailDataSource();
441
+ yield dataSource.fetchPageModel('orderPlaced');
442
+ const start = moment.tz(reqBody.dateTime, 'UTC'); // original timezone
443
+ let curentTimeZone = start;
444
+ curentTimeZone.tz(reqBody.timezoneOffset).format('Do MMMM YYYY, h:mm a');
445
+ const emailTemplate = path_1.default.resolve(__dirname, '../../../templates/orderPlaced.ejs');
446
+ console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>.', emailTemplate);
447
+ let billingStr = '';
448
+ billingStr +=
449
+ Object.keys(reqBody.billing_address).length !== 0
450
+ ? `${reqBody.billing_address.street_name}` ||
451
+ '' + `${reqBody.billing_address.city}` ||
452
+ '' + `${reqBody.billing_address.state}` ||
453
+ '' + `${reqBody.billing_address.country}` ||
454
+ '' + `${reqBody.billing_address.postal_code}` ||
455
+ ''
456
+ : '';
457
+ let shippingStr = '';
458
+ shippingStr +=
459
+ Object.keys(reqBody.shipping_address).length !== 0
460
+ ? `${reqBody.shipping_address.street_name}` ||
461
+ '' + `${reqBody.shipping_address.city}` ||
462
+ '' + ` ${reqBody.shipping_address.state}` ||
463
+ '' + ` ${reqBody.shipping_address.country}` ||
464
+ '' + `${reqBody.shipping_address.postal_code}` ||
465
+ ''
466
+ : '';
467
+ let templateData = yield ejs.renderFile(emailTemplate, {
468
+ userName: reqBody.userName,
469
+ orderNumber: reqBody.orderNumber,
470
+ completeAddressStr: billingStr || shippingStr,
471
+ total_tax: `${reqBody.total_tax}`,
472
+ total_price: `${reqBody.total_price}`,
473
+ data: reqBody.line_item,
474
+ });
475
+ if (templateData) {
476
+ let emailConfiguration = {
477
+ email: reqBody.emailTo,
478
+ emailTemplate: templateData,
479
+ subject: 'Order Confirmation',
480
+ };
481
+ let emailResponse = yield this.pushEmails(emailConfiguration);
482
+ return emailResponse;
483
+ }
484
+ else {
485
+ return 'Error while rendering template';
486
+ }
487
+ }
488
+ catch (error) {
489
+ logger_1.Logger.error('EmailHandler: Error in preparing email Request', 'prepareEmailRequest', error);
490
+ throw error;
491
+ }
492
+ });
493
+ }
494
+ fetchEmailTemplateData(reqBody) {
495
+ return __awaiter(this, void 0, void 0, function* () {
496
+ var _a, _b, _c, _d;
497
+ try {
498
+ logger_1.Logger.info('EmailHandler: Reached fetchEmailTemplateData', 'fetchEmailTemplateData');
499
+ let { email_type } = reqBody;
500
+ let dataSource = new emailDataSource_1.EmailDataSource();
501
+ let templateData = {};
502
+ if ((config_1.default === null || config_1.default === void 0 ? void 0 : config_1.default.MULTISITE_WITH_SOLR) === 'true') {
503
+ let templateSolrRes = yield dataSource.fetchPageModel(email_type);
504
+ if ((templateSolrRes === null || templateSolrRes === void 0 ? void 0 : templateSolrRes.length) > 0) {
505
+ templateData.body = ((_a = templateSolrRes === null || templateSolrRes === void 0 ? void 0 : templateSolrRes[0]) === null || _a === void 0 ? void 0 : _a.hclplatformx_Body) || '';
506
+ templateData.subject = ((_b = templateSolrRes === null || templateSolrRes === void 0 ? void 0 : templateSolrRes[0]) === null || _b === void 0 ? void 0 : _b.hclplatformx_Subject) || '';
507
+ }
508
+ }
509
+ else {
510
+ let templateRes = yield new formBuilder_dao_1.default().fetch('email_templates', { name: email_type });
511
+ templateData.body = (_c = templateRes === null || templateRes === void 0 ? void 0 : templateRes[0]) === null || _c === void 0 ? void 0 : _c.body;
512
+ templateData.subject = (_d = templateRes === null || templateRes === void 0 ? void 0 : templateRes[0]) === null || _d === void 0 ? void 0 : _d.subject;
513
+ }
514
+ return templateData;
515
+ }
516
+ catch (error) {
517
+ logger_1.Logger.error('EmailHandler: Error in fetchEmailTemplateData', 'fetchEmailTemplateData', error);
518
+ throw error;
519
+ }
520
+ });
521
+ }
522
+ }
523
+ exports.EmailHandler = EmailHandler;
524
+ //# sourceMappingURL=emailHandler.js.map
@@ -0,0 +1,4 @@
1
+ export declare class EmailTemplateHandler {
2
+ constructor();
3
+ static prepareEmailTemplate(reqBody: any): Promise<string>;
4
+ }
@@ -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,26 @@
1
+ export interface Pagination {
2
+ start: number;
3
+ rows: number;
4
+ }
5
+ export interface FilterQueryType {
6
+ field: string;
7
+ value: string;
8
+ }
9
+ export interface SolrQueryRequest {
10
+ query: string | object;
11
+ filterQuery?: FilterQueryType[] | null | any;
12
+ pagination?: Pagination;
13
+ filter?: object | string[];
14
+ sort?: object;
15
+ }
16
+ export declare class SolrHttpDataSource<TContext = any> {
17
+ private solr;
18
+ context: TContext;
19
+ private cache;
20
+ private memoizedResults;
21
+ constructor();
22
+ cacheKey(id: string): string;
23
+ memoizedCacheKey(): string;
24
+ createQuery(queryRequest: SolrQueryRequest): void;
25
+ executeSearch(): Promise<any>;
26
+ }