@bymax-one/nest-notification 1.4.5 → 1.4.7

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/CHANGELOG.md CHANGED
@@ -7,6 +7,44 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.4.7] - 2026-11-07
11
+
12
+ ### Added
13
+
14
+ - **A swallowed audit failure now leaves a warning.** With the default `audit.swallowErrors: true`
15
+ a failed audit write was dropped without a trace, so an audit outage, or a `tenantIdResolver`
16
+ that returned a blank id, emptied the audit trail, including the entries that record a recipient
17
+ reaching its attempt ceiling, while every send and verification kept succeeding. The OTP
18
+ service, the email service and the audit interceptor each log
19
+ `BYMAX_NOTIFICATION_AUDIT_WRITE_FAILED`, naming the channel and the failure's class or code only:
20
+ a `notification.` code, otherwise the error's name and code, each
21
+ only when it is a short token. The repository's error message is never printed, because it can
22
+ quote the entry it rejected, whose recipient and user id are personal data, in any form; the cause
23
+ is in the repository's own logs. A name or code your repository sets itself is printed when it is a short token, so do not put an identifier of the entry in one. No OTP code is ever written. At most one line is written per
24
+ channel per minute; the next line says how many failures it stands for. What the caller receives
25
+ is unchanged.
26
+
27
+ ### Documentation
28
+
29
+ - The README now states the ordering behind `AUDIT_LOG_FAILED` when `audit.swallowErrors` is
30
+ `false`: the audit write comes after the state change, so the error says only that the audit write
31
+ failed and replaces the result the call would have returned. It can follow a stored, delivered or
32
+ accepted code, or the recording of a refusal, so the outcome cannot be inferred from it. When the
33
+ email channel's own audit of a send fails, `generate()` also releases the stored code and the
34
+ resend cooldown.
35
+
36
+ ## [1.4.6] - 2026-11-01
37
+
38
+ ### Fixed
39
+
40
+ - **The missing-template startup warning names the locale once for an `en` host.** With `en` as the
41
+ default locale the line read "neither 'en' nor 'en'". It now reads "does not resolve for 'en'";
42
+ every other default locale keeps "resolves for neither '<locale>' nor 'en'".
43
+ - **The `remedy` on `TEMPLATE_NOT_FOUND` for `otp_code` is true on every path.** It told the reader
44
+ to pass `emailTemplate` to `generate()`, which a direct `sendTemplate('otp_code')` has no way to
45
+ do. It now says where the option applies: the OTP email can use another template through the
46
+ `emailTemplate` option of `generate()`.
47
+
10
48
  ## [1.4.5] - 2026-11-01
11
49
 
12
50
  ### Added
@@ -1003,7 +1041,9 @@ rejected at startup rather than failing on the first send.
1003
1041
 
1004
1042
  [1.0.4]: https://github.com/bymaxone/nest-notification/compare/v1.0.3...v1.0.4
1005
1043
  [1.0.3]: https://github.com/bymaxone/nest-notification/compare/v1.0.2...v1.0.3
1006
- [Unreleased]: https://github.com/bymaxone/nest-notification/compare/v1.4.5...HEAD
1044
+ [Unreleased]: https://github.com/bymaxone/nest-notification/compare/v1.4.7...HEAD
1045
+ [1.4.7]: https://github.com/bymaxone/nest-notification/compare/v1.4.6...v1.4.7
1046
+ [1.4.6]: https://github.com/bymaxone/nest-notification/compare/v1.4.5...v1.4.6
1007
1047
  [1.4.5]: https://github.com/bymaxone/nest-notification/compare/v1.4.4...v1.4.5
1008
1048
  [1.4.4]: https://github.com/bymaxone/nest-notification/compare/v1.4.3...v1.4.4
1009
1049
  [1.4.3]: https://github.com/bymaxone/nest-notification/compare/v1.4.2...v1.4.3
