@contentgrowth/content-emailing 0.2.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentgrowth/content-emailing",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "Unified email delivery and template management system",
6
6
  "main": "src/index.js",
@@ -240,7 +240,11 @@ export class EmailService {
240
240
  * @param {Object} [params.metadata] - Additional metadata
241
241
  * @returns {Promise<Object>} Delivery result
242
242
  */
243
- async sendEmail({ to, subject, html, text, provider, profile = 'system', tenantId = null, metadata = {} }) {
243
+ async sendEmail({ to, subject, html, htmlBody, text, textBody, provider, profile = 'system', tenantId = null, metadata = {} }) {
244
+ // Backward compatibility: accept htmlBody/textBody as aliases
245
+ const htmlContent = html || htmlBody;
246
+ const textContent = text || textBody;
247
+
244
248
  try {
245
249
  const settings = await this.loadSettings(profile, tenantId);
246
250
  const useProvider = provider || settings.provider || 'mailchannels';
@@ -249,16 +253,16 @@ export class EmailService {
249
253
 
250
254
  switch (useProvider) {
251
255
  case 'mailchannels':
252
- result = await this.sendViaMailChannels(to, subject, html, text, settings, metadata);
256
+ result = await this.sendViaMailChannels(to, subject, htmlContent, textContent, settings, metadata);
253
257
  break;
254
258
  case 'sendgrid':
255
- result = await this.sendViaSendGrid(to, subject, html, text, settings, metadata);
259
+ result = await this.sendViaSendGrid(to, subject, htmlContent, textContent, settings, metadata);
256
260
  break;
257
261
  case 'resend':
258
- result = await this.sendViaResend(to, subject, html, text, settings, metadata);
262
+ result = await this.sendViaResend(to, subject, htmlContent, textContent, settings, metadata);
259
263
  break;
260
264
  case 'sendpulse':
261
- result = await this.sendViaSendPulse(to, subject, html, text, settings, metadata);
265
+ result = await this.sendViaSendPulse(to, subject, htmlContent, textContent, settings, metadata);
262
266
  break;
263
267
  default:
264
268
  console.error(`[EmailService] Unknown provider: ${useProvider}`);
@@ -441,7 +445,16 @@ export class EmailService {
441
445
  }
442
446
 
443
447
  const { access_token } = tokenData;
444
- const toBase64 = (str) => Buffer.from(str).toString('base64');
448
+
449
+ // Safe base64 encoding
450
+ const toBase64 = (str) => {
451
+ if (!str) return '';
452
+ return Buffer.from(String(str)).toString('base64');
453
+ };
454
+
455
+ // Ensure html/text are strings
456
+ const htmlSafe = html || '';
457
+ const textSafe = text || (htmlSafe ? htmlSafe.replace(/<[^>]*>/g, '') : '');
445
458
 
446
459
  // Send the email
447
460
  const response = await fetch('https://api.sendpulse.com/smtp/emails', {
@@ -452,8 +465,8 @@ export class EmailService {
452
465
  },
453
466
  body: JSON.stringify({
454
467
  email: {
455
- html: toBase64(html),
456
- text: toBase64(text || html.replace(/<[^>]*>/g, '')),
468
+ html: toBase64(htmlSafe),
469
+ text: toBase64(textSafe),
457
470
  subject,
458
471
  from: { name: settings.fromName, email: settings.fromAddress },
459
472
  to: [{ name: metadata.recipientName || '', email: to }],