@platform-x/hep-notification-client 1.1.20 → 1.2.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.
- package/dist/src/common/service/secretKeyManager.services.d.ts +7 -0
- package/dist/src/common/service/secretKeyManager.services.js +58 -0
- package/dist/src/common/service/twilioService.d.ts +2 -1
- package/dist/src/common/service/twilioService.js +11 -4
- package/dist/src/config/index.d.ts +1 -0
- package/dist/src/config/index.js +1 -0
- package/dist/src/platform-x/constants/index.d.ts +7 -0
- package/dist/src/platform-x/constants/index.js +8 -1
- package/dist/src/platform-x/database/connection.d.ts +1 -1
- package/dist/src/platform-x/database/connection.js +7 -3
- package/dist/src/platform-x/database/index.d.ts +1 -1
- package/dist/src/platform-x/database/models/formBuilder.model.d.ts +5 -17
- package/dist/src/platform-x/util/emailHandler.d.ts +7 -0
- package/dist/src/platform-x/util/emailHandler.js +76 -13
- package/package.json +6 -5
|
@@ -0,0 +1,58 @@
|
|
|
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.SecretKeyServices = void 0;
|
|
16
|
+
const hep_secret_access_1 = require("hep-secret-access");
|
|
17
|
+
const config_1 = __importDefault(require("../../config"));
|
|
18
|
+
const constants_1 = require("../../platform-x/constants");
|
|
19
|
+
class SecretKeyServices {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.ruleCache = new Map();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Fetches all the secret keys
|
|
25
|
+
*/
|
|
26
|
+
getSecretKeys() {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
try {
|
|
29
|
+
// Initialize secret manager object
|
|
30
|
+
if (this.ruleCache.has('secret_data')) {
|
|
31
|
+
return this.ruleCache.get('secret_data');
|
|
32
|
+
}
|
|
33
|
+
const secretObject = (0, hep_secret_access_1.secretManager)();
|
|
34
|
+
// If secret mode is ENV – read one by one
|
|
35
|
+
// for local testing
|
|
36
|
+
if ((config_1.default === null || config_1.default === void 0 ? void 0 : config_1.default.SECRET_MODE) === 'env') {
|
|
37
|
+
const keyConfig = {};
|
|
38
|
+
for (const key of Object.values(constants_1.DynamicValues)) {
|
|
39
|
+
// Fetch individual value (existing read() method)
|
|
40
|
+
const value = yield secretObject.read(key);
|
|
41
|
+
keyConfig[key] = value;
|
|
42
|
+
}
|
|
43
|
+
this.ruleCache.set('secret_data', keyConfig);
|
|
44
|
+
return keyConfig;
|
|
45
|
+
}
|
|
46
|
+
// else – fetch all secrets from GSM
|
|
47
|
+
const data = yield secretObject.readAllSecrets();
|
|
48
|
+
this.ruleCache.set('secret_data', data);
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.SecretKeyServices = SecretKeyServices;
|
|
58
|
+
//# sourceMappingURL=secretKeyManager.services.js.map
|
|
@@ -7,7 +7,8 @@ export declare class TwilioService {
|
|
|
7
7
|
* @param authToken - Twilio Auth Token
|
|
8
8
|
* @param senderNumber - Twilio Sender Phone Number
|
|
9
9
|
*/
|
|
10
|
-
constructor();
|
|
10
|
+
private constructor();
|
|
11
|
+
static TwilioClassObject(): Promise<TwilioService>;
|
|
11
12
|
/**
|
|
12
13
|
* Send an SMS using Twilio
|
|
13
14
|
* @param to - Recipient's phone number
|
|
@@ -15,7 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.TwilioService = void 0;
|
|
16
16
|
const twilio_1 = __importDefault(require("twilio"));
|
|
17
17
|
const logger_1 = require("../util/logger");
|
|
18
|
-
const
|
|
18
|
+
const secretKeyManager_services_1 = require("./secretKeyManager.services");
|
|
19
|
+
const constants_1 = require("../../platform-x/constants");
|
|
19
20
|
class TwilioService {
|
|
20
21
|
/**
|
|
21
22
|
* Constructor to initialize Twilio client and sender number
|
|
@@ -23,9 +24,15 @@ class TwilioService {
|
|
|
23
24
|
* @param authToken - Twilio Auth Token
|
|
24
25
|
* @param senderNumber - Twilio Sender Phone Number
|
|
25
26
|
*/
|
|
26
|
-
constructor() {
|
|
27
|
-
this.client = (0, twilio_1.default)(
|
|
28
|
-
this.senderNumber =
|
|
27
|
+
constructor(twilioConfig) {
|
|
28
|
+
this.client = (0, twilio_1.default)(twilioConfig === null || twilioConfig === void 0 ? void 0 : twilioConfig[constants_1.DynamicValues === null || constants_1.DynamicValues === void 0 ? void 0 : constants_1.DynamicValues.TWILIO_ACCOUNT_SID], twilioConfig === null || twilioConfig === void 0 ? void 0 : twilioConfig[constants_1.DynamicValues === null || constants_1.DynamicValues === void 0 ? void 0 : constants_1.DynamicValues.TWILIO_AUTH_TOKEN]);
|
|
29
|
+
this.senderNumber = twilioConfig === null || twilioConfig === void 0 ? void 0 : twilioConfig[constants_1.DynamicValues === null || constants_1.DynamicValues === void 0 ? void 0 : constants_1.DynamicValues.TWILIO_SENDER_NUMBER];
|
|
30
|
+
}
|
|
31
|
+
static TwilioClassObject() {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const secrets = yield new secretKeyManager_services_1.SecretKeyServices().getSecretKeys();
|
|
34
|
+
return new TwilioService(secrets);
|
|
35
|
+
});
|
|
29
36
|
}
|
|
30
37
|
/**
|
|
31
38
|
* Send an SMS using Twilio
|
package/dist/src/config/index.js
CHANGED
|
@@ -9,3 +9,10 @@ export declare const TRACE_ID_HEADER_NAME = "Platform-X-Trace-Id";
|
|
|
9
9
|
export declare const DEFAULT_APP_PORT = 8080;
|
|
10
10
|
export declare const DEFAULT_APP_NAME = "api-gateway";
|
|
11
11
|
export declare const DEFAULT_REALM_NAME = "platform-x";
|
|
12
|
+
export declare const DynamicValues: {
|
|
13
|
+
SENDGRID_API_KEY: string;
|
|
14
|
+
TWILIO_ACCOUNT_SID: string;
|
|
15
|
+
TWILIO_AUTH_TOKEN: string;
|
|
16
|
+
TWILIO_SENDER_NUMBER: string;
|
|
17
|
+
MONGO_PASS: string;
|
|
18
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_REALM_NAME = exports.DEFAULT_APP_NAME = exports.DEFAULT_APP_PORT = exports.TRACE_ID_HEADER_NAME = exports.HTTP_CONTENT_TYPE_JSON = exports.CREATE_USER_EMAIL_TEMPLATE = exports.DEFAULT_SOLR_ROWS = void 0;
|
|
3
|
+
exports.DynamicValues = exports.DEFAULT_REALM_NAME = exports.DEFAULT_APP_NAME = exports.DEFAULT_APP_PORT = exports.TRACE_ID_HEADER_NAME = exports.HTTP_CONTENT_TYPE_JSON = exports.CREATE_USER_EMAIL_TEMPLATE = exports.DEFAULT_SOLR_ROWS = void 0;
|
|
4
4
|
exports.DEFAULT_SOLR_ROWS = 2147483647;
|
|
5
5
|
exports.CREATE_USER_EMAIL_TEMPLATE = [{
|
|
6
6
|
subject: 'Plat-x User Registration',
|
|
@@ -12,4 +12,11 @@ exports.TRACE_ID_HEADER_NAME = 'Platform-X-Trace-Id';
|
|
|
12
12
|
exports.DEFAULT_APP_PORT = 8080;
|
|
13
13
|
exports.DEFAULT_APP_NAME = 'api-gateway';
|
|
14
14
|
exports.DEFAULT_REALM_NAME = 'platform-x';
|
|
15
|
+
exports.DynamicValues = {
|
|
16
|
+
SENDGRID_API_KEY: 'SENDGRID_API_KEY',
|
|
17
|
+
TWILIO_ACCOUNT_SID: 'TWILIO_ACCOUNT_SID',
|
|
18
|
+
TWILIO_AUTH_TOKEN: 'TWILIO_AUTH_TOKEN',
|
|
19
|
+
TWILIO_SENDER_NUMBER: 'TWILIO_SENDER_NUMBER',
|
|
20
|
+
MONGO_PASS: 'MONGO_PASS',
|
|
21
|
+
};
|
|
15
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -15,17 +15,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
16
16
|
const logger_1 = require("../../common/util/logger");
|
|
17
17
|
const index_1 = __importDefault(require("../../config/index"));
|
|
18
|
+
const secretKeyManager_services_1 = require("../../common/service/secretKeyManager.services");
|
|
19
|
+
const constants_1 = require("../constants");
|
|
18
20
|
let database = mongoose_1.default.connection;
|
|
19
21
|
// Exit on error
|
|
20
22
|
mongoose_1.default.connection.on('error', (err) => {
|
|
21
23
|
logger_1.Logger.info(`MongoDB connection error: ${err}`, 'mongoose');
|
|
22
24
|
process.exit(-1);
|
|
23
25
|
});
|
|
24
|
-
const connect = () => {
|
|
26
|
+
const connect = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
27
|
if (database.readyState) {
|
|
26
28
|
return;
|
|
27
29
|
}
|
|
28
|
-
|
|
30
|
+
const secrets = yield new secretKeyManager_services_1.SecretKeyServices().getSecretKeys();
|
|
31
|
+
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>.', secrets);
|
|
32
|
+
mongoose_1.default.connect(`mongodb://${index_1.default.MONGO.USER}:${secrets === null || secrets === void 0 ? void 0 : secrets[constants_1.DynamicValues === null || constants_1.DynamicValues === void 0 ? void 0 : constants_1.DynamicValues.MONGO_PASS]}@${index_1.default.MONGO.HOST}:${index_1.default.MONGO.PORT}/${index_1.default.MONGO.DB_NAME}?directConnection=true&authMechanism=DEFAULT&authSource=${index_1.default.MONGO.DB_NAME}`);
|
|
29
33
|
database = mongoose_1.default.connection;
|
|
30
34
|
database.once('open', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
35
|
logger_1.Logger.info(`[Server] connected to MongoDB`, 'connect');
|
|
@@ -34,7 +38,7 @@ const connect = () => {
|
|
|
34
38
|
logger_1.Logger.error(`[Server] error connecting to MongoDB`, 'connect', err);
|
|
35
39
|
process.exit(-1);
|
|
36
40
|
});
|
|
37
|
-
};
|
|
41
|
+
});
|
|
38
42
|
const disconnect = () => {
|
|
39
43
|
if (!database) {
|
|
40
44
|
return;
|
|
@@ -10,37 +10,25 @@ declare const dynamicModelName: (collectionName: string) => Promise<mongoose.Mod
|
|
|
10
10
|
} & {}, {}, {}, {}, mongoose.Document<unknown, {}, {
|
|
11
11
|
createdAt: NativeDate;
|
|
12
12
|
updatedAt: NativeDate;
|
|
13
|
-
} & {}
|
|
14
|
-
timestamps: true;
|
|
15
|
-
minimize: false;
|
|
16
|
-
strict: false;
|
|
17
|
-
}> & {
|
|
13
|
+
} & {}> & Omit<{
|
|
18
14
|
createdAt: NativeDate;
|
|
19
15
|
updatedAt: NativeDate;
|
|
20
16
|
} & {} & {
|
|
21
17
|
_id: mongoose.Types.ObjectId;
|
|
22
|
-
}
|
|
23
|
-
__v: number;
|
|
24
|
-
}, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
18
|
+
}, never>, mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, mongoose.ResolveSchemaOptions<{
|
|
25
19
|
timestamps: true;
|
|
26
20
|
minimize: false;
|
|
27
21
|
strict: false;
|
|
28
|
-
}
|
|
22
|
+
}>, {
|
|
29
23
|
createdAt: NativeDate;
|
|
30
24
|
updatedAt: NativeDate;
|
|
31
25
|
} & {}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
32
26
|
createdAt: NativeDate;
|
|
33
27
|
updatedAt: NativeDate;
|
|
34
|
-
} & {}
|
|
35
|
-
timestamps: true;
|
|
36
|
-
minimize: false;
|
|
37
|
-
strict: false;
|
|
38
|
-
}>> & mongoose.FlatRecord<{
|
|
28
|
+
} & {}>> & Omit<mongoose.FlatRecord<{
|
|
39
29
|
createdAt: NativeDate;
|
|
40
30
|
updatedAt: NativeDate;
|
|
41
31
|
} & {}> & {
|
|
42
32
|
_id: mongoose.Types.ObjectId;
|
|
43
|
-
}
|
|
44
|
-
__v: number;
|
|
45
|
-
}>>>;
|
|
33
|
+
}, never>>>>;
|
|
46
34
|
export default dynamicModelName;
|
|
@@ -3,6 +3,7 @@ interface EmailOptions {
|
|
|
3
3
|
emailTemplate: string;
|
|
4
4
|
subject: string;
|
|
5
5
|
bcc?: string;
|
|
6
|
+
cc?: string | string[];
|
|
6
7
|
personalizations?: Personalize;
|
|
7
8
|
}
|
|
8
9
|
interface Personalize {
|
|
@@ -42,6 +43,12 @@ export declare class EmailHandler {
|
|
|
42
43
|
* @returns
|
|
43
44
|
*/
|
|
44
45
|
sendEmailWithPersonalizations(emailConfig: any, isCFF?: any): Promise<unknown>;
|
|
46
|
+
/**
|
|
47
|
+
* Utility method to prepare CC emails in standardized format
|
|
48
|
+
* @param ccEmails - Can be string, array of strings, or Recipients array
|
|
49
|
+
* @returns Array of email strings
|
|
50
|
+
*/
|
|
51
|
+
private prepareCCEmails;
|
|
45
52
|
/**
|
|
46
53
|
* prepare personalize email request to send email through sendgrid
|
|
47
54
|
* @param reqBody
|
|
@@ -63,6 +63,7 @@ const dompurify_1 = __importDefault(require("dompurify"));
|
|
|
63
63
|
const jsdom_1 = require("jsdom");
|
|
64
64
|
const logger_1 = require("../../common/util/logger");
|
|
65
65
|
const path_1 = __importDefault(require("path"));
|
|
66
|
+
const secretKeyManager_services_1 = require("../../common/service/secretKeyManager.services");
|
|
66
67
|
const window = new jsdom_1.JSDOM('').window;
|
|
67
68
|
const DOMPurify = (0, dompurify_1.default)(window);
|
|
68
69
|
// NOSONAR-NEXT-LINE
|
|
@@ -76,14 +77,24 @@ class EmailHandler {
|
|
|
76
77
|
sendEmail(emailConfig) {
|
|
77
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
79
|
logger_1.Logger.info('EmailHandler: Reached sendEmail method', 'sendEmail');
|
|
79
|
-
|
|
80
|
+
const secrets = yield new secretKeyManager_services_1.SecretKeyServices().getSecretKeys();
|
|
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
|
+
}
|
|
80
96
|
const msg = {
|
|
81
|
-
personalizations: [
|
|
82
|
-
{
|
|
83
|
-
to: [{ email: emailConfig.email }],
|
|
84
|
-
// cc: emailCC,
|
|
85
|
-
},
|
|
86
|
-
],
|
|
97
|
+
personalizations: [personalization],
|
|
87
98
|
from: { email: config_1.default.EMAIL_FROM },
|
|
88
99
|
html: emailConfig.emailTemplate,
|
|
89
100
|
subject: emailConfig.subject,
|
|
@@ -218,12 +229,13 @@ class EmailHandler {
|
|
|
218
229
|
sendEmailWithPersonalizations(emailConfig, isCFF) {
|
|
219
230
|
return __awaiter(this, void 0, void 0, function* () {
|
|
220
231
|
logger_1.Logger.info(`EmailHandler: Reached sendEmailWithPersonalizations method with emailConfig: ${JSON.stringify(emailConfig)}`, 'sendEmailWithPersonalizations');
|
|
221
|
-
logger_1.Logger.info(`
|
|
232
|
+
logger_1.Logger.info(`EMAIL_FROM-------> ${config_1.default === null || config_1.default === void 0 ? void 0 : config_1.default.EMAIL_FROM}`, 'triggerEmails');
|
|
222
233
|
const Mail = sgHelpers.classes.Mail;
|
|
223
234
|
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;
|
|
224
235
|
logger_1.Logger.info('sendEmailWithPersonalizations : Email From:', JSON.stringify(email_from));
|
|
225
236
|
const Personalization = sgHelpers.classes.Personalization;
|
|
226
|
-
|
|
237
|
+
const secrets = yield new secretKeyManager_services_1.SecretKeyServices().getSecretKeys();
|
|
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]);
|
|
227
239
|
const mail = new Mail();
|
|
228
240
|
mail.setFrom(email_from);
|
|
229
241
|
mail.setSubject(emailConfig.subject);
|
|
@@ -232,10 +244,19 @@ class EmailHandler {
|
|
|
232
244
|
// Set personalizations as per the emailConfig
|
|
233
245
|
if ((emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.personalizations) &&
|
|
234
246
|
(emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.personalizations.to.length)) {
|
|
235
|
-
const { to } = emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.personalizations;
|
|
236
|
-
|
|
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) => {
|
|
237
250
|
const personalization = new Personalization();
|
|
238
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
|
|
239
260
|
if (toData === null || toData === void 0 ? void 0 : toData.substitutions) {
|
|
240
261
|
for (const key in toData === null || toData === void 0 ? void 0 : toData.substitutions) {
|
|
241
262
|
if (key) {
|
|
@@ -244,7 +265,9 @@ class EmailHandler {
|
|
|
244
265
|
}
|
|
245
266
|
}
|
|
246
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');
|
|
247
269
|
});
|
|
270
|
+
// Handle attachments
|
|
248
271
|
if ((emailConfig === null || emailConfig === void 0 ? void 0 : emailConfig.attachments) && Array.isArray(emailConfig.attachments)) {
|
|
249
272
|
emailConfig.attachments.forEach((attachment) => {
|
|
250
273
|
mail.addAttachment({
|
|
@@ -258,9 +281,17 @@ class EmailHandler {
|
|
|
258
281
|
}
|
|
259
282
|
}
|
|
260
283
|
else {
|
|
261
|
-
// set to email for non personalized email
|
|
284
|
+
// set to email for non personalized email with CC support
|
|
262
285
|
const personalization = new Personalization();
|
|
263
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
|
+
}
|
|
264
295
|
logger_1.Logger.info('sendEmailWithPersonalizations : Email personalizations:', JSON.stringify(personalization));
|
|
265
296
|
mail.addPersonalization(personalization);
|
|
266
297
|
}
|
|
@@ -278,6 +309,28 @@ class EmailHandler {
|
|
|
278
309
|
});
|
|
279
310
|
});
|
|
280
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
|
+
}
|
|
281
334
|
/**
|
|
282
335
|
* prepare personalize email request to send email through sendgrid
|
|
283
336
|
* @param reqBody
|
|
@@ -287,7 +340,7 @@ class EmailHandler {
|
|
|
287
340
|
return __awaiter(this, void 0, void 0, function* () {
|
|
288
341
|
var _a, _b;
|
|
289
342
|
try {
|
|
290
|
-
let { email_type, replacement_variables, recipients, isCFF = false } = reqBody;
|
|
343
|
+
let { email_type, replacement_variables, recipients, cc_recipients, isCFF = false } = reqBody;
|
|
291
344
|
logger_1.Logger.info(`EmailHandler: reached in sendPersonalizeEmailRequest with emailType: ${email_type}`, 'sendPersonalizeEmailRequest');
|
|
292
345
|
// disable SOLR because of connectivity issue
|
|
293
346
|
logger_1.Logger.debug('Reached sendPersonalizeEmailRequest in emailHandler', 'sendPersonalizeEmailRequest');
|
|
@@ -306,6 +359,16 @@ class EmailHandler {
|
|
|
306
359
|
recipientsData = {
|
|
307
360
|
to,
|
|
308
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
|
+
}
|
|
309
372
|
}
|
|
310
373
|
if (templateData && ((_a = Object.keys(templateData)) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
|
|
311
374
|
const root = (0, node_html_parser_1.parse)(templateData === null || templateData === void 0 ? void 0 : templateData.body);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platform-x/hep-notification-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "@platform-x/hep-notification-client",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@types/node": "^15.12.2",
|
|
32
32
|
"@types/twilio": "^3.19.2",
|
|
33
33
|
"apollo-server-caching": "^3.3.0",
|
|
34
|
+
"axios": "0.21.4",
|
|
34
35
|
"bunyan": "^1.8.15",
|
|
35
36
|
"bunyan-format": "^0.2.1",
|
|
36
37
|
"cls-hooked": "^4.2.2",
|
|
@@ -40,19 +41,19 @@
|
|
|
40
41
|
"ejs": "^3.1.10",
|
|
41
42
|
"express": "^4.17.1",
|
|
42
43
|
"fs": "^0.0.1-security",
|
|
44
|
+
"hep-secret-access": "^1.3.4",
|
|
43
45
|
"jsdom": "^26.1.0",
|
|
44
46
|
"lodash": "4.17.21",
|
|
45
47
|
"moment": "2.29.4",
|
|
46
48
|
"moment-timezone": "0.5.34",
|
|
49
|
+
"mongodb": "5.9.2",
|
|
50
|
+
"mongoose": "7.0.3",
|
|
47
51
|
"mysql2": "2.3.3",
|
|
48
52
|
"node-html-parser": "5.1.0",
|
|
49
53
|
"request-ip": "2.1.3",
|
|
50
54
|
"solr-client": "0.10.0-rc6",
|
|
51
55
|
"twilio": "^5.3.6",
|
|
52
|
-
"uuid": "8.3.2"
|
|
53
|
-
"mongodb": "5.9.2",
|
|
54
|
-
"mongoose": "7.0.3",
|
|
55
|
-
"axios": "0.21.4"
|
|
56
|
+
"uuid": "8.3.2"
|
|
56
57
|
},
|
|
57
58
|
"private": false,
|
|
58
59
|
"publishConfig": {
|