@bymax-one/nest-notification 1.0.1 → 1.0.4

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,72 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.0.4] - 2026-08-06
11
+
12
+ **Published-artifact change, not a behavioural one.** `dist/` differs from `1.0.3` — this
13
+ bundler preserves comments and the source gained mutation-suppression notes — but no runtime
14
+ path changed. Measured by building both revisions and diffing the output.
15
+
16
+ ### Documentation
17
+
18
+ - The mutation badge said **98%**; the measured score is **100.00%**.
19
+
20
+ ### Tests
21
+
22
+ - OTP expiry is `now + ttlSeconds * 1000` and only its order of magnitude was checked. Dividing
23
+ instead of multiplying would expire a 300-second code 0.3 milliseconds after minting it, and
24
+ every failure would read as a delivery problem rather than an arithmetic one.
25
+ - A dotted template path stops at the first non-object. Without that guard `{{ name.0 }}` renders
26
+ the first letter of the string, and the same slip against `{{ token.0 }}` would put the first
27
+ character of a secret in an email.
28
+
29
+ ## [1.0.3] - 2026-08-05
30
+
31
+ ### Fixed
32
+
33
+ - **`NotificationService` never received its channel services, and said the channels were
34
+ disabled.** Both constructor parameters carried `@Optional()` and no `@Inject`. Nest
35
+ reads three separate metadata keys here — `self:paramtypes` from `@Inject()`,
36
+ `design:paramtypes` from TypeScript, and `optional:paramtypes` from `@Optional()` — and
37
+ the third only says a dependency may be missing; it carries no token. The published
38
+ bundle is built by tsup/esbuild, which documents that it cannot emit `design:paramtypes`,
39
+ so neither key that names a dependency was present and both parameters resolved to
40
+ `undefined`.
41
+
42
+ With both channels configured, the module logged `Initialized with channels: email, otp`
43
+ while `getEnabledChannels()` returned `[]` and `dispatch()` threw `CHANNEL_DISABLED` —
44
+ an error that blamed a configuration that was correct. Both parameters now carry
45
+ `@Inject`, keeping `@Optional()`, which is the shape `@nestjs/jwt` uses for the same
46
+ situation.
47
+
48
+ ### Changed
49
+
50
+ - `emitDecoratorMetadata` is `false` in `tsconfig.json`. It was `true`, which was never
51
+ true of the artifact — tsup printed this on every build of this package:
52
+
53
+ ```
54
+ You have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin
55
+ ```
56
+
57
+ The source now compiles the way the bundle is built, so a parameter that depends on
58
+ reflected types fails where it is cheap to see rather than in a consumer's process.
59
+
60
+ ## [1.0.2] - 2026-08-04
61
+
62
+ ### Security
63
+
64
+ - The Resend API key and the Redis client are no longer disclosed when the provider or
65
+ the OTP storage that holds them is serialized. `ResendEmailProvider` kept its adapter
66
+ options — which carry `apiKey` — and `RedisOtpStorage` kept its client in TypeScript
67
+ `private` properties, which are erased at runtime and leave enumerable own properties.
68
+ `JSON.stringify`, object spread and `util.inspect` therefore emitted the API key in
69
+ plaintext, and reached `options.password` on the ioredis instance. Both move to
70
+ ECMAScript private fields. That matters because these are registered providers: a
71
+ structured logger rendering its arguments, or an error reporter capturing the scope of
72
+ a throw, walks them without being asked to.
73
+
74
+ Reading on purpose is unchanged and no public type or export moved.
75
+
10
76
  ## [1.0.1] - 2026-08-01
11
77
 
12
78
  ### Security
@@ -99,6 +165,9 @@ rejected at startup rather than failing on the first send.
99
165
  - **`forRootAsync` `useClass` / `useExisting`** — only `useFactory` is wired.
100
166
  - **Multi-provider failover and routing.**
101
167
 
102
- [Unreleased]: https://github.com/bymaxone/nest-notification/compare/v1.0.1...HEAD
168
+ [1.0.4]: https://github.com/bymaxone/nest-notification/compare/v1.0.3...v1.0.4
169
+ [1.0.3]: https://github.com/bymaxone/nest-notification/compare/v1.0.2...v1.0.3
170
+ [Unreleased]: https://github.com/bymaxone/nest-notification/compare/v1.0.3...HEAD
171
+ [1.0.2]: https://github.com/bymaxone/nest-notification/compare/v1.0.1...v1.0.2
103
172
  [1.0.1]: https://github.com/bymaxone/nest-notification/compare/v1.0.0...v1.0.1
104
173
  [1.0.0]: https://github.com/bymaxone/nest-notification/releases/tag/v1.0.0
package/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
  <a href="https://www.npmjs.com/package/@bymax-one/nest-notification"><img src="https://img.shields.io/npm/dm/@bymax-one/nest-notification?style=flat-square&colorA=000000&colorB=000000" alt="npm downloads" /></a>
15
15
  <a href="https://github.com/bymaxone/nest-notification/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/bymaxone/nest-notification/ci.yml?branch=main&style=flat-square&colorA=000000&label=CI" alt="CI status" /></a>
16
16
  <a href="https://github.com/bymaxone/nest-notification/actions/workflows/ci.yml"><img src="https://img.shields.io/badge/coverage-100%25-brightgreen?style=flat-square&colorA=000000" alt="coverage" /></a>
17
- <a href="https://github.com/bymaxone/nest-notification/blob/main/docs/mutation_testing_results.md"><img src="https://img.shields.io/badge/mutation-98%25-brightgreen?style=flat-square&colorA=000000" alt="mutation score" /></a>
17
+ <a href="https://github.com/bymaxone/nest-notification/blob/main/docs/mutation_testing_results.md"><img src="https://img.shields.io/badge/mutation-100.00%25-brightgreen?style=flat-square&colorA=000000" alt="mutation score" /></a>
18
18
  <a href="https://scorecard.dev/viewer/?uri=github.com/bymaxone/nest-notification"><img src="https://api.scorecard.dev/projects/github.com/bymaxone/nest-notification/badge?style=flat-square" alt="OpenSSF Scorecard" /></a>
19
19
  <a href="https://github.com/bymaxone/nest-notification/blob/main/LICENSE"><img src="https://img.shields.io/github/license/bymaxone/nest-notification?style=flat-square&colorA=000000&colorB=000000" alt="license" /></a>
20
20
  <a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-strict-3178C6?style=flat-square&logo=typescript&logoColor=white" alt="TypeScript" /></a>
@@ -603,6 +603,7 @@ When integrating `@bymax-one/nest-notification` in production, verify each of th
603
603
  | Code Lifetime | TTL-bound in the store; expiry and absence are reported identically so neither leaks the other |
604
604
  | Code Exposure | Never logged, never audited, never in an error message or stack trace — asserted by a regression test |
605
605
  | Recipient PII | Absent from keys; optionally masked before it reaches the audit sink |
606
+ | Provider Secrets | The Resend API key and the Redis client live in private fields; serializing a provider omits them |
606
607
  | Tenant Isolation | `tenantId` scopes every operation and is resolved from a trusted source, not the payload |
607
608
  | Template Injection | HTML body escaped on interpolation by the bundled renderer — closes stored XSS through a display name |
608
609
  | Attachment DoS | Total attachment size rejected against a budget before the provider is called |
@@ -5,6 +5,9 @@ var crypto = require('crypto');
5
5
  var rxjs = require('rxjs');
6
6
 
