@bymax-one/nest-notification 1.2.1 → 1.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.
@@ -76,6 +76,13 @@ interface EmailSendOptions {
76
76
  * inside it, e.g. an OTP code) into the transport error.
77
77
  */
78
78
  redactValues?: readonly string[];
79
+ /**
80
+ * Whether this send's failures may surface the text the provider authored.
81
+ * `false` means the adapter must publish none of it — not in a log line, not
82
+ * in the message of the error it throws — because the body carries a
83
+ * credential and redaction cannot be relied on to remove it.
84
+ */
85
+ publishProviderText?: boolean;
79
86
  }
80
87
  /** Result of a successful send. `messageId` is provider-specific; useful for audit correlation. */
81
88
  interface EmailSendResult {
@@ -152,6 +159,19 @@ type NotificationLogVerb = 'sent' | 'generated' | 'verified' | 'failed' | 'coold
152
159
  interface NotificationLogEntry {
153
160
  /** Event time as a Unix timestamp in milliseconds. */
154
161
  timestamp: number;
162
+ /**
163
+ * Basic SMTP reply code of a failed delivery, when the provider's answer
164
+ * carried exactly one. Recorded for sends that withhold the provider's text:
165
+ * the code is independent of the message body, so it diagnoses the failure
166
+ * without disclosing anything the body held.
167
+ */
168
+ deliveryStatus?: number;
169
+ /**
170
+ * RFC 3463 enhanced status code (`5.7.1`, `5.2.2`, …) of a failed delivery,
171
+ * when the provider's answer carried exactly one. Distinguishes failures a
172
+ * basic `550` cannot — a content rejection from a blocked sender.
173
+ */
174
+ deliveryEnhancedStatus?: string;
155
175
  /** Tenant the event belongs to. */
156
176
  tenantId: string;
157
177
  /** Channel the event occurred on. */
@@ -763,8 +783,27 @@ interface EmailSendInput {
763
783
  /**
764
784
  * Secret values (e.g. an OTP code the body carries) redacted from the audit
765
785
  * entry's `errorMessage` when a provider failure echoes them back.
786
+ *
787
+ * Precision where text is published on purpose — NOT a barrier. Matching is
788
+ * literal, so the same bytes in another transfer encoding are missed; set
789
+ * {@link EmailSendInput.publishProviderText} to `false` when the body must
790
+ * not surface at all.
766
791
  */
767
792
  auditRedactValues?: readonly string[];
793
+ /**
794
+ * Whether a delivery failure may surface the text the PROVIDER authored —
795
+ * its message, its stack, and the `cause` chain built from them. Defaults to
796
+ * `true`, which keeps full diagnosability for ordinary mail.
797
+ *
798
+ * Set it to `false` for a message whose body carries a credential. A relay
799
+ * that quotes the rejected content puts the body into its error, and a
800
+ * declared value cannot be relied on to remove it: redaction predicts shapes,
801
+ * and a body quoted in base64 matches nothing. With this `false` the failure
802
+ * carries no provider-authored byte — no `cause`, and no message in the audit
803
+ * entry — only the SMTP reply codes a fixed grammar can express, which are
804
+ * the same whatever the body held.
805
+ */
806
+ publishProviderText?: boolean;
768
807
  }
769
808
  /** Input for {@link EmailService.sendTemplate} — the renderer produces the body. */
770
809
  interface EmailSendTemplateInput {
@@ -783,6 +822,13 @@ interface EmailSendTemplateInput {
783
822
  * entry's `errorMessage` when a provider failure echoes them back.
784
823
  */
785
824
  auditRedactValues?: readonly string[];
825
+ /**
826
+ * Whether a delivery failure may surface provider-authored text. Forwarded
827
+ * verbatim to {@link EmailService.send} — see
828
+ * {@link EmailSendInput.publishProviderText}, which documents why a declared
829
+ * value cannot substitute for it.
830
+ */
831
+ publishProviderText?: boolean;
786
832
  }
787
833
  /** Transactional email service. */
788
834
  declare class EmailService {
@@ -814,6 +860,25 @@ declare class EmailService {
814
860
  send(input: EmailSendInput): Promise<{
815
861
  messageId: string;
816
862
  }>;
863
+ /**
864
+ * Hands the message to the provider, converting any failure it raises.
865
+ *
866
+ * Only the provider call sits in this `try`. The success-path audit is the
867
+ * caller's business, so an `AUDIT_LOG_FAILED` cannot be mistaken for a
868
+ * delivery failure — and, more importantly, a `NotificationException` the
869
+ * PROVIDER throws no longer escapes unconverted. A custom adapter may raise
870
+ * one carrying its own message, details and cause, and an early rethrow would
871
+ * have handed that provider-authored text straight to the caller even with
872
+ * `publishProviderText: false`.
873
+ *
874
+ * @param sendOptions - The envelope handed to the provider.
875
+ * @param input - The original input, for redaction values and the audit entry.
876
+ * @param recipient - The already-masked recipient.
877
+ * @returns The provider's result.
878
+ * @throws NotificationException `EMAIL_SEND_FAILED`, carrying only what the
879
+ * caller allows to be published.
880
+ */
881
+ private deliver;
817
882
  /**
818
883
  * Renders a template (with an `en` fallback) and sends the result.
819
884
  *
@@ -841,6 +906,21 @@ declare class EmailService {
841
906
  private audit;
842
907
  /** Masks the recipient(s) per `audit.maskRecipient`, joining an array with `', '`. */
843
908
  private maskRecipients;
909
+ /**
910
+ * Fails a send whose caller forbade publishing provider-authored text.
911
+ *
912
+ * Nothing the provider wrote is carried: no `cause`, and no provider message
913
+ * in the audit entry. Redaction could not honour the promise — it removes the
914
+ * shapes it predicts, and an echo in another transfer encoding defeats every
915
+ * declared value — so the failure publishes only the reply codes a fixed
916
+ * grammar can express, which are independent of whatever the body held.
917
+ *
918
+ * @param error - The provider failure, read but never surfaced.
919
+ * @param input - The send input, for the tenant and user recorded in the audit.
920
+ * @param recipient - The already-masked recipient.
921
+ * @throws NotificationException Always — `EMAIL_SEND_FAILED` carrying the codes only.
922
+ */
923
+ private failWithoutProviderText;
844
924
  /**
845
925
  * Assembles every value to scrub from a provider failure: the caller's
846
926
  * declared secrets plus any excerpt of the rendered body the error is
@@ -76,6 +76,13 @@ interface EmailSendOptions {
76
76
  * inside it, e.g. an OTP code) into the transport error.
77
77
  */
78
78
  redactValues?: readonly string[];
79
+ /**
80
+ * Whether this send's failures may surface the text the provider authored.
81
+ * `false` means the adapter must publish none of it — not in a log line, not
82
+ * in the message of the error it throws — because the body carries a
83
+ * credential and redaction cannot be relied on to remove it.
84
+ */
85
+ publishProviderText?: boolean;
79
86
  }
80
87
  /** Result of a successful send. `messageId` is provider-specific; useful for audit correlation. */
81
88
  interface EmailSendResult {
@@ -152,6 +159,19 @@ type NotificationLogVerb = 'sent' | 'generated' | 'verified' | 'failed' | 'coold
152
159
  interface NotificationLogEntry {
153
160
  /** Event time as a Unix timestamp in milliseconds. */
154
161
  timestamp: number;
162
+ /**
163
+ * Basic SMTP reply code of a failed delivery, when the provider's answer
164
+ * carried exactly one. Recorded for sends that withhold the provider's text:
165
+ * the code is independent of the message body, so it diagnoses the failure
166
+ * without disclosing anything the body held.
167
+ */
168
+ deliveryStatus?: number;
169
+ /**
170
+ * RFC 3463 enhanced status code (`5.7.1`, `5.2.2`, …) of a failed delivery,
171
+ * when the provider's answer carried exactly one. Distinguishes failures a
172
+ * basic `550` cannot — a content rejection from a blocked sender.
173
+ */
174
+ deliveryEnhancedStatus?: string;
155
175
  /** Tenant the event belongs to. */
156
176
  tenantId: string;
157
177
  /** Channel the event occurred on. */
@@ -763,8 +783,27 @@ interface EmailSendInput {
763
783
  /**
764
784
  * Secret values (e.g. an OTP code the body carries) redacted from the audit
765
785
  * entry's `errorMessage` when a provider failure echoes them back.
786
+ *
787
+ * Precision where text is published on purpose — NOT a barrier. Matching is
788
+ * literal, so the same bytes in another transfer encoding are missed; set
789
+ * {@link EmailSendInput.publishProviderText} to `false` when the body must
790
+ * not surface at all.
766
791
  */
767
792
  auditRedactValues?: readonly string[];
793
+ /**
794
+ * Whether a delivery failure may surface the text the PROVIDER authored —
795
+ * its message, its stack, and the `cause` chain built from them. Defaults to
796
+ * `true`, which keeps full diagnosability for ordinary mail.
797
+ *
798
+ * Set it to `false` for a message whose body carries a credential. A relay
799
+ * that quotes the rejected content puts the body into its error, and a
800
+ * declared value cannot be relied on to remove it: redaction predicts shapes,
801
+ * and a body quoted in base64 matches nothing. With this `false` the failure
802
+ * carries no provider-authored byte — no `cause`, and no message in the audit
803
+ * entry — only the SMTP reply codes a fixed grammar can express, which are
804
+ * the same whatever the body held.
805
+ */
806
+ publishProviderText?: boolean;
768
807
  }
769
808
  /** Input for {@link EmailService.sendTemplate} — the renderer produces the body. */
770
809
  interface EmailSendTemplateInput {
@@ -783,6 +822,13 @@ interface EmailSendTemplateInput {
783
822
  * entry's `errorMessage` when a provider failure echoes them back.
784
823
  */
785
824
  auditRedactValues?: readonly string[];
825
+ /**
826
+ * Whether a delivery failure may surface provider-authored text. Forwarded
827
+ * verbatim to {@link EmailService.send} — see
828
+ * {@link EmailSendInput.publishProviderText}, which documents why a declared
829
+ * value cannot substitute for it.
830
+ */
831
+ publishProviderText?: boolean;
786
832
  }
787
833
  /** Transactional email service. */
788
834
  declare class EmailService {
@@ -814,6 +860,25 @@ declare class EmailService {
814
860
  send(input: EmailSendInput): Promise<{
815
861
  messageId: string;
816
862
  }>;
863
+ /**
864
+ * Hands the message to the provider, converting any failure it raises.
865
+ *
866
+ * Only the provider call sits in this `try`. The success-path audit is the
867
+ * caller's business, so an `AUDIT_LOG_FAILED` cannot be mistaken for a
868
+ * delivery failure — and, more importantly, a `NotificationException` the
869
+ * PROVIDER throws no longer escapes unconverted. A custom adapter may raise
870
+ * one carrying its own message, details and cause, and an early rethrow would
871
+ * have handed that provider-authored text straight to the caller even with
872
+ * `publishProviderText: false`.
873
+ *
874
+ * @param sendOptions - The envelope handed to the provider.
875
+ * @param input - The original input, for redaction values and the audit entry.
876
+ * @param recipient - The already-masked recipient.
877
+ * @returns The provider's result.
878
+ * @throws NotificationException `EMAIL_SEND_FAILED`, carrying only what the
879
+ * caller allows to be published.
880
+ */
881
+ private deliver;
817
882
  /**
818
883
  * Renders a template (with an `en` fallback) and sends the result.
819
884
  *
@@ -841,6 +906,21 @@ declare class EmailService {
841
906
  private audit;
842
907
  /** Masks the recipient(s) per `audit.maskRecipient`, joining an array with `', '`. */
843
908
  private maskRecipients;
909
+ /**
910
+ * Fails a send whose caller forbade publishing provider-authored text.
911
+ *
912
+ * Nothing the provider wrote is carried: no `cause`, and no provider message
913
+ * in the audit entry. Redaction could not honour the promise — it removes the
914
+ * shapes it predicts, and an echo in another transfer encoding defeats every
915
+ * declared value — so the failure publishes only the reply codes a fixed
916
+ * grammar can express, which are independent of whatever the body held.
917
+ *
918
+ * @param error - The provider failure, read but never surfaced.
919
+ * @param input - The send input, for the tenant and user recorded in the audit.
920
+ * @param recipient - The already-masked recipient.
921
+ * @throws NotificationException Always — `EMAIL_SEND_FAILED` carrying the codes only.
922
+ */
923
+ private failWithoutProviderText;
844
924
  /**
845
925
  * Assembles every value to scrub from a provider failure: the caller's
846
926
  * declared secrets plus any excerpt of the rendered body the error is
@@ -540,6 +540,45 @@ NoOpNotificationLogRepository = __decorateClass([
540
540
  Injectable()
541
541
  ], NoOpNotificationLogRepository);
542
542
 
543
+ // src/server/utils/delivery-status.ts
544
+ var MAX_SUBFIELD_DIGITS = 3;
545
+ var BASIC_STATUS = /(?<![\d.])([245]\d\d)(?![\d.])/g;
546
+ var ENHANCED_STATUS = new RegExp(
547
+ `(?<![\\d.])([245])\\.(\\d{1,${MAX_SUBFIELD_DIGITS}})\\.(\\d{1,${MAX_SUBFIELD_DIGITS}})(?![\\d.])`,
548
+ "g"
549
+ );
550
+ function soleMatch(text, pattern) {
551
+ const found = new Set(text.match(pattern) ?? []);
552
+ const [only] = found;
553
+ return found.size === 1 ? only : void 0;
554
+ }
555
+ function isBasicStatus(value) {
556
+ return Number.isInteger(value) && /^[245]\d\d$/.test(String(value));
557
+ }
558
+ function isEnhancedStatus(value) {
559
+ return new RegExp(`^[245]\\.\\d{1,${MAX_SUBFIELD_DIGITS}}\\.\\d{1,${MAX_SUBFIELD_DIGITS}}$`).test(
560
+ value
561
+ );
562
+ }
563
+ function extractDeliveryStatus(text) {
564
+ const basic = soleMatch(text, BASIC_STATUS);
565
+ const enhanced = soleMatch(text, ENHANCED_STATUS);
566
+ return {
567
+ ...basic !== void 0 ? { status: Number(basic) } : {},
568
+ ...enhanced !== void 0 ? { enhanced } : {}
569
+ };
570
+ }
571
+ function withoutDeclaredValues(status, declared) {
572
+ if (!declared) {
573
+ return status;
574
+ }
575
+ const collides = (value) => declared.some((secret) => secret !== "" && value.includes(secret));
576
+ return {
577
+ ...status.status !== void 0 && !collides(String(status.status)) ? { status: status.status } : {},
578
+ ...status.enhanced !== void 0 && !collides(status.enhanced) ? { enhanced: status.enhanced } : {}
579
+ };
580
+ }
581
+
543
582
  // src/server/utils/redact.ts
544
583
  var REDACTED_VALUE = "[redacted]";
545
584
  function redactValues(text, values) {
@@ -581,6 +620,12 @@ function readRedactedMessage(error, values) {
581
620
  }
582
621
  }
583
622
  function collectErrorChainText(error) {
623
+ return walkChain(error, true);
624
+ }
625
+ function collectErrorChainMessages(error) {
626
+ return walkChain(error, false);
627
+ }
628
+ function walkChain(error, includeStack) {
584
629
  const parts = [];
585
630
  const seen = /* @__PURE__ */ new Set();
586
631
  let current = error;
@@ -591,7 +636,7 @@ function collectErrorChainText(error) {
591
636
  break;
592
637
  }
593
638
  try {
594
- if (typeof current.stack === "string") {
639
+ if (includeStack && typeof current.stack === "string") {
595
640
  parts.push(current.stack);
596
641
  }
597
642
  } catch {
@@ -786,6 +831,25 @@ function buildRedactedCopy(name, message, stack) {
786
831
 
787
832
  // src/server/services/email.service.ts
788
833
  var FALLBACK_LOCALE = "en";
834
+ var WITHHELD_PROVIDER_TEXT = "[provider text withheld]";
835
+ function readAttachedStatus(error) {
836
+ try {
837
+ const carrier = error;
838
+ const rawStatus = carrier.deliveryStatus;
839
+ const rawEnhanced = carrier.deliveryEnhancedStatus;
840
+ const status = typeof rawStatus === "number" && isBasicStatus(rawStatus) ? rawStatus : void 0;
841
+ const enhanced = typeof rawEnhanced === "string" && isEnhancedStatus(rawEnhanced) ? rawEnhanced : void 0;
842
+ if (status === void 0 && enhanced === void 0) {
843
+ return void 0;
844
+ }
845
+ return {
846
+ ...status !== void 0 ? { status } : {},
847
+ ...enhanced !== void 0 ? { enhanced } : {}
848
+ };
849
+ } catch {
850
+ return void 0;
851
+ }
852
+ }
789
853
  var EmailService = class {
790
854
  /**
791
855
  * @param options - The resolved, frozen module options.
@@ -820,17 +884,38 @@ var EmailService = class {
820
884
  this.guardAttachmentSize(input.attachments, email.maxAttachmentBytes);
821
885
  const sendOptions = this.buildSendOptions(input, email);
822
886
  const recipient = this.maskRecipients(input.to);
887
+ const result = await this.deliver(sendOptions, input, recipient);
888
+ await this.audit(
889
+ this.auditEntry("sent", input.tenantId, recipient, input.userId, {
890
+ messageId: result.messageId
891
+ })
892
+ );
893
+ return { messageId: result.messageId };
894
+ }
895
+ /**
896
+ * Hands the message to the provider, converting any failure it raises.
897
+ *
898
+ * Only the provider call sits in this `try`. The success-path audit is the
899
+ * caller's business, so an `AUDIT_LOG_FAILED` cannot be mistaken for a
900
+ * delivery failure — and, more importantly, a `NotificationException` the
901
+ * PROVIDER throws no longer escapes unconverted. A custom adapter may raise
902
+ * one carrying its own message, details and cause, and an early rethrow would
903
+ * have handed that provider-authored text straight to the caller even with
904
+ * `publishProviderText: false`.
905
+ *
906
+ * @param sendOptions - The envelope handed to the provider.
907
+ * @param input - The original input, for redaction values and the audit entry.
908
+ * @param recipient - The already-masked recipient.
909
+ * @returns The provider's result.
910
+ * @throws NotificationException `EMAIL_SEND_FAILED`, carrying only what the
911
+ * caller allows to be published.
912
+ */
913
+ async deliver(sendOptions, input, recipient) {
823
914
  try {
824
- const result = await this.provider.send(sendOptions);
825
- await this.audit(
826
- this.auditEntry("sent", input.tenantId, recipient, input.userId, {
827
- messageId: result.messageId
828
- })
829
- );
830
- return { messageId: result.messageId };
915
+ return await this.provider.send(sendOptions);
831
916
  } catch (error) {
832
- if (error instanceof NotificationException) {
833
- throw error;
917
+ if (input.publishProviderText === false) {
918
+ await this.failWithoutProviderText(error, input, recipient);
834
919
  }
835
920
  const secretValues = this.gatherRedactionValues(error, input.auditRedactValues, sendOptions);
836
921
  await this.audit(
@@ -874,7 +959,8 @@ var EmailService = class {
874
959
  ...input.fromName !== void 0 ? { fromName: input.fromName } : {},
875
960
  ...input.replyTo !== void 0 ? { replyTo: input.replyTo } : {},
876
961
  ...input.userId !== void 0 ? { userId: input.userId } : {},
877
- ...input.auditRedactValues !== void 0 ? { auditRedactValues: input.auditRedactValues } : {}
962
+ ...input.auditRedactValues !== void 0 ? { auditRedactValues: input.auditRedactValues } : {},
963
+ ...input.publishProviderText !== void 0 ? { publishProviderText: input.publishProviderText } : {}
878
964
  });
879
965
  }
880
966
  /** Returns the resolved email options or throws when the channel is not configured. */
@@ -919,7 +1005,8 @@ var EmailService = class {
919
1005
  ...input.cc !== void 0 ? { cc: input.cc } : {},
920
1006
  ...input.bcc !== void 0 ? { bcc: input.bcc } : {},
921
1007
  ...input.attachments !== void 0 ? { attachments: input.attachments } : {},
922
- ...input.auditRedactValues !== void 0 ? { redactValues: input.auditRedactValues } : {}
1008
+ ...input.auditRedactValues !== void 0 ? { redactValues: input.auditRedactValues } : {},
1009
+ ...input.publishProviderText !== void 0 ? { publishProviderText: input.publishProviderText } : {}
923
1010
  };
924
1011
  }
925
1012
  /** Picks the locale that has a template, falling back to `en`, else throws `TEMPLATE_NOT_FOUND`. */
@@ -957,6 +1044,8 @@ var EmailService = class {
957
1044
  providerName: this.provider.name,
958
1045
  ...extra.messageId !== void 0 ? { messageId: extra.messageId } : {},
959
1046
  ...extra.errorMessage !== void 0 ? { errorMessage: extra.errorMessage } : {},
1047
+ ...extra.status !== void 0 ? { deliveryStatus: extra.status } : {},
1048
+ ...extra.enhanced !== void 0 ? { deliveryEnhancedStatus: extra.enhanced } : {},
960
1049
  ...userId !== void 0 ? { userId } : {}
961
1050
  };
962
1051
  }
@@ -975,6 +1064,36 @@ var EmailService = class {
975
1064
  const mask = this.options.audit.maskRecipient;
976
1065
  return Array.isArray(to) ? to.map((recipient) => mask(recipient)).join(", ") : mask(to);
977
1066
  }
1067
+ /**
1068
+ * Fails a send whose caller forbade publishing provider-authored text.
1069
+ *
1070
+ * Nothing the provider wrote is carried: no `cause`, and no provider message
1071
+ * in the audit entry. Redaction could not honour the promise — it removes the
1072
+ * shapes it predicts, and an echo in another transfer encoding defeats every
1073
+ * declared value — so the failure publishes only the reply codes a fixed
1074
+ * grammar can express, which are independent of whatever the body held.
1075
+ *
1076
+ * @param error - The provider failure, read but never surfaced.
1077
+ * @param input - The send input, for the tenant and user recorded in the audit.
1078
+ * @param recipient - The already-masked recipient.
1079
+ * @throws NotificationException Always — `EMAIL_SEND_FAILED` carrying the codes only.
1080
+ */
1081
+ async failWithoutProviderText(error, input, recipient) {
1082
+ const status = withoutDeclaredValues(
1083
+ readAttachedStatus(error) ?? extractDeliveryStatus(collectErrorChainMessages(error)),
1084
+ input.auditRedactValues
1085
+ );
1086
+ await this.audit(
1087
+ this.auditEntry("failed", input.tenantId, recipient, input.userId, {
1088
+ errorMessage: WITHHELD_PROVIDER_TEXT,
1089
+ ...status
1090
+ })
1091
+ );
1092
+ throw new NotificationException("EMAIL_SEND_FAILED", {
1093
+ providerName: this.provider.name,
1094
+ ...status
1095
+ });
1096
+ }
978
1097
  /**
979
1098
  * Assembles every value to scrub from a provider failure: the caller's
980
1099
  * declared secrets plus any excerpt of the rendered body the error is
@@ -1276,8 +1395,11 @@ var OtpService = class {
1276
1395
  template: input.emailTemplate ?? DEFAULT_OTP_TEMPLATE,
1277
1396
  data: { ...input.emailData, code, expiresInMinutes, purpose: input.purpose },
1278
1397
  // The provider receives the code inside the rendered body and may echo it
1279
- // in an error; EmailService must redact it from ITS OWN failed-audit entry.
1398
+ // in an error. Declaring it covers the shapes redaction can predict; the
1399
+ // flag below covers the ones it cannot — an OTP body is a credential by
1400
+ // definition, so this path never publishes what the provider wrote.
1280
1401
  auditRedactValues: [code],
1402
+ publishProviderText: false,
1281
1403
  ...input.locale !== void 0 ? { locale: input.locale } : {},
1282
1404
  ...input.userId !== void 0 ? { userId: input.userId } : {}
1283
1405
  };
@@ -1935,6 +2057,13 @@ async function loadOptionalPeer(moduleName) {
1935
2057
  }
1936
2058
 
1937
2059
  // src/server/providers/resend-email.provider.ts
2060
+ function readSdkMessage(error) {
2061
+ try {
2062
+ return String(error.message);
2063
+ } catch {
2064
+ return REDACTED_VALUE;
2065
+ }
2066
+ }
1938
2067
  var RESEND_MODULE = "resend";
1939
2068
  var _clientPromise, _options;
1940
2069
  var ResendEmailProvider = class {
@@ -2000,10 +2129,10 @@ var ResendEmailProvider = class {
2000
2129
  attachments: options.attachments
2001
2130
  });
2002
2131
  } catch (error) {
2003
- throw this.sendFailure(error instanceof Error ? error.message : String(error), options);
2132
+ throw this.sendFailure(readRedactedMessage(error), options);
2004
2133
  }
2005
2134
  if (result.error) {
2006
- throw this.sendFailure(result.error.message, options);
2135
+ throw this.sendFailure(readSdkMessage(result.error), options);
2007
2136
  }
2008
2137
  if (!result.data?.id) {
2009
2138
  throw new Error("Resend returned no message ID");
@@ -2020,6 +2149,10 @@ var ResendEmailProvider = class {
2020
2149
  * @returns The `Error` for the caller to throw.
2021
2150
  */
2022
2151
  sendFailure(rawMessage, options) {
2152
+ if (options.publishProviderText === false) {
2153
+ this.logger.warn("[RESEND_SEND_FAILED] (provider text withheld)");
2154
+ return new Error("Resend send failed");
2155
+ }
2023
2156
  const reason = this.scrubSendError(rawMessage, options);
2024
2157
  this.logger.warn(`[RESEND_SEND_FAILED] ${reason}`);
2025
2158
  return new Error(`Resend send failed: ${reason}`);
@@ -2201,7 +2334,8 @@ var SmtpEmailProvider = class {
2201
2334
  headers: options.headers,
2202
2335
  attachments: this.mapAttachments(options.attachments)
2203
2336
  },
2204
- options.redactValues
2337
+ options.redactValues,
2338
+ options.publishProviderText
2205
2339
  );
2206
2340
  if (!info.messageId) {
2207
2341
  throw new Error("SMTP transport returned no message ID");
@@ -2218,15 +2352,24 @@ var SmtpEmailProvider = class {
2218
2352
  * @returns The transport's send info.
2219
2353
  * @throws Error When the transport rejects the message.
2220
2354
  */
2221
- async dispatch(transport, payload, redactValues2) {
2355
+ async dispatch(transport, payload, redactValuesList, publishProviderText) {
2222
2356
  try {
2223
2357
  return await transport.sendMail(payload);
2224
2358
  } catch (error) {
2225
- const reason = this.scrubTransportError(
2226
- error instanceof Error ? error.message : String(error),
2227
- payload,
2228
- redactValues2
2229
- );
2359
+ const raw = readRedactedMessage(error);
2360
+ if (publishProviderText === false) {
2361
+ const { status, enhanced } = withoutDeclaredValues(
2362
+ extractDeliveryStatus(raw),
2363
+ redactValuesList
2364
+ );
2365
+ const codes = [status, enhanced].filter((code) => code !== void 0).join(" ");
2366
+ this.logger.warn(`[SMTP_SEND_FAILED] ${codes || "no reply code"}`);
2367
+ throw Object.assign(new Error("SMTP send failed"), {
2368
+ ...status !== void 0 ? { deliveryStatus: status } : {},
2369
+ ...enhanced !== void 0 ? { deliveryEnhancedStatus: enhanced } : {}
2370
+ });
2371
+ }
2372
+ const reason = this.scrubTransportError(raw, payload, redactValuesList);
2230
2373
  this.logger.warn(`[SMTP_SEND_FAILED] ${reason}`);
2231
2374
  throw new Error(`SMTP send failed: ${reason}`);
2232
2375
  }