package/README.md CHANGED
@@ -514,30 +514,30 @@ if (error.code === NOTIFICATION_ERROR_CODES.OTP_MAX_ATTEMPTS_EXCEEDED) {
514
514
 
515
515
  Configure via `forRoot(options)` or `forRootAsync({ useFactory })`. **At least one channel must be configured**, and configuring a channel the library does not implement throws at startup rather than failing on the first send. The full reference is in [`docs/technical_specification.md` §4](./docs/technical_specification.md); the most-used options:
516
516
 
517
- | Section | Option | Default | Notes |
518
- | -------- | ----------------------- | ---------------- | ----------------------------------------------------------------------------------------------------------------------- |
519
- | `global` | `redisNamespace` | `'notification'` | Prefix for store keys. |
520
- | `global` | `defaultLocale` | `'en'` | Template locale fallback. |
521
- | `global` | `tenantIdResolver` | — | `(req) => tenantId`; the audit source of truth. |
522
- | `email` | `provider` | — (required) | Instance or class implementing `IEmailProvider`. |
523
- | `email` | `defaultFrom` | — (required) | Must look like an email address. |
524
- | `email` | `templateRenderer` | default renderer | Any `IEmailTemplateRenderer`. |
525
- | `email` | `maxAttachmentBytes` | `10485760` | 10 MiB attachment guard. |
526
- | `otp` | `storage` | — (required) | Instance or class implementing `IOtpStorage`. |
527
- | `otp` | `defaultLength` | `6` | 1–32. |
528
- | `otp` | `defaultCodeType` | `'numeric'` | `numeric` \| `alpha` \| `alphanumeric`. |
529
- | `otp` | `defaultTtlSeconds` | `600` | Code lifetime. |
530
- | `otp` | `defaultMaxAttempts` | `5` | Verify attempts before lock-out. |
531
- | `otp` | `codeSecret` | — | Secret (>= 32 bytes) the stored code is keyed under. |
532
- | `otp` | `consumeOnVerify` | `false` | `true` deletes the code when `verify()` succeeds; otherwise the entry is marked validated until `consume()` or its TTL. |
533
- | `email` | `defaultFromName` | — | Display name sent with `defaultFrom`. |
534
- | `email` | `defaultReplyTo` | — | `Reply-To` applied when a send does not set one. |
535
- | `email` | `defaultTags` | `[]` | Tags merged into every send, before the send's own tags. |
536
- | `otp` | `resendCooldownSeconds` | `60` | Anti-resend window (atomic `SET NX EX`). |
537
- | `otp` | `perPurpose` | `{}` | Per-purpose overrides of the above. |
538
- | `audit` | `repository` | — (required) | Any `INotificationLogRepository`. |
539
- | `audit` | `swallowErrors` | `true` | Keep audit failures out of the delivery path. |
540
- | `audit` | `maskRecipient` | identity | Minimize recipient PII before persisting. |
517
+ | Section | Option | Default | Notes |
518
+ | -------- | ----------------------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
519
+ | `global` | `redisNamespace` | `'notification'` | Prefix for store keys. |
520
+ | `global` | `defaultLocale` | `'en'` | Template locale fallback. |
521
+ | `global` | `tenantIdResolver` | — | `(req) => tenantId`; the audit source of truth. |
522
+ | `email` | `provider` | — (required) | Instance or class implementing `IEmailProvider`. |
523
+ | `email` | `defaultFrom` | — (required) | Must look like an email address. |
524
+ | `email` | `templateRenderer` | default renderer | Any `IEmailTemplateRenderer`. |
525
+ | `email` | `maxAttachmentBytes` | `10485760` | 10 MiB attachment guard. |
526
+ | `otp` | `storage` | — (required) | Instance or class implementing `IOtpStorage`. |
527
+ | `otp` | `defaultLength` | `6` | 1–32. |
528
+ | `otp` | `defaultCodeType` | `'numeric'` | `numeric` \| `alpha` \| `alphanumeric`. |
529
+ | `otp` | `defaultTtlSeconds` | `600` | Code lifetime. |
530
+ | `otp` | `defaultMaxAttempts` | `5` | Verify attempts before lock-out. |
531
+ | `otp` | `codeSecret` | — | Secret (>= 32 bytes) the stored code is keyed under. |
532
+ | `otp` | `consumeOnVerify` | `false` | `true` deletes the code when `verify()` succeeds; otherwise the entry is marked validated until `consume()` or its TTL. |
533
+ | `email` | `defaultFromName` | — | Display name sent with `defaultFrom`. |
534
+ | `email` | `defaultReplyTo` | — | `Reply-To` applied when a send does not set one. |
535
+ | `email` | `defaultTags` | `[]` | Tags merged into every send, before the send's own tags. |
536
+ | `otp` | `resendCooldownSeconds` | `60` | Anti-resend window (atomic `SET NX EX`). |
537
+ | `otp` | `perPurpose` | `{}` | Per-purpose overrides of the above. |
538
+ | `audit` | `repository` | — (required) | Any `INotificationLogRepository`. |
539
+ | `audit` | `swallowErrors` | `true` | Keep audit failures out of the delivery path. A swallowed failure logs `BYMAX_NOTIFICATION_AUDIT_WRITE_FAILED`, at most once a minute per channel. |
540
+ | `audit` | `maskRecipient` | identity | Minimize recipient PII before persisting. |
541
541
 
542
542
  ---
543
543
 
@@ -639,6 +639,10 @@ const tenantIdResolver = (req: NotificationRequest): string =>
639
639
 
640
640
  A tenant id that identifies nobody is never recorded. The interceptor refuses a value that is not a string, is empty, or is whitespace-only, on every path that produces the id: what `tenantIdResolver` returns, the payload's `tenantId` when no resolver is configured, and the payload's `tenantId` when a resolver is configured but there is no HTTP request to read it from (a non-HTTP context). Your caller never sees the refusal itself. With `audit.swallowErrors: true` (the default) it is swallowed and no audit entry is written; with `false` it surfaces as `AUDIT_LOG_FAILED`, whose `cause` is a sanitized copy of the refusal. One input is ignored, not refused: an argument whose payload `tenantId` is not a string is not recognised as a dispatch at all, so it produces no audit entry and no error.
641
641
 
642
+ A swallowed audit failure is not silent: each channel (`otp`, `email`, the interceptor) logs one warning, `BYMAX_NOTIFICATION_AUDIT_WRITE_FAILED`, naming the channel and the failure's class or code only: a `notification.` code (such as `notification.invalid_scope_identifier` for a refused tenant id), otherwise the error's name and code, each only when it is a short token such as `Error` or `ECONNREFUSED`. The repository's error message is never printed, since it can quote the entry it rejected, whose recipient and user id are personal data, in any form; the cause is in your repository's own logs. A name or code your repository sets itself is printed when it is a short token, so do not put an identifier of the entry in one. No OTP code is ever written. At most one line is written per channel per minute; the next line says how many failures it stands for. The operation's own result is unchanged.
643
+
644
+ With `audit.swallowErrors: false` the audit write comes after the state change, so `AUDIT_LOG_FAILED` says only that the audit write failed. It does not say what the operation did, and it replaces the result the call would have returned: `generate()` can raise it after the code was stored and delivered (its resend cooldown is then held, unless the email channel's own audit of the send is the one that failed, which releases the stored code and the cooldown), or while recording a blocked cooldown or a failed delivery; `verify()` can raise it after the code was accepted (consumed, or marked validated), or while recording a wrong code, a missing code or an exhausted attempt limit. Never read it as success or as failure of the operation; check the state through your own means.
645
+
642
646
  > [!NOTE]
643
647
  > The resolver governs what the audit interceptor trusts. Service methods still take an explicit `tenantId`: resolve the tenant in your controller and pass it down — there is no hidden override of a method argument.
644
648
 
@@ -626,6 +626,65 @@ var CANONICAL_EMAIL_TEMPLATES = {
626
626
  MFA_DISABLED: "mfa_disabled"
627
627
  };
628
628
 
629
+ // src/server/utils/audit-write-warning.ts
630
+ var AUDIT_WARNING_INTERVAL_MS = 6e4;
631
+ var WARNING_CODE = "BYMAX_NOTIFICATION_AUDIT_WRITE_FAILED";
632
+ var TOKEN = /^[A-Za-z0-9_.:-]{1,64}$/;
633
+ var LIBRARY_CODE_PREFIX = "notification.";
634
+ function tokenOf(value) {
635
+ return typeof value === "string" && TOKEN.test(value) ? value : void 0;
636
+ }
637
+ function reasonOf(error) {
638
+ try {
639
+ const source = error;
640
+ const code = tokenOf(source?.code);
641
+ if (code?.startsWith(LIBRARY_CODE_PREFIX)) {
642
+ return code;
643
+ }
644
+ const name = tokenOf(source?.name) ?? "Error";
645
+ return code === void 0 ? name : `${name} ${code}`;
646
+ } catch {
647
+ return "Error";
648
+ }
649
+ }
650
+ var AuditWriteWarning = class {
651
+ /**
652
+ * @param logger - Where the line goes.
653
+ * @param channel - The place that swallows the failure.
654
+ */
655
+ constructor(logger, channel) {
656
+ this.logger = logger;
657
+ this.channel = channel;
658
+ this.suppressed = 0;
659
+ }
660
+ /**
661
+ * Whether `elapsed` milliseconds since the last line is still inside the interval.
662
+ *
663
+ * @internal
664
+ */
665
+ within(elapsed) {
666
+ return elapsed >= 0 && elapsed < AUDIT_WARNING_INTERVAL_MS;
667
+ }
668
+ /**
669
+ * Logs the warning, or counts the failure when one was logged less than an interval ago.
670
+ *
671
+ * @param error - What the audit repository threw; any value, named without throwing.
672
+ */
673
+ warn(error) {
674
+ const now = Date.now();
675
+ if (this.lastLoggedAt !== void 0 && this.within(now - this.lastLoggedAt)) {
676
+ this.suppressed += 1;
677
+ return;
678
+ }
679
+ const similar = this.suppressed > 0 ? `; ${this.suppressed} similar since the last line` : "";
680
+ this.lastLoggedAt = now;
681
+ this.suppressed = 0;
682
+ this.logger.warn(
683
+ `[${WARNING_CODE}] An audit entry could not be written by the ${this.channel} channel (${reasonOf(error)}${similar}); the operation's result is unaffected because audit.swallowErrors is true.`
684
+ );
685
+ }
686
+ };
687
+
629
688
  // src/server/utils/delivery-status.ts
630
689
  var MAX_SUBFIELD_DIGITS = 3;
631
690
  var BASIC_STATUS = /(?<![\d.])([245]\d\d)(?![\d.])/g;
@@ -934,7 +993,7 @@ function assertIdentifies(owner, label, value) {
934
993
 
935
994
  // src/server/services/email.service.ts
936
995
  var FALLBACK_LOCALE = "en";
937
- var OTP_TEMPLATE_REMEDY = "register an 'otp_code' template (for example 'otp_code::en') in your template renderer, such as DefaultTemplateRenderer, or pass emailTemplate to generate()";
996
+ var OTP_TEMPLATE_REMEDY = "register an 'otp_code' template (for example 'otp_code::en') in your template renderer, such as DefaultTemplateRenderer; the OTP email can use another template through the emailTemplate option of generate()";
938
997
  var WITHHELD_PROVIDER_TEXT = "[provider text withheld]";
939
998
  function readAttachedStatus(error) {
940
999
  try {
@@ -966,6 +1025,8 @@ exports.EmailService = class EmailService {
966
1025
  this.provider = provider;
967
1026
  this.renderer = renderer;
968
1027
  this.auditLog = auditLog;
1028
+ /** @internal */
1029
+ this.auditWarning = new AuditWriteWarning(new common.Logger(exports.EmailService.name), "email");
969
1030
  }
970
1031
  /**
971
1032
  * Whether the email channel is configured and its provider is ready.
@@ -1192,6 +1253,7 @@ exports.EmailService = class EmailService {
1192
1253
  if (!this.options.audit.swallowErrors) {
1193
1254
  throw new NotificationException("AUDIT_LOG_FAILED", void 0, { cause: error });
1194
1255
  }
1256
+ this.auditWarning.warn(error);
1195
1257
  }
1196
1258
  }
1197
1259
  /** Masks the recipient(s) per `audit.maskRecipient`, joining an array with `', '`. */
@@ -1358,6 +1420,8 @@ exports.OtpService = class OtpService {
1358
1420
  this.warnedFailuresNotCarried = false;
1359
1421
  /** @internal */
1360
1422
  this.warnedTemplate = false;
1423
+ /** @internal */
1424
+ this.auditWarning = new AuditWriteWarning(this.logger, "otp");
1361
1425
  }
1362
1426
  /**
1363
1427
  * Whether the OTP channel is configured and its storage is ready.
@@ -1607,8 +1671,9 @@ exports.OtpService = class OtpService {
1607
1671
  if (!this.emailService.isConfigured() || await this.emailService.resolvesTemplate(DEFAULT_OTP_TEMPLATE, locale)) {
1608
1672
  return;
1609
1673
  }
1674
+ const resolution = locale === "en" ? "does not resolve for 'en'" : `resolves for neither '${locale}' nor 'en'`;
1610
1675
  this.logger.warn(
1611
- `[${TEMPLATE_WARNING_CODE}] The email template '${DEFAULT_OTP_TEMPLATE}' resolves for neither '${locale}' nor 'en', so the first generate() that delivers by email fails with TEMPLATE_NOT_FOUND. Register '${DEFAULT_OTP_TEMPLATE}' in your template renderer (DefaultTemplateRenderer takes it under 'otp_code::en'). Ignore this line if every generate() call passes emailTemplate, if you deliver manually, or if your renderer loads its templates after startup.`
1676
+ `[${TEMPLATE_WARNING_CODE}] The email template '${DEFAULT_OTP_TEMPLATE}' ${resolution}, so the first generate() that delivers by email fails with TEMPLATE_NOT_FOUND. Register '${DEFAULT_OTP_TEMPLATE}' in your template renderer (DefaultTemplateRenderer takes it under 'otp_code::en'). Ignore this line if every generate() call passes emailTemplate, if you deliver manually, or if your renderer loads its templates after startup.`
1612
1677
  );
1613
1678
  } catch (error) {
1614
1679
  this.logger.warn(
@@ -1763,6 +1828,7 @@ exports.OtpService = class OtpService {
1763
1828
  if (!this.options.audit.swallowErrors) {
1764
1829
  throw new NotificationException("AUDIT_LOG_FAILED", void 0, { cause: error });
1765
1830
  }
1831
+ this.auditWarning.warn(error);
1766
1832
  }
1767
1833
  }
1768
1834
  };
@@ -2212,6 +2278,11 @@ exports.NotificationAuditInterceptor = class NotificationAuditInterceptor {
2212
2278
  constructor(options, auditLog) {
2213
2279
  this.options = options;
2214
2280
  this.auditLog = auditLog;
2281
+ /** @internal */
2282
+ this.auditWarning = new AuditWriteWarning(
2283
+ new common.Logger(exports.NotificationAuditInterceptor.name),
2284
+ "interceptor"
2285
+ );
2215
2286
  }
2216
2287
  /**
2217
2288
  * Taps the handler stream: records `'sent'` after a successful dispatch and
@@ -2249,6 +2320,7 @@ exports.NotificationAuditInterceptor = class NotificationAuditInterceptor {
2249
2320
  if (!this.options.audit.swallowErrors) {
2250
2321
  throw new NotificationException("AUDIT_LOG_FAILED", void 0, { cause: error });
2251
2322
  }
2323
+ this.auditWarning.warn(error);
2252
2324
  }
2253
2325
  }
2254
2326
  /** Returns the first handler argument shaped like a {@link DispatchInput}, else `null`. */
@@ -624,6 +624,65 @@ var CANONICAL_EMAIL_TEMPLATES = {
624
624
  MFA_DISABLED: "mfa_disabled"
625
625
  };
626
626
 
627
+ // src/server/utils/audit-write-warning.ts
628
+ var AUDIT_WARNING_INTERVAL_MS = 6e4;
629
+ var WARNING_CODE = "BYMAX_NOTIFICATION_AUDIT_WRITE_FAILED";
630
+ var TOKEN = /^[A-Za-z0-9_.:-]{1,64}$/;
631
+ var LIBRARY_CODE_PREFIX = "notification.";
632
+ function tokenOf(value) {
633
+ return typeof value === "string" && TOKEN.test(value) ? value : void 0;
634
+ }
635
+ function reasonOf(error) {
636
+ try {
637
+ const source = error;
638
+ const code = tokenOf(source?.code);
639
+ if (code?.startsWith(LIBRARY_CODE_PREFIX)) {
640
+ return code;
641
+ }
642
+ const name = tokenOf(source?.name) ?? "Error";
643
+ return code === void 0 ? name : `${name} ${code}`;
644
+ } catch {
645
+ return "Error";
646
+ }
647
+ }
648
+ var AuditWriteWarning = class {
649
+ /**
650
+ * @param logger - Where the line goes.
651
+ * @param channel - The place that swallows the failure.
652
+ */
653
+ constructor(logger, channel) {
654
+ this.logger = logger;
655
+ this.channel = channel;
656
+ this.suppressed = 0;
657
+ }
658
+ /**
659
+ * Whether `elapsed` milliseconds since the last line is still inside the interval.
660
+ *
661
+ * @internal
662
+ */
663
+ within(elapsed) {
664
+ return elapsed >= 0 && elapsed < AUDIT_WARNING_INTERVAL_MS;
665
+ }
666
+ /**
667
+ * Logs the warning, or counts the failure when one was logged less than an interval ago.
668
+ *
669
+ * @param error - What the audit repository threw; any value, named without throwing.
670
+ */
671
+ warn(error) {
672
+ const now = Date.now();
673
+ if (this.lastLoggedAt !== void 0 && this.within(now - this.lastLoggedAt)) {
674
+ this.suppressed += 1;
675
+ return;
676
+ }
677
+ const similar = this.suppressed > 0 ? `; ${this.suppressed} similar since the last line` : "";
678
+ this.lastLoggedAt = now;
679
+ this.suppressed = 0;
680
+ this.logger.warn(
681
+ `[${WARNING_CODE}] An audit entry could not be written by the ${this.channel} channel (${reasonOf(error)}${similar}); the operation's result is unaffected because audit.swallowErrors is true.`
682
+ );
683
+ }
684
+ };
685
+
627
686
  // src/server/utils/delivery-status.ts
628
687
  var MAX_SUBFIELD_DIGITS = 3;
629
688
  var BASIC_STATUS = /(?<![\d.])([245]\d\d)(?![\d.])/g;
@@ -932,7 +991,7 @@ function assertIdentifies(owner, label, value) {
932
991
 
933
992
  // src/server/services/email.service.ts
934
993
  var FALLBACK_LOCALE = "en";
935
- var OTP_TEMPLATE_REMEDY = "register an 'otp_code' template (for example 'otp_code::en') in your template renderer, such as DefaultTemplateRenderer, or pass emailTemplate to generate()";
994
+ var OTP_TEMPLATE_REMEDY = "register an 'otp_code' template (for example 'otp_code::en') in your template renderer, such as DefaultTemplateRenderer; the OTP email can use another template through the emailTemplate option of generate()";
936
995
  var WITHHELD_PROVIDER_TEXT = "[provider text withheld]";
937
996
  function readAttachedStatus(error) {
938
997
  try {
@@ -964,6 +1023,8 @@ var EmailService = class {
964
1023
  this.provider = provider;
965
1024
  this.renderer = renderer;
966
1025
  this.auditLog = auditLog;
1026
+ /** @internal */
1027
+ this.auditWarning = new AuditWriteWarning(new Logger(EmailService.name), "email");
967
1028
  }
968
1029
  /**
969
1030
  * Whether the email channel is configured and its provider is ready.
@@ -1190,6 +1251,7 @@ var EmailService = class {
1190
1251
  if (!this.options.audit.swallowErrors) {
1191
1252
  throw new NotificationException("AUDIT_LOG_FAILED", void 0, { cause: error });
1192
1253
  }
1254
+ this.auditWarning.warn(error);
1193
1255
  }
1194
1256
  }
1195
1257
  /** Masks the recipient(s) per `audit.maskRecipient`, joining an array with `', '`. */
@@ -1356,6 +1418,8 @@ var OtpService = class {
1356
1418
  this.warnedFailuresNotCarried = false;
1357
1419
  /** @internal */
1358
1420
  this.warnedTemplate = false;
1421
+ /** @internal */
1422
+ this.auditWarning = new AuditWriteWarning(this.logger, "otp");
1359
1423
  }
1360
1424
  /**
1361
1425
  * Whether the OTP channel is configured and its storage is ready.
@@ -1605,8 +1669,9 @@ var OtpService = class {
1605
1669
  if (!this.emailService.isConfigured() || await this.emailService.resolvesTemplate(DEFAULT_OTP_TEMPLATE, locale)) {
1606
1670
  return;
1607
1671
  }
1672
+ const resolution = locale === "en" ? "does not resolve for 'en'" : `resolves for neither '${locale}' nor 'en'`;
1608
1673
  this.logger.warn(
1609
- `[${TEMPLATE_WARNING_CODE}] The email template '${DEFAULT_OTP_TEMPLATE}' resolves for neither '${locale}' nor 'en', so the first generate() that delivers by email fails with TEMPLATE_NOT_FOUND. Register '${DEFAULT_OTP_TEMPLATE}' in your template renderer (DefaultTemplateRenderer takes it under 'otp_code::en'). Ignore this line if every generate() call passes emailTemplate, if you deliver manually, or if your renderer loads its templates after startup.`
1674
+ `[${TEMPLATE_WARNING_CODE}] The email template '${DEFAULT_OTP_TEMPLATE}' ${resolution}, so the first generate() that delivers by email fails with TEMPLATE_NOT_FOUND. Register '${DEFAULT_OTP_TEMPLATE}' in your template renderer (DefaultTemplateRenderer takes it under 'otp_code::en'). Ignore this line if every generate() call passes emailTemplate, if you deliver manually, or if your renderer loads its templates after startup.`
1610
1675
  );
1611
1676
  } catch (error) {
1612
1677
  this.logger.warn(
@@ -1761,6 +1826,7 @@ var OtpService = class {
1761
1826
  if (!this.options.audit.swallowErrors) {
1762
1827
  throw new NotificationException("AUDIT_LOG_FAILED", void 0, { cause: error });
1763
1828
  }
1829
+ this.auditWarning.warn(error);
1764
1830
  }
1765
1831
  }
1766
1832
  };
@@ -2210,6 +2276,11 @@ var NotificationAuditInterceptor = class {
2210
2276
  constructor(options, auditLog) {
2211
2277
  this.options = options;
2212
2278
  this.auditLog = auditLog;
2279
+ /** @internal */
2280
+ this.auditWarning = new AuditWriteWarning(
2281
+ new Logger(NotificationAuditInterceptor.name),
2282
+ "interceptor"
2283
+ );
2213
2284
  }
2214
2285
  /**
2215
2286
  * Taps the handler stream: records `'sent'` after a successful dispatch and
@@ -2247,6 +2318,7 @@ var NotificationAuditInterceptor = class {
2247
2318
  if (!this.options.audit.swallowErrors) {
2248
2319
  throw new NotificationException("AUDIT_LOG_FAILED", void 0, { cause: error });
2249
2320
  }
2321
+ this.auditWarning.warn(error);
2250
2322
  }
2251
2323
  }
2252
2324
  /** Returns the first handler argument shaped like a {@link DispatchInput}, else `null`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-notification",
3
- "version": "1.4.5",
3
+ "version": "1.4.7",
4
4
  "description": "Multi-channel notification library for NestJS — email, OTP, SMS, push — with pluggable providers and storage, multi-tenant by design, zero runtime dependencies.",
5
5
  "author": "Bymax One <support@bymax.one>",
6
6
  "license": "MIT",
@@ -81,6 +81,7 @@
81
81
  },
82
82
  "scripts": {
83
83
  "build": "pnpm clean && tsup",
84
+ "check:api": "node scripts/check-api-surface.mjs",
84
85
  "check:exports": "attw --pack .",
85
86
  "check:mutants": "node scripts/check-mutation-directives.mjs",
86
87
  "check:no-prisma": "grep -rq '@prisma/client' src; s=$?; [ $s -eq 1 ] && exit 0; [ $s -eq 0 ] && { echo check:no-prisma: found @prisma/client import in src/; exit 1; }; echo check:no-prisma: grep failed with exit $s; exit $s",