7
7
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __typeError = (msg) => {
9
+ throw TypeError(msg);
10
+ };
8
11
  var __decorateClass = (decorators, target, key, kind) => {
9
12
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
10
13
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
@@ -13,6 +16,10 @@ var __decorateClass = (decorators, target, key, kind) => {
13
16
  return result;
14
17
  };
15
18
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
19
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
20
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
21
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
22
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
16
23
 
17
24
  // src/server/bymax-notification.constants.ts
18
25
  var BYMAX_NOTIFICATION_OPTIONS = /* @__PURE__ */ Symbol("BYMAX_NOTIFICATION_OPTIONS");
@@ -597,7 +604,10 @@ exports.EmailService = class EmailService {
597
604
  return;
598
605
  }
599
606
  const totalBytes = attachments.reduce(
600
- (sum, { content }) => sum + (typeof content === "string" ? Buffer.byteLength(content) : content.length),
607
+ (sum, { content }) => (
608
+ // Stryker disable next-line ConditionalExpression: equivalent — `Buffer.byteLength` answers a Buffer's own length, so both arms measure the same bytes; the conditional says where the number comes from
609
+ sum + (typeof content === "string" ? Buffer.byteLength(content) : content.length)
610
+ ),
601
611
  0
602
612
  );
603
613
  if (totalBytes > maxBytes) {
@@ -682,152 +692,6 @@ exports.EmailService = __decorateClass([
682
692
  __decorateParam(2, common.Inject(BYMAX_NOTIFICATION_TEMPLATE_RENDERER)),
683
693
  __decorateParam(3, common.Inject(BYMAX_NOTIFICATION_LOG_REPOSITORY))
684
694
  ], exports.EmailService);
685
- exports.NotificationService = class NotificationService {
686
- /**
687
- * @param emailService - The email service, present only when the email channel is configured.
688
- * @param otpService - The OTP service, present only when the OTP channel is configured.
689
- */
690
- constructor(emailService, otpService) {
691
- this.emailService = emailService;
692
- this.otpService = otpService;
693
- }
694
- /**
695
- * Dispatches a notification to the channel named in `input`.
696
- *
697
- * @param input - The channel-discriminated dispatch request.
698
- * @returns The channel-discriminated result.
699
- * @throws NotificationException `CHANNEL_DISABLED` (channel not configured) or
700
- * `EMAIL_MISSING_BODY` (email payload has neither a template nor subject+html).
701
- */
702
- async dispatch(input) {
703
- if (input.channel === "email") {
704
- return {
705
- channel: "email",
706
- messageId: await this.dispatchEmail(input.tenantId, input.payload)
707
- };
708
- }
709
- return { channel: "otp", result: await this.dispatchOtp(input.tenantId, input.payload) };
710
- }
711
- /**
712
- * Lists the channels whose service is present and reports itself configured.
713
- *
714
- * @returns The enabled channels.
715
- */
716
- getEnabledChannels() {
717
- const channels = [];
718
- if (this.emailService?.isConfigured()) {
719
- channels.push("email");
720
- }
721
- if (this.otpService?.isConfigured()) {
722
- channels.push("otp");
723
- }
724
- return channels;
725
- }
726
- /**
727
- * Returns the email service or throws when the email channel is not enabled.
728
- *
729
- * @returns The email service.
730
- * @throws NotificationException `CHANNEL_DISABLED` when email is not configured.
731
- */
732
- getEmail() {
733
- if (!this.emailService) {
734
- throw new NotificationException("CHANNEL_DISABLED", { channel: "email" });
735
- }
736
- return this.emailService;
737
- }
738
- /**
739
- * Returns the OTP service or throws when the OTP channel is not enabled.
740
- *
741
- * @returns The OTP service.
742
- * @throws NotificationException `CHANNEL_DISABLED` when OTP is not configured.
743
- */
744
- getOtp() {
745
- if (!this.otpService) {
746
- throw new NotificationException("CHANNEL_DISABLED", { channel: "otp" });
747
- }
748
- return this.otpService;
749
- }
750
- /** Routes an email dispatch to `sendTemplate` (template) or `send` (raw body). */
751
- async dispatchEmail(tenantId, payload) {
752
- const email = this.getEmail();
753
- if (payload.template !== void 0) {
754
- const input = this.toTemplateInput(tenantId, payload.template, payload);
755
- return (await email.sendTemplate(input)).messageId;
756
- }
757
- if (payload.subject !== void 0 && payload.html !== void 0) {
758
- const input = this.toSendInput(tenantId, payload.subject, payload.html, payload);
759
- return (await email.send(input)).messageId;
760
- }
761
- throw new NotificationException("EMAIL_MISSING_BODY", {
762
- hint: "payload requires either `template` OR `{ subject, html }`"
763
- });
764
- }
765
- /** Routes an OTP dispatch by `action`, defaulting to `generate`. */
766
- async dispatchOtp(tenantId, payload) {
767
- const otp = this.getOtp();
768
- const action = payload.action ?? "generate";
769
- const ref = {
770
- tenantId,
771
- recipient: payload.recipient,
772
- purpose: payload.purpose,
773
- ...payload.userId !== void 0 ? { userId: payload.userId } : {}
774
- };
775
- if (action === "verify") {
776
- return otp.verify({ ...ref, code: payload.code ?? "" });
777
- }
778
- if (action === "consume") {
779
- return otp.consume(ref);
780
- }
781
- return otp.generate(this.toGenerateInput(ref, payload));
782
- }
783
- /** Builds the `sendTemplate` input from a resolved template name and payload. */
784
- toTemplateInput(tenantId, template, payload) {
785
- return {
786
- tenantId,
787
- to: payload.to,
788
- template,
789
- data: payload.data ?? {},
790
- ...payload.locale !== void 0 ? { locale: payload.locale } : {},
791
- ...this.commonEmailFields(payload)
792
- };
793
- }
794
- /** Builds the raw `send` input from a resolved subject/html and payload. */
795
- toSendInput(tenantId, subject, html, payload) {
796
- return {
797
- tenantId,
798
- to: payload.to,
799
- subject,
800
- html,
801
- ...payload.text !== void 0 ? { text: payload.text } : {},
802
- ...this.commonEmailFields(payload)
803
- };
804
- }
805
- /** The optional envelope fields shared by both email paths. */
806
- commonEmailFields(payload) {
807
- return {
808
- ...payload.from !== void 0 ? { from: payload.from } : {},
809
- ...payload.fromName !== void 0 ? { fromName: payload.fromName } : {},
810
- ...payload.replyTo !== void 0 ? { replyTo: payload.replyTo } : {},
811
- ...payload.tags !== void 0 ? { tags: payload.tags } : {},
812
- ...payload.userId !== void 0 ? { userId: payload.userId } : {}
813
- };
814
- }
815
- /** Builds the `generate` input from a reference and an OTP dispatch payload. */
816
- toGenerateInput(ref, payload) {
817
- return {
818
- ...ref,
819
- ...payload.deliverVia !== void 0 ? { deliverVia: payload.deliverVia } : {},
820
- ...payload.emailTemplate !== void 0 ? { emailTemplate: payload.emailTemplate } : {},
821
- ...payload.emailData !== void 0 ? { emailData: payload.emailData } : {},
822
- ...payload.locale !== void 0 ? { locale: payload.locale } : {}
823
- };
824
- }
825
- };
826
- exports.NotificationService = __decorateClass([
827
- common.Injectable(),
828
- __decorateParam(0, common.Optional()),
829
- __decorateParam(1, common.Optional())
830
- ], exports.NotificationService);
831
695
  var NUMERIC = "0123456789";
832
696
  var ALPHA = "ABCDEFGHJKLMNPQRSTUVWXYZ";
833
697
  var ALPHANUMERIC = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
@@ -1151,6 +1015,156 @@ exports.OtpService = __decorateClass([
1151
1015
  __decorateParam(3, common.Inject(exports.EmailService))
1152
1016
  ], exports.OtpService);
1153
1017
 
1018
+ // src/server/services/notification.service.ts
1019
+ exports.NotificationService = class NotificationService {
1020
+ /**
1021
+ * @param emailService - The email service, present only when the email channel is configured.
1022
+ * @param otpService - The OTP service, present only when the OTP channel is configured.
1023
+ */
1024
+ constructor(emailService, otpService) {
1025
+ this.emailService = emailService;
1026
+ this.otpService = otpService;
1027
+ }
1028
+ /**
1029
+ * Dispatches a notification to the channel named in `input`.
1030
+ *
1031
+ * @param input - The channel-discriminated dispatch request.
1032
+ * @returns The channel-discriminated result.
1033
+ * @throws NotificationException `CHANNEL_DISABLED` (channel not configured) or
1034
+ * `EMAIL_MISSING_BODY` (email payload has neither a template nor subject+html).
1035
+ */
1036
+ async dispatch(input) {
1037
+ if (input.channel === "email") {
1038
+ return {
1039
+ channel: "email",
1040
+ messageId: await this.dispatchEmail(input.tenantId, input.payload)
1041
+ };
1042
+ }
1043
+ return { channel: "otp", result: await this.dispatchOtp(input.tenantId, input.payload) };
1044
+ }
1045
+ /**
1046
+ * Lists the channels whose service is present and reports itself configured.
1047
+ *
1048
+ * @returns The enabled channels.
1049
+ */
1050
+ getEnabledChannels() {
1051
+ const channels = [];
1052
+ if (this.emailService?.isConfigured()) {
1053
+ channels.push("email");
1054
+ }
1055
+ if (this.otpService?.isConfigured()) {
1056
+ channels.push("otp");
1057
+ }
1058
+ return channels;
1059
+ }
1060
+ /**
1061
+ * Returns the email service or throws when the email channel is not enabled.
1062
+ *
1063
+ * @returns The email service.
1064
+ * @throws NotificationException `CHANNEL_DISABLED` when email is not configured.
1065
+ */
1066
+ getEmail() {
1067
+ if (!this.emailService) {
1068
+ throw new NotificationException("CHANNEL_DISABLED", { channel: "email" });
1069
+ }
1070
+ return this.emailService;
1071
+ }
1072
+ /**
1073
+ * Returns the OTP service or throws when the OTP channel is not enabled.
1074
+ *
1075
+ * @returns The OTP service.
1076
+ * @throws NotificationException `CHANNEL_DISABLED` when OTP is not configured.
1077
+ */
1078
+ getOtp() {
1079
+ if (!this.otpService) {
1080
+ throw new NotificationException("CHANNEL_DISABLED", { channel: "otp" });
1081
+ }
1082
+ return this.otpService;
1083
+ }
1084
+ /** Routes an email dispatch to `sendTemplate` (template) or `send` (raw body). */
1085
+ async dispatchEmail(tenantId, payload) {
1086
+ const email = this.getEmail();
1087
+ if (payload.template !== void 0) {
1088
+ const input = this.toTemplateInput(tenantId, payload.template, payload);
1089
+ return (await email.sendTemplate(input)).messageId;
1090
+ }
1091
+ if (payload.subject !== void 0 && payload.html !== void 0) {
1092
+ const input = this.toSendInput(tenantId, payload.subject, payload.html, payload);
1093
+ return (await email.send(input)).messageId;
1094
+ }
1095
+ throw new NotificationException("EMAIL_MISSING_BODY", {
1096
+ hint: "payload requires either `template` OR `{ subject, html }`"
1097
+ });
1098
+ }
1099
+ /** Routes an OTP dispatch by `action`, defaulting to `generate`. */
1100
+ async dispatchOtp(tenantId, payload) {
1101
+ const otp = this.getOtp();
1102
+ const action = payload.action ?? "generate";
1103
+ const ref = {
1104
+ tenantId,
1105
+ recipient: payload.recipient,
1106
+ purpose: payload.purpose,
1107
+ ...payload.userId !== void 0 ? { userId: payload.userId } : {}
1108
+ };
1109
+ if (action === "verify") {
1110
+ return otp.verify({ ...ref, code: payload.code ?? "" });
1111
+ }
1112
+ if (action === "consume") {
1113
+ return otp.consume(ref);
1114
+ }
1115
+ return otp.generate(this.toGenerateInput(ref, payload));
1116
+ }
1117
+ /** Builds the `sendTemplate` input from a resolved template name and payload. */
1118
+ toTemplateInput(tenantId, template, payload) {
1119
+ return {
1120
+ tenantId,
1121
+ to: payload.to,
1122
+ template,
1123
+ data: payload.data ?? {},
1124
+ ...payload.locale !== void 0 ? { locale: payload.locale } : {},
1125
+ ...this.commonEmailFields(payload)
1126
+ };
1127
+ }
1128
+ /** Builds the raw `send` input from a resolved subject/html and payload. */
1129
+ toSendInput(tenantId, subject, html, payload) {
1130
+ return {
1131
+ tenantId,
1132
+ to: payload.to,
1133
+ subject,
1134
+ html,
1135
+ ...payload.text !== void 0 ? { text: payload.text } : {},
1136
+ ...this.commonEmailFields(payload)
1137
+ };
1138
+ }
1139
+ /** The optional envelope fields shared by both email paths. */
1140
+ commonEmailFields(payload) {
1141
+ return {
1142
+ ...payload.from !== void 0 ? { from: payload.from } : {},
1143
+ ...payload.fromName !== void 0 ? { fromName: payload.fromName } : {},
1144
+ ...payload.replyTo !== void 0 ? { replyTo: payload.replyTo } : {},
1145
+ ...payload.tags !== void 0 ? { tags: payload.tags } : {},
1146
+ ...payload.userId !== void 0 ? { userId: payload.userId } : {}
1147
+ };
1148
+ }
1149
+ /** Builds the `generate` input from a reference and an OTP dispatch payload. */
1150
+ toGenerateInput(ref, payload) {
1151
+ return {
1152
+ ...ref,
1153
+ ...payload.deliverVia !== void 0 ? { deliverVia: payload.deliverVia } : {},
1154
+ ...payload.emailTemplate !== void 0 ? { emailTemplate: payload.emailTemplate } : {},
1155
+ ...payload.emailData !== void 0 ? { emailData: payload.emailData } : {},
1156
+ ...payload.locale !== void 0 ? { locale: payload.locale } : {}
1157
+ };
1158
+ }
1159
+ };
1160
+ exports.NotificationService = __decorateClass([
1161
+ common.Injectable(),
1162
+ __decorateParam(0, common.Optional()),
1163
+ __decorateParam(0, common.Inject(exports.EmailService)),
1164
+ __decorateParam(1, common.Optional()),
1165
+ __decorateParam(1, common.Inject(exports.OtpService))
1166
+ ], exports.NotificationService);
1167
+
1154
1168
  // src/server/bymax-notification.module.ts
1155
1169
  var RAW_NOTIFICATION_OPTIONS = /* @__PURE__ */ Symbol("RAW_NOTIFICATION_OPTIONS");
1156
1170
  exports.BymaxNotificationModule = class BymaxNotificationModule {
@@ -1563,12 +1577,9 @@ exports.NoOpEmailProvider = __decorateClass([
1563
1577
  common.Injectable()
1564
1578
  ], exports.NoOpEmailProvider);
1565
1579
  var RESEND_MODULE = "resend";
1580
+ var _clientPromise, _options;
1566
1581
  exports.ResendEmailProvider = class ResendEmailProvider {
1567
- /**
1568
- * @param options - Adapter options; `apiKey` is required to actually send.
1569
- */
1570
1582
  constructor(options = {}) {
1571
- this.options = options;
1572
1583
  this.name = "resend";
1573
1584
  this.logger = new common.Logger(exports.ResendEmailProvider.name);
1574
1585
  /**
@@ -1577,7 +1588,22 @@ exports.ResendEmailProvider = class ResendEmailProvider {
1577
1588
  * collapses concurrent first sends onto a single dynamic `import()` + instantiation;
1578
1589
  * a failed init resets this back to `null` so a transient error can be retried.
1579
1590
  */
1580
- this.clientPromise = null;
1591
+ __privateAdd(this, _clientPromise, null);
1592
+ /**
1593
+ * @param options - Adapter options; `apiKey` is required to actually send.
1594
+ */
1595
+ /**
1596
+ * The adapter options, which carry the Resend API key.
1597
+ *
1598
+ * An ECMAScript private field rather than a TypeScript `private` one: the
1599
+ * latter is erased at runtime, leaving an enumerable own property that
1600
+ * `JSON.stringify`, object spread and `util.inspect` all walk into. This
1601
+ * provider is registered in the container, so anything that renders it
1602
+ * incidentally — a structured logger formatting its arguments, an error
1603
+ * reporter capturing the scope of a throw — would emit the key in plaintext.
1604
+ */
1605
+ __privateAdd(this, _options);
1606
+ __privateSet(this, _options, options);
1581
1607
  }
1582
1608
  /**
1583
1609
  * Whether an API key was supplied. Does not load the SDK.
@@ -1585,7 +1611,7 @@ exports.ResendEmailProvider = class ResendEmailProvider {
1585
1611
  * @returns `true` when an `apiKey` is present.
1586
1612
  */
1587
1613
  isConfigured() {
1588
- return Boolean(this.options.apiKey);
1614
+ return Boolean(__privateGet(this, _options).apiKey);
1589
1615
  }
1590
1616
  /**
1591
1617
  * Sends one transactional email through Resend.
@@ -1647,8 +1673,8 @@ exports.ResendEmailProvider = class ResendEmailProvider {
1647
1673
  * @throws Error When `apiKey` is missing or the `resend` package is not installed.
1648
1674
  */
1649
1675
  getClient() {
1650
- this.clientPromise ??= this.createClient();
1651
- return this.clientPromise;
1676
+ __privateGet(this, _clientPromise) ?? __privateSet(this, _clientPromise, this.createClient());
1677
+ return __privateGet(this, _clientPromise);
1652
1678
  }
1653
1679
  /**
1654
1680
  * Builds a fresh SDK client, resetting the cached promise on any failure so the
@@ -1659,14 +1685,14 @@ exports.ResendEmailProvider = class ResendEmailProvider {
1659
1685
  */
1660
1686
  async createClient() {
1661
1687
  try {
1662
- const apiKey = this.options.apiKey;
1688
+ const apiKey = __privateGet(this, _options).apiKey;
1663
1689
  if (!apiKey) {
1664
1690
  throw new Error("ResendEmailProvider: missing API key \u2014 pass { apiKey } to the constructor");
1665
1691
  }
1666
1692
  const ResendCtor = await this.loadResendConstructor();
1667
1693
  return new ResendCtor(apiKey);
1668
1694
  } catch (error) {
1669
- this.clientPromise = null;
1695
+ __privateSet(this, _clientPromise, null);
1670
1696
  throw error;
1671
1697
  }
1672
1698
  }
@@ -1687,6 +1713,8 @@ exports.ResendEmailProvider = class ResendEmailProvider {
1687
1713
  }
1688
1714
  }
1689
1715
  };
1716
+ _clientPromise = new WeakMap();
1717
+ _options = new WeakMap();
1690
1718
  exports.ResendEmailProvider = __decorateClass([
1691
1719
  common.Injectable()
1692
1720
  ], exports.ResendEmailProvider);
@@ -1867,13 +1895,24 @@ function hashTenantRecipient(tenantId, recipient) {
1867
1895
 
1868
1896
  // src/server/providers/redis-otp.storage.ts
1869
1897
  var MS_PER_SECOND4 = 1e3;
1898
+ var _redis;
1870
1899
  exports.RedisOtpStorage = class RedisOtpStorage {
1871
1900
  /**
1872
1901
  * @param options - The Redis client and optional namespace.
1873
1902
  */
1874
1903
  constructor(options) {
1875
1904
  this.name = "redis";
1876
- this.redis = options.redisClient;
1905
+ /**
1906
+ * The Redis client.
1907
+ *
1908
+ * An ECMAScript private field rather than a TypeScript `private` one, which
1909
+ * is erased at runtime: an ioredis instance carries `options.password` as a
1910
+ * plain field, so leaving this enumerable would let anything that serializes
1911
+ * this storage — a structured logger, an error reporter walking the scope of
1912
+ * a throw — reach the Redis credentials.
1913
+ */
1914
+ __privateAdd(this, _redis);
1915
+ __privateSet(this, _redis, options.redisClient);
1877
1916
  this.namespace = options.namespace ?? "notification";
1878
1917
  }
1879
1918
  /** Whether a Redis client was supplied.
@@ -1881,7 +1920,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1881
1920
  * @returns `true` when a client is present.
1882
1921
  */
1883
1922
  isConfigured() {
1884
- return Boolean(this.redis);
1923
+ return Boolean(__privateGet(this, _redis));
1885
1924
  }
1886
1925
  /**
1887
1926
  * Creates or replaces an OTP entry with a TTL derived from `expiresAt`.
@@ -1893,7 +1932,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1893
1932
  */
1894
1933
  async set(tenantId, recipient, purpose, entry) {
1895
1934
  const ttlSeconds = Math.max(1, Math.ceil((entry.expiresAt - Date.now()) / MS_PER_SECOND4));
1896
- await this.redis.setex(
1935
+ await __privateGet(this, _redis).setex(
1897
1936
  this.otpKey(tenantId, recipient, purpose),
1898
1937
  ttlSeconds,
1899
1938
  JSON.stringify(entry)
@@ -1908,7 +1947,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1908
1947
  * @returns The parsed entry, or `null` when absent/corrupted.
1909
1948
  */
1910
1949
  async get(tenantId, recipient, purpose) {
1911
- const raw = await this.redis.get(this.otpKey(tenantId, recipient, purpose));
1950
+ const raw = await __privateGet(this, _redis).get(this.otpKey(tenantId, recipient, purpose));
1912
1951
  if (!raw) {
1913
1952
  return null;
1914
1953
  }
@@ -1928,7 +1967,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1928
1967
  * @returns `not_found`, `max_attempts`, or `ok` with the incremented entry.
1929
1968
  */
1930
1969
  async consumeAttempt(tenantId, recipient, purpose) {
1931
- const raw = await this.redis.eval(
1970
+ const raw = await __privateGet(this, _redis).eval(
1932
1971
  exports.RedisOtpStorage.CONSUME_ATTEMPT_LUA,
1933
1972
  1,
1934
1973
  this.otpKey(tenantId, recipient, purpose),
@@ -1946,7 +1985,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1946
1985
  * @param entry - The replacement entry.
1947
1986
  */
1948
1987
  async update(tenantId, recipient, purpose, entry) {
1949
- await this.redis.set(
1988
+ await __privateGet(this, _redis).set(
1950
1989
  this.otpKey(tenantId, recipient, purpose),
1951
1990
  JSON.stringify(entry),
1952
1991
  "KEEPTTL",
@@ -1961,7 +2000,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1961
2000
  * @param purpose - OTP purpose.
1962
2001
  */
1963
2002
  async delete(tenantId, recipient, purpose) {
1964
- await this.redis.del(this.otpKey(tenantId, recipient, purpose));
2003
+ await __privateGet(this, _redis).del(this.otpKey(tenantId, recipient, purpose));
1965
2004
  }
1966
2005
  /**
1967
2006
  * Atomic cooldown acquire with `SET … NX EX` — only the first concurrent caller wins.
@@ -1980,10 +2019,10 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1980
2019
  async tryAcquireCooldown(tenantId, recipient, purpose, ttlSeconds) {
1981
2020
  const key = this.cooldownKey(tenantId, recipient, purpose);
1982
2021
  if (ttlSeconds <= 0) {
1983
- await this.redis.del(key);
2022
+ await __privateGet(this, _redis).del(key);
1984
2023
  return true;
1985
2024
  }
1986
- const result = await this.redis.set(key, "1", "EX", ttlSeconds, "NX");
2025
+ const result = await __privateGet(this, _redis).set(key, "1", "EX", ttlSeconds, "NX");
1987
2026
  return result === "OK";
1988
2027
  }
1989
2028
  /**
@@ -1995,7 +2034,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1995
2034
  * @returns Remaining seconds, or `0` when there is no active cooldown.
1996
2035
  */
1997
2036
  async getCooldown(tenantId, recipient, purpose) {
1998
- const ttl = await this.redis.ttl(this.cooldownKey(tenantId, recipient, purpose));
2037
+ const ttl = await __privateGet(this, _redis).ttl(this.cooldownKey(tenantId, recipient, purpose));
1999
2038
  return ttl > 0 ? ttl : 0;
2000
2039
  }
2001
2040
  /**
@@ -2006,7 +2045,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
2006
2045
  * @param purpose - OTP purpose.
2007
2046
  */
2008
2047
  async clearCooldown(tenantId, recipient, purpose) {
2009
- await this.redis.del(this.cooldownKey(tenantId, recipient, purpose));
2048
+ await __privateGet(this, _redis).del(this.cooldownKey(tenantId, recipient, purpose));
2010
2049
  }
2011
2050
  /** Builds the OTP entry key: `{namespace}:otp:{purpose}:{sha256(tenantId:recipient)}`. */
2012
2051
  otpKey(tenantId, recipient, purpose) {
@@ -2017,6 +2056,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
2017
2056
  return `${this.namespace}:otp_cd:${purpose}:${hashTenantRecipient(tenantId, recipient)}`;
2018
2057
  }
2019
2058
  };
2059
+ _redis = new WeakMap();
2020
2060
  /**
2021
2061
  * Atomic verify primitive. The entire read → expiry/max check → increment → write
2022
2062
  * runs in this single script, so concurrent calls cannot overshoot `maxAttempts`.
@@ -1430,19 +1430,9 @@ interface ResendEmailProviderOptions {
1430
1430
  * ```
1431
1431
  */
1432
1432
  declare class ResendEmailProvider implements IEmailProvider {
1433
- private readonly options;
1433
+ #private;
1434
1434
  readonly name = "resend";
1435
1435
  private readonly logger;
1436
- /**
1437
- * Cached in-flight (or resolved) SDK client initialization. `null` until the first
1438
- * `send()` and after a failed init. Caching the PROMISE (not just the client)
1439
- * collapses concurrent first sends onto a single dynamic `import()` + instantiation;
1440
- * a failed init resets this back to `null` so a transient error can be retried.
1441
- */
1442
- private clientPromise;
1443
- /**
1444
- * @param options - Adapter options; `apiKey` is required to actually send.
1445
- */
1446
1436
  constructor(options?: ResendEmailProviderOptions);
1447
1437
  /**
1448
1438
  * Whether an API key was supplied. Does not load the SDK.
@@ -1655,8 +1645,8 @@ interface RedisOtpStorageOptions {
1655
1645
  }
1656
1646
  /** Redis-backed `IOtpStorage` with atomic Lua attempt counting and NX cooldown locking. */
1657
1647
  declare class RedisOtpStorage implements IOtpStorage {
1648
+ #private;
1658
1649
  readonly name = "redis";
1659
- private readonly redis;
1660
1650
  private readonly namespace;
1661
1651
  /**
1662
1652
  * @param options - The Redis client and optional namespace.
@@ -1430,19 +1430,9 @@ interface ResendEmailProviderOptions {
1430
1430
  * ```
1431
1431
  */
1432
1432
  declare class ResendEmailProvider implements IEmailProvider {
1433
- private readonly options;
1433
+ #private;
1434
1434
  readonly name = "resend";
1435
1435
  private readonly logger;
1436
- /**
1437
- * Cached in-flight (or resolved) SDK client initialization. `null` until the first
1438
- * `send()` and after a failed init. Caching the PROMISE (not just the client)
1439
- * collapses concurrent first sends onto a single dynamic `import()` + instantiation;
1440
- * a failed init resets this back to `null` so a transient error can be retried.
1441
- */
1442
- private clientPromise;
1443
- /**
1444
- * @param options - Adapter options; `apiKey` is required to actually send.
1445
- */
1446
1436
  constructor(options?: ResendEmailProviderOptions);
1447
1437
  /**
1448
1438
  * Whether an API key was supplied. Does not load the SDK.
@@ -1655,8 +1645,8 @@ interface RedisOtpStorageOptions {
1655
1645
  }
1656
1646
  /** Redis-backed `IOtpStorage` with atomic Lua attempt counting and NX cooldown locking. */
1657
1647
  declare class RedisOtpStorage implements IOtpStorage {
1648
+ #private;
1658
1649
  readonly name = "redis";
1659
- private readonly redis;
1660
1650
  private readonly namespace;
1661
1651
  /**
1662
1652
  * @param options - The Redis client and optional namespace.
@@ -3,6 +3,9 @@ import { randomInt, timingSafeEqual, randomUUID, createHash } from 'crypto';
3
3
  import { catchError, from, concatMap, throwError, map } from 'rxjs';
4
4
 
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
6
9
  var __decorateClass = (decorators, target, key, kind) => {
7
10
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
8
11
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
@@ -11,6 +14,10 @@ var __decorateClass = (decorators, target, key, kind) => {
11
14
  return result;
12
15
  };
13
16
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
17
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
18
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
19
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
20
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
14
21
 
15
22
  // src/server/bymax-notification.constants.ts
16
23
  var BYMAX_NOTIFICATION_OPTIONS = /* @__PURE__ */ Symbol("BYMAX_NOTIFICATION_OPTIONS");
@@ -595,7 +602,10 @@ var EmailService = class {
595
602
  return;
596
603
  }
597
604
  const totalBytes = attachments.reduce(
598
- (sum, { content }) => sum + (typeof content === "string" ? Buffer.byteLength(content) : content.length),
605
+ (sum, { content }) => (
606
+ // Stryker disable next-line ConditionalExpression: equivalent — `Buffer.byteLength` answers a Buffer's own length, so both arms measure the same bytes; the conditional says where the number comes from
607
+ sum + (typeof content === "string" ? Buffer.byteLength(content) : content.length)
608
+ ),
599
609
  0
600
610
  );
601
611
  if (totalBytes > maxBytes) {
@@ -680,152 +690,6 @@ EmailService = __decorateClass([
680
690
  __decorateParam(2, Inject(BYMAX_NOTIFICATION_TEMPLATE_RENDERER)),
681
691
  __decorateParam(3, Inject(BYMAX_NOTIFICATION_LOG_REPOSITORY))
682
692
  ], EmailService);
683
- var NotificationService = class {
684
- /**
685
- * @param emailService - The email service, present only when the email channel is configured.
686
- * @param otpService - The OTP service, present only when the OTP channel is configured.
687
- */
688
- constructor(emailService, otpService) {
689
- this.emailService = emailService;
690
- this.otpService = otpService;
691
- }
692
- /**
693
- * Dispatches a notification to the channel named in `input`.
694
- *
695
- * @param input - The channel-discriminated dispatch request.
696
- * @returns The channel-discriminated result.
697
- * @throws NotificationException `CHANNEL_DISABLED` (channel not configured) or
698
- * `EMAIL_MISSING_BODY` (email payload has neither a template nor subject+html).
699
- */
700
- async dispatch(input) {
701
- if (input.channel === "email") {
702
- return {
703
- channel: "email",
704
- messageId: await this.dispatchEmail(input.tenantId, input.payload)
705
- };
706
- }
707
- return { channel: "otp", result: await this.dispatchOtp(input.tenantId, input.payload) };
708
- }
709
- /**
710
- * Lists the channels whose service is present and reports itself configured.
711
- *
712
- * @returns The enabled channels.
713
- */
714
- getEnabledChannels() {
715
- const channels = [];
716
- if (this.emailService?.isConfigured()) {
717
- channels.push("email");
718
- }
719
- if (this.otpService?.isConfigured()) {
720
- channels.push("otp");
721
- }
722
- return channels;
723
- }
724
- /**
725
- * Returns the email service or throws when the email channel is not enabled.
726
- *
727
- * @returns The email service.
728
- * @throws NotificationException `CHANNEL_DISABLED` when email is not configured.
729
- */
730
- getEmail() {
731
- if (!this.emailService) {
732
- throw new NotificationException("CHANNEL_DISABLED", { channel: "email" });
733
- }
734
- return this.emailService;
735
- }
736
- /**
737
- * Returns the OTP service or throws when the OTP channel is not enabled.
738
- *
739
- * @returns The OTP service.
740
- * @throws NotificationException `CHANNEL_DISABLED` when OTP is not configured.
741
- */
742
- getOtp() {
743
- if (!this.otpService) {
744
- throw new NotificationException("CHANNEL_DISABLED", { channel: "otp" });
745
- }
746
- return this.otpService;
747
- }
748
- /** Routes an email dispatch to `sendTemplate` (template) or `send` (raw body). */
749
- async dispatchEmail(tenantId, payload) {
750
- const email = this.getEmail();
751
- if (payload.template !== void 0) {
752
- const input = this.toTemplateInput(tenantId, payload.template, payload);
753
- return (await email.sendTemplate(input)).messageId;
754
- }
755
- if (payload.subject !== void 0 && payload.html !== void 0) {
756
- const input = this.toSendInput(tenantId, payload.subject, payload.html, payload);
757
- return (await email.send(input)).messageId;
758
- }
759
- throw new NotificationException("EMAIL_MISSING_BODY", {
760
- hint: "payload requires either `template` OR `{ subject, html }`"
761
- });
762
- }
763
- /** Routes an OTP dispatch by `action`, defaulting to `generate`. */
764
- async dispatchOtp(tenantId, payload) {
765
- const otp = this.getOtp();
766
- const action = payload.action ?? "generate";
767
- const ref = {
768
- tenantId,
769
- recipient: payload.recipient,
770
- purpose: payload.purpose,
771
- ...payload.userId !== void 0 ? { userId: payload.userId } : {}
772
- };
773
- if (action === "verify") {
774
- return otp.verify({ ...ref, code: payload.code ?? "" });
775
- }
776
- if (action === "consume") {
777
- return otp.consume(ref);
778
- }
779
- return otp.generate(this.toGenerateInput(ref, payload));
780
- }
781
- /** Builds the `sendTemplate` input from a resolved template name and payload. */
782
- toTemplateInput(tenantId, template, payload) {
783
- return {
784
- tenantId,
785
- to: payload.to,
786
- template,
787
- data: payload.data ?? {},
788
- ...payload.locale !== void 0 ? { locale: payload.locale } : {},
789
- ...this.commonEmailFields(payload)
790
- };
791
- }
792
- /** Builds the raw `send` input from a resolved subject/html and payload. */
793
- toSendInput(tenantId, subject, html, payload) {
794
- return {
795
- tenantId,
796
- to: payload.to,
797
- subject,
798
- html,
799
- ...payload.text !== void 0 ? { text: payload.text } : {},
800
- ...this.commonEmailFields(payload)
801
- };
802
- }
803
- /** The optional envelope fields shared by both email paths. */
804
- commonEmailFields(payload) {
805
- return {
806
- ...payload.from !== void 0 ? { from: payload.from } : {},
807
- ...payload.fromName !== void 0 ? { fromName: payload.fromName } : {},
808
- ...payload.replyTo !== void 0 ? { replyTo: payload.replyTo } : {},
809
- ...payload.tags !== void 0 ? { tags: payload.tags } : {},
810
- ...payload.userId !== void 0 ? { userId: payload.userId } : {}
811
- };
812
- }
813
- /** Builds the `generate` input from a reference and an OTP dispatch payload. */
814
- toGenerateInput(ref, payload) {
815
- return {
816
- ...ref,
817
- ...payload.deliverVia !== void 0 ? { deliverVia: payload.deliverVia } : {},
818
- ...payload.emailTemplate !== void 0 ? { emailTemplate: payload.emailTemplate } : {},
819
- ...payload.emailData !== void 0 ? { emailData: payload.emailData } : {},
820
- ...payload.locale !== void 0 ? { locale: payload.locale } : {}
821
- };
822
- }
823
- };
824
- NotificationService = __decorateClass([
825
- Injectable(),
826
- __decorateParam(0, Optional()),
827
- __decorateParam(1, Optional())
828
- ], NotificationService);
829
693
  var NUMERIC = "0123456789";
830
694
  var ALPHA = "ABCDEFGHJKLMNPQRSTUVWXYZ";
831
695
  var ALPHANUMERIC = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
@@ -1149,6 +1013,156 @@ OtpService = __decorateClass([
1149
1013
  __decorateParam(3, Inject(EmailService))
1150
1014
  ], OtpService);
1151
1015
 
1016
+ // src/server/services/notification.service.ts
1017
+ var NotificationService = class {
1018
+ /**
1019
+ * @param emailService - The email service, present only when the email channel is configured.
1020
+ * @param otpService - The OTP service, present only when the OTP channel is configured.
1021
+ */
1022
+ constructor(emailService, otpService) {
1023
+ this.emailService = emailService;
1024
+ this.otpService = otpService;
1025
+ }
1026
+ /**
1027
+ * Dispatches a notification to the channel named in `input`.
1028
+ *
1029
+ * @param input - The channel-discriminated dispatch request.
1030
+ * @returns The channel-discriminated result.
1031
+ * @throws NotificationException `CHANNEL_DISABLED` (channel not configured) or
1032
+ * `EMAIL_MISSING_BODY` (email payload has neither a template nor subject+html).
1033
+ */
1034
+ async dispatch(input) {
1035
+ if (input.channel === "email") {
1036
+ return {
1037
+ channel: "email",
1038
+ messageId: await this.dispatchEmail(input.tenantId, input.payload)
1039
+ };
1040
+ }
1041
+ return { channel: "otp", result: await this.dispatchOtp(input.tenantId, input.payload) };
1042
+ }
1043
+ /**
1044
+ * Lists the channels whose service is present and reports itself configured.
1045
+ *
1046
+ * @returns The enabled channels.
1047
+ */
1048
+ getEnabledChannels() {
1049
+ const channels = [];
1050
+ if (this.emailService?.isConfigured()) {
1051
+ channels.push("email");
1052
+ }
1053
+ if (this.otpService?.isConfigured()) {
1054
+ channels.push("otp");
1055
+ }
1056
+ return channels;
1057
+ }
1058
+ /**
1059
+ * Returns the email service or throws when the email channel is not enabled.
1060
+ *
1061
+ * @returns The email service.
1062
+ * @throws NotificationException `CHANNEL_DISABLED` when email is not configured.
1063
+ */
1064
+ getEmail() {
1065
+ if (!this.emailService) {
1066
+ throw new NotificationException("CHANNEL_DISABLED", { channel: "email" });
1067
+ }
1068
+ return this.emailService;
1069
+ }
1070
+ /**
1071
+ * Returns the OTP service or throws when the OTP channel is not enabled.
1072
+ *
1073
+ * @returns The OTP service.
1074
+ * @throws NotificationException `CHANNEL_DISABLED` when OTP is not configured.
1075
+ */
1076
+ getOtp() {
1077
+ if (!this.otpService) {
1078
+ throw new NotificationException("CHANNEL_DISABLED", { channel: "otp" });
1079
+ }
1080
+ return this.otpService;
1081
+ }
1082
+ /** Routes an email dispatch to `sendTemplate` (template) or `send` (raw body). */
1083
+ async dispatchEmail(tenantId, payload) {
1084
+ const email = this.getEmail();
1085
+ if (payload.template !== void 0) {
1086
+ const input = this.toTemplateInput(tenantId, payload.template, payload);
1087
+ return (await email.sendTemplate(input)).messageId;
1088
+ }
1089
+ if (payload.subject !== void 0 && payload.html !== void 0) {
1090
+ const input = this.toSendInput(tenantId, payload.subject, payload.html, payload);
1091
+ return (await email.send(input)).messageId;
1092
+ }
1093
+ throw new NotificationException("EMAIL_MISSING_BODY", {
1094
+ hint: "payload requires either `template` OR `{ subject, html }`"
1095
+ });
1096
+ }
1097
+ /** Routes an OTP dispatch by `action`, defaulting to `generate`. */
1098
+ async dispatchOtp(tenantId, payload) {
1099
+ const otp = this.getOtp();
1100
+ const action = payload.action ?? "generate";
1101
+ const ref = {
1102
+ tenantId,
1103
+ recipient: payload.recipient,
1104
+ purpose: payload.purpose,
1105
+ ...payload.userId !== void 0 ? { userId: payload.userId } : {}
1106
+ };
1107
+ if (action === "verify") {
1108
+ return otp.verify({ ...ref, code: payload.code ?? "" });
1109
+ }
1110
+ if (action === "consume") {
1111
+ return otp.consume(ref);
1112
+ }
1113
+ return otp.generate(this.toGenerateInput(ref, payload));
1114
+ }
1115
+ /** Builds the `sendTemplate` input from a resolved template name and payload. */
1116
+ toTemplateInput(tenantId, template, payload) {
1117
+ return {
1118
+ tenantId,
1119
+ to: payload.to,
1120
+ template,
1121
+ data: payload.data ?? {},
1122
+ ...payload.locale !== void 0 ? { locale: payload.locale } : {},
1123
+ ...this.commonEmailFields(payload)
1124
+ };
1125
+ }
1126
+ /** Builds the raw `send` input from a resolved subject/html and payload. */
1127
+ toSendInput(tenantId, subject, html, payload) {
1128
+ return {
1129
+ tenantId,
1130
+ to: payload.to,
1131
+ subject,
1132
+ html,
1133
+ ...payload.text !== void 0 ? { text: payload.text } : {},
1134
+ ...this.commonEmailFields(payload)
1135
+ };
1136
+ }
1137
+ /** The optional envelope fields shared by both email paths. */
1138
+ commonEmailFields(payload) {
1139
+ return {
1140
+ ...payload.from !== void 0 ? { from: payload.from } : {},
1141
+ ...payload.fromName !== void 0 ? { fromName: payload.fromName } : {},
1142
+ ...payload.replyTo !== void 0 ? { replyTo: payload.replyTo } : {},
1143
+ ...payload.tags !== void 0 ? { tags: payload.tags } : {},
1144
+ ...payload.userId !== void 0 ? { userId: payload.userId } : {}
1145
+ };
1146
+ }
1147
+ /** Builds the `generate` input from a reference and an OTP dispatch payload. */
1148
+ toGenerateInput(ref, payload) {
1149
+ return {
1150
+ ...ref,
1151
+ ...payload.deliverVia !== void 0 ? { deliverVia: payload.deliverVia } : {},
1152
+ ...payload.emailTemplate !== void 0 ? { emailTemplate: payload.emailTemplate } : {},
1153
+ ...payload.emailData !== void 0 ? { emailData: payload.emailData } : {},
1154
+ ...payload.locale !== void 0 ? { locale: payload.locale } : {}
1155
+ };
1156
+ }
1157
+ };
1158
+ NotificationService = __decorateClass([
1159
+ Injectable(),
1160
+ __decorateParam(0, Optional()),
1161
+ __decorateParam(0, Inject(EmailService)),
1162
+ __decorateParam(1, Optional()),
1163
+ __decorateParam(1, Inject(OtpService))
1164
+ ], NotificationService);
1165
+
1152
1166
  // src/server/bymax-notification.module.ts
1153
1167
  var RAW_NOTIFICATION_OPTIONS = /* @__PURE__ */ Symbol("RAW_NOTIFICATION_OPTIONS");
1154
1168
  var BymaxNotificationModule = class {
@@ -1561,12 +1575,9 @@ NoOpEmailProvider = __decorateClass([
1561
1575
  Injectable()
1562
1576
  ], NoOpEmailProvider);
1563
1577
  var RESEND_MODULE = "resend";
1578
+ var _clientPromise, _options;
1564
1579
  var ResendEmailProvider = class {
1565
- /**
1566
- * @param options - Adapter options; `apiKey` is required to actually send.
1567
- */
1568
1580
  constructor(options = {}) {
1569
- this.options = options;
1570
1581
  this.name = "resend";
1571
1582
  this.logger = new Logger(ResendEmailProvider.name);
1572
1583
  /**
@@ -1575,7 +1586,22 @@ var ResendEmailProvider = class {
1575
1586
  * collapses concurrent first sends onto a single dynamic `import()` + instantiation;
1576
1587
  * a failed init resets this back to `null` so a transient error can be retried.
1577
1588
  */
1578
- this.clientPromise = null;
1589
+ __privateAdd(this, _clientPromise, null);
1590
+ /**
1591
+ * @param options - Adapter options; `apiKey` is required to actually send.
1592
+ */
1593
+ /**
1594
+ * The adapter options, which carry the Resend API key.
1595
+ *
1596
+ * An ECMAScript private field rather than a TypeScript `private` one: the
1597
+ * latter is erased at runtime, leaving an enumerable own property that
1598
+ * `JSON.stringify`, object spread and `util.inspect` all walk into. This
1599
+ * provider is registered in the container, so anything that renders it
1600
+ * incidentally — a structured logger formatting its arguments, an error
1601
+ * reporter capturing the scope of a throw — would emit the key in plaintext.
1602
+ */
1603
+ __privateAdd(this, _options);
1604
+ __privateSet(this, _options, options);
1579
1605
  }
1580
1606
  /**
1581
1607
  * Whether an API key was supplied. Does not load the SDK.
@@ -1583,7 +1609,7 @@ var ResendEmailProvider = class {
1583
1609
  * @returns `true` when an `apiKey` is present.
1584
1610
  */
1585
1611
  isConfigured() {
1586
- return Boolean(this.options.apiKey);
1612
+ return Boolean(__privateGet(this, _options).apiKey);
1587
1613
  }
1588
1614
  /**
1589
1615
  * Sends one transactional email through Resend.
@@ -1645,8 +1671,8 @@ var ResendEmailProvider = class {
1645
1671
  * @throws Error When `apiKey` is missing or the `resend` package is not installed.
1646
1672
  */
1647
1673
  getClient() {
1648
- this.clientPromise ??= this.createClient();
1649
- return this.clientPromise;
1674
+ __privateGet(this, _clientPromise) ?? __privateSet(this, _clientPromise, this.createClient());
1675
+ return __privateGet(this, _clientPromise);
1650
1676
  }
1651
1677
  /**
1652
1678
  * Builds a fresh SDK client, resetting the cached promise on any failure so the
@@ -1657,14 +1683,14 @@ var ResendEmailProvider = class {
1657
1683
  */
1658
1684
  async createClient() {
1659
1685
  try {
1660
- const apiKey = this.options.apiKey;
1686
+ const apiKey = __privateGet(this, _options).apiKey;
1661
1687
  if (!apiKey) {
1662
1688
  throw new Error("ResendEmailProvider: missing API key \u2014 pass { apiKey } to the constructor");
1663
1689
  }
1664
1690
  const ResendCtor = await this.loadResendConstructor();
1665
1691
  return new ResendCtor(apiKey);
1666
1692
  } catch (error) {
1667
- this.clientPromise = null;
1693
+ __privateSet(this, _clientPromise, null);
1668
1694
  throw error;
1669
1695
  }
1670
1696
  }
@@ -1685,6 +1711,8 @@ var ResendEmailProvider = class {
1685
1711
  }
1686
1712
  }
1687
1713
  };
1714
+ _clientPromise = new WeakMap();
1715
+ _options = new WeakMap();
1688
1716
  ResendEmailProvider = __decorateClass([
1689
1717
  Injectable()
1690
1718
  ], ResendEmailProvider);
@@ -1865,13 +1893,24 @@ function hashTenantRecipient(tenantId, recipient) {
1865
1893
 
1866
1894
  // src/server/providers/redis-otp.storage.ts
1867
1895
  var MS_PER_SECOND4 = 1e3;
1896
+ var _redis;
1868
1897
  var RedisOtpStorage = class {
1869
1898
  /**
1870
1899
  * @param options - The Redis client and optional namespace.
1871
1900
  */
1872
1901
  constructor(options) {
1873
1902
  this.name = "redis";
1874
- this.redis = options.redisClient;
1903
+ /**
1904
+ * The Redis client.
1905
+ *
1906
+ * An ECMAScript private field rather than a TypeScript `private` one, which
1907
+ * is erased at runtime: an ioredis instance carries `options.password` as a
1908
+ * plain field, so leaving this enumerable would let anything that serializes
1909
+ * this storage — a structured logger, an error reporter walking the scope of
1910
+ * a throw — reach the Redis credentials.
1911
+ */
1912
+ __privateAdd(this, _redis);
1913
+ __privateSet(this, _redis, options.redisClient);
1875
1914
  this.namespace = options.namespace ?? "notification";
1876
1915
  }
1877
1916
  /** Whether a Redis client was supplied.
@@ -1879,7 +1918,7 @@ var RedisOtpStorage = class {
1879
1918
  * @returns `true` when a client is present.
1880
1919
  */
1881
1920
  isConfigured() {
1882
- return Boolean(this.redis);
1921
+ return Boolean(__privateGet(this, _redis));
1883
1922
  }
1884
1923
  /**
1885
1924
  * Creates or replaces an OTP entry with a TTL derived from `expiresAt`.
@@ -1891,7 +1930,7 @@ var RedisOtpStorage = class {
1891
1930
  */
1892
1931
  async set(tenantId, recipient, purpose, entry) {
1893
1932
  const ttlSeconds = Math.max(1, Math.ceil((entry.expiresAt - Date.now()) / MS_PER_SECOND4));
1894
- await this.redis.setex(
1933
+ await __privateGet(this, _redis).setex(
1895
1934
  this.otpKey(tenantId, recipient, purpose),
1896
1935
  ttlSeconds,
1897
1936
  JSON.stringify(entry)
@@ -1906,7 +1945,7 @@ var RedisOtpStorage = class {
1906
1945
  * @returns The parsed entry, or `null` when absent/corrupted.
1907
1946
  */
1908
1947
  async get(tenantId, recipient, purpose) {
1909
- const raw = await this.redis.get(this.otpKey(tenantId, recipient, purpose));
1948
+ const raw = await __privateGet(this, _redis).get(this.otpKey(tenantId, recipient, purpose));
1910
1949
  if (!raw) {
1911
1950
  return null;
1912
1951
  }
@@ -1926,7 +1965,7 @@ var RedisOtpStorage = class {
1926
1965
  * @returns `not_found`, `max_attempts`, or `ok` with the incremented entry.
1927
1966
  */
1928
1967
  async consumeAttempt(tenantId, recipient, purpose) {
1929
- const raw = await this.redis.eval(
1968
+ const raw = await __privateGet(this, _redis).eval(
1930
1969
  RedisOtpStorage.CONSUME_ATTEMPT_LUA,
1931
1970
  1,
1932
1971
  this.otpKey(tenantId, recipient, purpose),
@@ -1944,7 +1983,7 @@ var RedisOtpStorage = class {
1944
1983
  * @param entry - The replacement entry.
1945
1984
  */
1946
1985
  async update(tenantId, recipient, purpose, entry) {
1947
- await this.redis.set(
1986
+ await __privateGet(this, _redis).set(
1948
1987
  this.otpKey(tenantId, recipient, purpose),
1949
1988
  JSON.stringify(entry),
1950
1989
  "KEEPTTL",
@@ -1959,7 +1998,7 @@ var RedisOtpStorage = class {
1959
1998
  * @param purpose - OTP purpose.
1960
1999
  */
1961
2000
  async delete(tenantId, recipient, purpose) {
1962
- await this.redis.del(this.otpKey(tenantId, recipient, purpose));
2001
+ await __privateGet(this, _redis).del(this.otpKey(tenantId, recipient, purpose));
1963
2002
  }
1964
2003
  /**
1965
2004
  * Atomic cooldown acquire with `SET … NX EX` — only the first concurrent caller wins.
@@ -1978,10 +2017,10 @@ var RedisOtpStorage = class {
1978
2017
  async tryAcquireCooldown(tenantId, recipient, purpose, ttlSeconds) {
1979
2018
  const key = this.cooldownKey(tenantId, recipient, purpose);
1980
2019
  if (ttlSeconds <= 0) {
1981
- await this.redis.del(key);
2020
+ await __privateGet(this, _redis).del(key);
1982
2021
  return true;
1983
2022
  }
1984
- const result = await this.redis.set(key, "1", "EX", ttlSeconds, "NX");
2023
+ const result = await __privateGet(this, _redis).set(key, "1", "EX", ttlSeconds, "NX");
1985
2024
  return result === "OK";
1986
2025
  }
1987
2026
  /**
@@ -1993,7 +2032,7 @@ var RedisOtpStorage = class {
1993
2032
  * @returns Remaining seconds, or `0` when there is no active cooldown.
1994
2033
  */
1995
2034
  async getCooldown(tenantId, recipient, purpose) {
1996
- const ttl = await this.redis.ttl(this.cooldownKey(tenantId, recipient, purpose));
2035
+ const ttl = await __privateGet(this, _redis).ttl(this.cooldownKey(tenantId, recipient, purpose));
1997
2036
  return ttl > 0 ? ttl : 0;
1998
2037
  }
1999
2038
  /**
@@ -2004,7 +2043,7 @@ var RedisOtpStorage = class {
2004
2043
  * @param purpose - OTP purpose.
2005
2044
  */
2006
2045
  async clearCooldown(tenantId, recipient, purpose) {
2007
- await this.redis.del(this.cooldownKey(tenantId, recipient, purpose));
2046
+ await __privateGet(this, _redis).del(this.cooldownKey(tenantId, recipient, purpose));
2008
2047
  }
2009
2048
  /** Builds the OTP entry key: `{namespace}:otp:{purpose}:{sha256(tenantId:recipient)}`. */
2010
2049
  otpKey(tenantId, recipient, purpose) {
@@ -2015,6 +2054,7 @@ var RedisOtpStorage = class {
2015
2054
  return `${this.namespace}:otp_cd:${purpose}:${hashTenantRecipient(tenantId, recipient)}`;
2016
2055
  }
2017
2056
  };
2057
+ _redis = new WeakMap();
2018
2058
  /**
2019
2059
  * Atomic verify primitive. The entire read → expiry/max check → increment → write
2020
2060
  * runs in this single script, so concurrent calls cannot overshoot `maxAttempts`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-notification",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
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",
@@ -66,6 +66,31 @@
66
66
  ]
67
67
  }
68
68
  },
69
+ "scripts": {
70
+ "build": "pnpm clean && tsup",
71
+ "check:exports": "attw --pack .",
72
+ "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",
73
+ "check:published": "node scripts/check-published-surface.mjs",
74
+ "clean": "rm -rf dist coverage",
75
+ "lint": "eslint src scripts test",
76
+ "lint:fix": "eslint src scripts test --fix",
77
+ "mutation": "stryker run",
78
+ "mutation:dry-run": "stryker run --dryRunOnly",
79
+ "mutation:incremental": "stryker run --incremental",
80
+ "prepare": "husky",
81
+ "prepublishOnly": "pnpm clean && pnpm typecheck && pnpm test:types && pnpm lint && pnpm check:no-prisma && pnpm test:cov:all && pnpm build && pnpm check:published",
82
+ "release": "npm publish --provenance --access public",
83
+ "size": "node scripts/check-size.mjs",
84
+ "smoke": "node scripts/dogfood-smoke-test.mjs",
85
+ "test": "jest",
86
+ "test:all": "pnpm test && pnpm test:e2e",
87
+ "test:cov": "jest --coverage",
88
+ "test:cov:all": "jest --config jest.coverage.config.ts --coverage",
89
+ "test:e2e": "jest --config jest.e2e.config.ts --runInBand",
90
+ "test:types": "tsc --noEmit -p tsconfig.typetest.json",
91
+ "test:watch": "jest --watch",
92
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.server.json"
93
+ },
69
94
  "dependencies": {},
70
95
  "peerDependencies": {
71
96
  "@nestjs/common": "^11.0.16",
@@ -212,34 +237,12 @@
212
237
  "prettier --write"
213
238
  ]
214
239
  },
240
+ "packageManager": "pnpm@11.20.0",
215
241
  "engines": {
216
242
  "node": ">=24.0.0"
217
243
  },
218
244
  "publishConfig": {
219
245
  "access": "public",
220
246
  "registry": "https://registry.npmjs.org/"
221
- },
222
- "scripts": {
223
- "build": "pnpm clean && tsup",
224
- "check:exports": "attw --pack .",
225
- "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",
226
- "check:published": "node scripts/check-published-surface.mjs",
227
- "clean": "rm -rf dist coverage",
228
- "lint": "eslint src scripts test",
229
- "lint:fix": "eslint src scripts test --fix",
230
- "mutation": "stryker run",
231
- "mutation:dry-run": "stryker run --dryRunOnly",
232
- "mutation:incremental": "stryker run --incremental",
233
- "release": "pnpm publish --provenance",
234
- "size": "node scripts/check-size.mjs",
235
- "smoke": "node scripts/dogfood-smoke-test.mjs",
236
- "test": "jest",
237
- "test:all": "pnpm test && pnpm test:e2e",
238
- "test:cov": "jest --coverage",
239
- "test:cov:all": "jest --config jest.coverage.config.ts --coverage",
240
- "test:e2e": "jest --config jest.e2e.config.ts --runInBand",
241
- "test:types": "tsc --noEmit -p tsconfig.typetest.json",
242
- "test:watch": "jest --watch",
243
- "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.server.json"
244
247
  }
245
- }
248
+ }