@punks/backend-entity-manager 0.0.41 → 0.0.43

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/cjs/index.js CHANGED
@@ -25015,8 +25015,11 @@ const WpSendgridEmailTemplate = (templateId, sendgridTemplateData) => common.app
25015
25015
 
25016
25016
  const sendgridSettings = new AppInMemorySettings();
25017
25017
 
25018
+ const sanitizeValue = (value) => value?.trim() ? value?.trim() : undefined;
25019
+ const sanitizeArray = (value) => (value?.length ?? 0) > 0 ? value : undefined;
25018
25020
  let SendgridEmailProvider = class SendgridEmailProvider {
25019
25021
  constructor() {
25022
+ this.logger = backendCore.Log.getLogger("Sendgrid");
25020
25023
  this.client = new mail.MailService();
25021
25024
  this.client.setApiKey(sendgridSettings.value.apiKey);
25022
25025
  }
@@ -25028,7 +25031,7 @@ let SendgridEmailProvider = class SendgridEmailProvider {
25028
25031
  if (!body) {
25029
25032
  throw new Error(`Missing body template for language ${input.languageId}`);
25030
25033
  }
25031
- const subject = getLocalizedText(templateData.bodyTemplate, input.languageId);
25034
+ const subject = getLocalizedText(templateData.subjectTemplate, input.languageId);
25032
25035
  if (!subject) {
25033
25036
  throw new Error(`Missing subject template for language ${input.languageId}`);
25034
25037
  }
@@ -25043,34 +25046,44 @@ let SendgridEmailProvider = class SendgridEmailProvider {
25043
25046
  });
25044
25047
  return;
25045
25048
  }
25046
- await this.client.send({
25049
+ const request = backendCore.removeUndefinedProps({
25047
25050
  from: input.from ?? templateData.from ?? sendgridSettings.value.defaultSender,
25048
- cc: [
25051
+ cc: sanitizeArray([
25049
25052
  ...(input.cc ?? templateData.cc ?? []),
25050
25053
  ...(sendgridSettings.value.defaultCc ?? []),
25051
- ],
25052
- bcc: [
25054
+ ]),
25055
+ bcc: sanitizeArray([
25053
25056
  ...(input.bcc ?? templateData.bcc ?? []),
25054
25057
  ...(sendgridSettings.value.defaultBcc ?? []),
25055
- ],
25058
+ ]),
25056
25059
  subject: input.subjectTemplate
25057
25060
  ? renderHandlebarsTemplate({
25058
25061
  template: input.subjectTemplate,
25059
25062
  context: processedPayload,
25060
25063
  })
25061
25064
  : undefined,
25062
- replyTo: templateData.replyTo ?? sendgridSettings.value.defaultReplyTo,
25065
+ replyTo: sanitizeValue(templateData.replyTo ?? sendgridSettings.value.defaultReplyTo),
25063
25066
  dynamicTemplateData: {
25064
25067
  ...processedPayload,
25065
25068
  },
25066
25069
  templateId: templateData.sendgridTemplateId,
25067
25070
  });
25071
+ if (sendgridSettings.value.loggingEnabled) {
25072
+ this.logger.info("Sending templated email", request);
25073
+ }
25074
+ await this.client.send(request);
25075
+ if (sendgridSettings.value.loggingEnabled) {
25076
+ this.logger.info("Templated email sent", request);
25077
+ }
25068
25078
  }
25069
25079
  async sendHtmlEmail(input) {
25070
- await this.client.send({
25080
+ const request = backendCore.removeUndefinedProps({
25071
25081
  from: input.from ?? sendgridSettings.value.defaultSender,
25072
- cc: input.cc,
25073
- bcc: [...(input.bcc ?? []), ...(sendgridSettings.value.defaultBcc ?? [])],
25082
+ cc: sanitizeArray(input.cc),
25083
+ bcc: sanitizeArray([
25084
+ ...(input.bcc ?? []),
25085
+ ...(sendgridSettings.value.defaultBcc ?? []),
25086
+ ]),
25074
25087
  subject: renderHandlebarsTemplate({
25075
25088
  template: input.subjectTemplate,
25076
25089
  context: input.payload,
@@ -25079,8 +25092,15 @@ let SendgridEmailProvider = class SendgridEmailProvider {
25079
25092
  template: input.bodyTemplate,
25080
25093
  context: input.payload,
25081
25094
  }),
25082
- replyTo: input.replyTo ?? sendgridSettings.value.defaultReplyTo,
25095
+ replyTo: sanitizeValue(input.replyTo ?? sendgridSettings.value.defaultReplyTo),
25083
25096
  });
25097
+ if (sendgridSettings.value.loggingEnabled) {
25098
+ this.logger.info("Sending html email", request);
25099
+ }
25100
+ await this.client.send(request);
25101
+ if (sendgridSettings.value.loggingEnabled) {
25102
+ this.logger.info("Html email sent", request);
25103
+ }
25084
25104
  }
25085
25105
  };
25086
25106
  SendgridEmailProvider = __decorate([