@bymax-one/nest-notification 1.0.1 → 1.0.2

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,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.0.2] - 2026-08-04
11
+
12
+ ### Security
13
+
14
+ - The Resend API key and the Redis client are no longer disclosed when the provider or
15
+ the OTP storage that holds them is serialized. `ResendEmailProvider` kept its adapter
16
+ options — which carry `apiKey` — and `RedisOtpStorage` kept its client in TypeScript
17
+ `private` properties, which are erased at runtime and leave enumerable own properties.
18
+ `JSON.stringify`, object spread and `util.inspect` therefore emitted the API key in
19
+ plaintext, and reached `options.password` on the ioredis instance. Both move to
20
+ ECMAScript private fields. That matters because these are registered providers: a
21
+ structured logger rendering its arguments, or an error reporter capturing the scope of
22
+ a throw, walks them without being asked to.
23
+
24
+ Reading on purpose is unchanged and no public type or export moved.
25
+
10
26
  ## [1.0.1] - 2026-08-01
11
27
 
12
28
  ### Security
@@ -99,6 +115,7 @@ rejected at startup rather than failing on the first send.
99
115
  - **`forRootAsync` `useClass` / `useExisting`** — only `useFactory` is wired.
100
116
  - **Multi-provider failover and routing.**
101
117
 
102
- [Unreleased]: https://github.com/bymaxone/nest-notification/compare/v1.0.1...HEAD
118
+ [Unreleased]: https://github.com/bymaxone/nest-notification/compare/v1.0.2...HEAD
119
+ [1.0.2]: https://github.com/bymaxone/nest-notification/compare/v1.0.1...v1.0.2
103
120
  [1.0.1]: https://github.com/bymaxone/nest-notification/compare/v1.0.0...v1.0.1
104
121
  [1.0.0]: https://github.com/bymaxone/nest-notification/releases/tag/v1.0.0
package/README.md CHANGED
@@ -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");
@@ -1563,12 +1570,9 @@ exports.NoOpEmailProvider = __decorateClass([
1563
1570
  common.Injectable()
1564
1571
  ], exports.NoOpEmailProvider);
1565
1572
  var RESEND_MODULE = "resend";
1573
+ var _clientPromise, _options;
1566
1574
  exports.ResendEmailProvider = class ResendEmailProvider {
1567
- /**
1568
- * @param options - Adapter options; `apiKey` is required to actually send.
1569
- */
1570
1575
  constructor(options = {}) {
1571
- this.options = options;
1572
1576
  this.name = "resend";
1573
1577
  this.logger = new common.Logger(exports.ResendEmailProvider.name);
1574
1578
  /**
@@ -1577,7 +1581,22 @@ exports.ResendEmailProvider = class ResendEmailProvider {
1577
1581
  * collapses concurrent first sends onto a single dynamic `import()` + instantiation;
1578
1582
  * a failed init resets this back to `null` so a transient error can be retried.
1579
1583
  */
1580
- this.clientPromise = null;
1584
+ __privateAdd(this, _clientPromise, null);
1585
+ /**
1586
+ * @param options - Adapter options; `apiKey` is required to actually send.
1587
+ */
1588
+ /**
1589
+ * The adapter options, which carry the Resend API key.
1590
+ *
1591
+ * An ECMAScript private field rather than a TypeScript `private` one: the
1592
+ * latter is erased at runtime, leaving an enumerable own property that
1593
+ * `JSON.stringify`, object spread and `util.inspect` all walk into. This
1594
+ * provider is registered in the container, so anything that renders it
1595
+ * incidentally — a structured logger formatting its arguments, an error
1596
+ * reporter capturing the scope of a throw — would emit the key in plaintext.
1597
+ */
1598
+ __privateAdd(this, _options);
1599
+ __privateSet(this, _options, options);
1581
1600
  }
1582
1601
  /**
1583
1602
  * Whether an API key was supplied. Does not load the SDK.
@@ -1585,7 +1604,7 @@ exports.ResendEmailProvider = class ResendEmailProvider {
1585
1604
  * @returns `true` when an `apiKey` is present.
1586
1605
  */
1587
1606
  isConfigured() {
1588
- return Boolean(this.options.apiKey);
1607
+ return Boolean(__privateGet(this, _options).apiKey);
1589
1608
  }
1590
1609
  /**
1591
1610
  * Sends one transactional email through Resend.
@@ -1647,8 +1666,8 @@ exports.ResendEmailProvider = class ResendEmailProvider {
1647
1666
  * @throws Error When `apiKey` is missing or the `resend` package is not installed.
1648
1667
  */
1649
1668
  getClient() {
1650
- this.clientPromise ??= this.createClient();
1651
- return this.clientPromise;
1669
+ __privateGet(this, _clientPromise) ?? __privateSet(this, _clientPromise, this.createClient());
1670
+ return __privateGet(this, _clientPromise);
1652
1671
  }
1653
1672
  /**
1654
1673
  * Builds a fresh SDK client, resetting the cached promise on any failure so the
@@ -1659,14 +1678,14 @@ exports.ResendEmailProvider = class ResendEmailProvider {
1659
1678
  */
1660
1679
  async createClient() {
1661
1680
  try {
1662
- const apiKey = this.options.apiKey;
1681
+ const apiKey = __privateGet(this, _options).apiKey;
1663
1682
  if (!apiKey) {
1664
1683
  throw new Error("ResendEmailProvider: missing API key \u2014 pass { apiKey } to the constructor");
1665
1684
  }
1666
1685
  const ResendCtor = await this.loadResendConstructor();
1667
1686
  return new ResendCtor(apiKey);
1668
1687
  } catch (error) {
1669
- this.clientPromise = null;
1688
+ __privateSet(this, _clientPromise, null);
1670
1689
  throw error;
1671
1690
  }
1672
1691
  }
@@ -1687,6 +1706,8 @@ exports.ResendEmailProvider = class ResendEmailProvider {
1687
1706
  }
1688
1707
  }
1689
1708
  };
1709
+ _clientPromise = new WeakMap();
1710
+ _options = new WeakMap();
1690
1711
  exports.ResendEmailProvider = __decorateClass([
1691
1712
  common.Injectable()
1692
1713
  ], exports.ResendEmailProvider);
@@ -1867,13 +1888,24 @@ function hashTenantRecipient(tenantId, recipient) {
1867
1888
 
1868
1889
  // src/server/providers/redis-otp.storage.ts
1869
1890
  var MS_PER_SECOND4 = 1e3;
1891
+ var _redis;
1870
1892
  exports.RedisOtpStorage = class RedisOtpStorage {
1871
1893
  /**
1872
1894
  * @param options - The Redis client and optional namespace.
1873
1895
  */
1874
1896
  constructor(options) {
1875
1897
  this.name = "redis";
1876
- this.redis = options.redisClient;
1898
+ /**
1899
+ * The Redis client.
1900
+ *
1901
+ * An ECMAScript private field rather than a TypeScript `private` one, which
1902
+ * is erased at runtime: an ioredis instance carries `options.password` as a
1903
+ * plain field, so leaving this enumerable would let anything that serializes
1904
+ * this storage — a structured logger, an error reporter walking the scope of
1905
+ * a throw — reach the Redis credentials.
1906
+ */
1907
+ __privateAdd(this, _redis);
1908
+ __privateSet(this, _redis, options.redisClient);
1877
1909
  this.namespace = options.namespace ?? "notification";
1878
1910
  }
1879
1911
  /** Whether a Redis client was supplied.
@@ -1881,7 +1913,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1881
1913
  * @returns `true` when a client is present.
1882
1914
  */
1883
1915
  isConfigured() {
1884
- return Boolean(this.redis);
1916
+ return Boolean(__privateGet(this, _redis));
1885
1917
  }
1886
1918
  /**
1887
1919
  * Creates or replaces an OTP entry with a TTL derived from `expiresAt`.
@@ -1893,7 +1925,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1893
1925
  */
1894
1926
  async set(tenantId, recipient, purpose, entry) {
1895
1927
  const ttlSeconds = Math.max(1, Math.ceil((entry.expiresAt - Date.now()) / MS_PER_SECOND4));
1896
- await this.redis.setex(
1928
+ await __privateGet(this, _redis).setex(
1897
1929
  this.otpKey(tenantId, recipient, purpose),
1898
1930
  ttlSeconds,
1899
1931
  JSON.stringify(entry)
@@ -1908,7 +1940,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1908
1940
  * @returns The parsed entry, or `null` when absent/corrupted.
1909
1941
  */
1910
1942
  async get(tenantId, recipient, purpose) {
1911
- const raw = await this.redis.get(this.otpKey(tenantId, recipient, purpose));
1943
+ const raw = await __privateGet(this, _redis).get(this.otpKey(tenantId, recipient, purpose));
1912
1944
  if (!raw) {
1913
1945
  return null;
1914
1946
  }
@@ -1928,7 +1960,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1928
1960
  * @returns `not_found`, `max_attempts`, or `ok` with the incremented entry.
1929
1961
  */
1930
1962
  async consumeAttempt(tenantId, recipient, purpose) {
1931
- const raw = await this.redis.eval(
1963
+ const raw = await __privateGet(this, _redis).eval(
1932
1964
  exports.RedisOtpStorage.CONSUME_ATTEMPT_LUA,
1933
1965
  1,
1934
1966
  this.otpKey(tenantId, recipient, purpose),
@@ -1946,7 +1978,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1946
1978
  * @param entry - The replacement entry.
1947
1979
  */
1948
1980
  async update(tenantId, recipient, purpose, entry) {
1949
- await this.redis.set(
1981
+ await __privateGet(this, _redis).set(
1950
1982
  this.otpKey(tenantId, recipient, purpose),
1951
1983
  JSON.stringify(entry),
1952
1984
  "KEEPTTL",
@@ -1961,7 +1993,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1961
1993
  * @param purpose - OTP purpose.
1962
1994
  */
1963
1995
  async delete(tenantId, recipient, purpose) {
1964
- await this.redis.del(this.otpKey(tenantId, recipient, purpose));
1996
+ await __privateGet(this, _redis).del(this.otpKey(tenantId, recipient, purpose));
1965
1997
  }
1966
1998
  /**
1967
1999
  * Atomic cooldown acquire with `SET … NX EX` — only the first concurrent caller wins.
@@ -1980,10 +2012,10 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1980
2012
  async tryAcquireCooldown(tenantId, recipient, purpose, ttlSeconds) {
1981
2013
  const key = this.cooldownKey(tenantId, recipient, purpose);
1982
2014
  if (ttlSeconds <= 0) {
1983
- await this.redis.del(key);
2015
+ await __privateGet(this, _redis).del(key);
1984
2016
  return true;
1985
2017
  }
1986
- const result = await this.redis.set(key, "1", "EX", ttlSeconds, "NX");
2018
+ const result = await __privateGet(this, _redis).set(key, "1", "EX", ttlSeconds, "NX");
1987
2019
  return result === "OK";
1988
2020
  }
1989
2021
  /**
@@ -1995,7 +2027,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
1995
2027
  * @returns Remaining seconds, or `0` when there is no active cooldown.
1996
2028
  */
1997
2029
  async getCooldown(tenantId, recipient, purpose) {
1998
- const ttl = await this.redis.ttl(this.cooldownKey(tenantId, recipient, purpose));
2030
+ const ttl = await __privateGet(this, _redis).ttl(this.cooldownKey(tenantId, recipient, purpose));
1999
2031
  return ttl > 0 ? ttl : 0;
2000
2032
  }
2001
2033
  /**
@@ -2006,7 +2038,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
2006
2038
  * @param purpose - OTP purpose.
2007
2039
  */
2008
2040
  async clearCooldown(tenantId, recipient, purpose) {
2009
- await this.redis.del(this.cooldownKey(tenantId, recipient, purpose));
2041
+ await __privateGet(this, _redis).del(this.cooldownKey(tenantId, recipient, purpose));
2010
2042
  }
2011
2043
  /** Builds the OTP entry key: `{namespace}:otp:{purpose}:{sha256(tenantId:recipient)}`. */
2012
2044
  otpKey(tenantId, recipient, purpose) {
@@ -2017,6 +2049,7 @@ exports.RedisOtpStorage = class RedisOtpStorage {
2017
2049
  return `${this.namespace}:otp_cd:${purpose}:${hashTenantRecipient(tenantId, recipient)}`;
2018
2050
  }
2019
2051
  };
2052
+ _redis = new WeakMap();
2020
2053
  /**
2021
2054
  * Atomic verify primitive. The entire read → expiry/max check → increment → write
2022
2055
  * 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");
@@ -1561,12 +1568,9 @@ NoOpEmailProvider = __decorateClass([
1561
1568
  Injectable()
1562
1569
  ], NoOpEmailProvider);
1563
1570
  var RESEND_MODULE = "resend";
1571
+ var _clientPromise, _options;
1564
1572
  var ResendEmailProvider = class {
1565
- /**
1566
- * @param options - Adapter options; `apiKey` is required to actually send.
1567
- */
1568
1573
  constructor(options = {}) {
1569
- this.options = options;
1570
1574
  this.name = "resend";
1571
1575
  this.logger = new Logger(ResendEmailProvider.name);
1572
1576
  /**
@@ -1575,7 +1579,22 @@ var ResendEmailProvider = class {
1575
1579
  * collapses concurrent first sends onto a single dynamic `import()` + instantiation;
1576
1580
  * a failed init resets this back to `null` so a transient error can be retried.
1577
1581
  */
1578
- this.clientPromise = null;
1582
+ __privateAdd(this, _clientPromise, null);
1583
+ /**
1584
+ * @param options - Adapter options; `apiKey` is required to actually send.
1585
+ */
1586
+ /**
1587
+ * The adapter options, which carry the Resend API key.
1588
+ *
1589
+ * An ECMAScript private field rather than a TypeScript `private` one: the
1590
+ * latter is erased at runtime, leaving an enumerable own property that
1591
+ * `JSON.stringify`, object spread and `util.inspect` all walk into. This
1592
+ * provider is registered in the container, so anything that renders it
1593
+ * incidentally — a structured logger formatting its arguments, an error
1594
+ * reporter capturing the scope of a throw — would emit the key in plaintext.
1595
+ */
1596
+ __privateAdd(this, _options);
1597
+ __privateSet(this, _options, options);
1579
1598
  }
1580
1599
  /**
1581
1600
  * Whether an API key was supplied. Does not load the SDK.
@@ -1583,7 +1602,7 @@ var ResendEmailProvider = class {
1583
1602
  * @returns `true` when an `apiKey` is present.
1584
1603
  */
1585
1604
  isConfigured() {
1586
- return Boolean(this.options.apiKey);
1605
+ return Boolean(__privateGet(this, _options).apiKey);
1587
1606
  }
1588
1607
  /**
1589
1608
  * Sends one transactional email through Resend.
@@ -1645,8 +1664,8 @@ var ResendEmailProvider = class {
1645
1664
  * @throws Error When `apiKey` is missing or the `resend` package is not installed.
1646
1665
  */
1647
1666
  getClient() {
1648
- this.clientPromise ??= this.createClient();
1649
- return this.clientPromise;
1667
+ __privateGet(this, _clientPromise) ?? __privateSet(this, _clientPromise, this.createClient());
1668
+ return __privateGet(this, _clientPromise);
1650
1669
  }
1651
1670
  /**
1652
1671
  * Builds a fresh SDK client, resetting the cached promise on any failure so the
@@ -1657,14 +1676,14 @@ var ResendEmailProvider = class {
1657
1676
  */
1658
1677
  async createClient() {
1659
1678
  try {
1660
- const apiKey = this.options.apiKey;
1679
+ const apiKey = __privateGet(this, _options).apiKey;
1661
1680
  if (!apiKey) {
1662
1681
  throw new Error("ResendEmailProvider: missing API key \u2014 pass { apiKey } to the constructor");
1663
1682
  }
1664
1683
  const ResendCtor = await this.loadResendConstructor();
1665
1684
  return new ResendCtor(apiKey);
1666
1685
  } catch (error) {
1667
- this.clientPromise = null;
1686
+ __privateSet(this, _clientPromise, null);
1668
1687
  throw error;
1669
1688
  }
1670
1689
  }
@@ -1685,6 +1704,8 @@ var ResendEmailProvider = class {
1685
1704
  }
1686
1705
  }
1687
1706
  };
1707
+ _clientPromise = new WeakMap();
1708
+ _options = new WeakMap();
1688
1709
  ResendEmailProvider = __decorateClass([
1689
1710
  Injectable()
1690
1711
  ], ResendEmailProvider);
@@ -1865,13 +1886,24 @@ function hashTenantRecipient(tenantId, recipient) {
1865
1886
 
1866
1887
  // src/server/providers/redis-otp.storage.ts
1867
1888
  var MS_PER_SECOND4 = 1e3;
1889
+ var _redis;
1868
1890
  var RedisOtpStorage = class {
1869
1891
  /**
1870
1892
  * @param options - The Redis client and optional namespace.
1871
1893
  */
1872
1894
  constructor(options) {
1873
1895
  this.name = "redis";
1874
- this.redis = options.redisClient;
1896
+ /**
1897
+ * The Redis client.
1898
+ *
1899
+ * An ECMAScript private field rather than a TypeScript `private` one, which
1900
+ * is erased at runtime: an ioredis instance carries `options.password` as a
1901
+ * plain field, so leaving this enumerable would let anything that serializes
1902
+ * this storage — a structured logger, an error reporter walking the scope of
1903
+ * a throw — reach the Redis credentials.
1904
+ */
1905
+ __privateAdd(this, _redis);
1906
+ __privateSet(this, _redis, options.redisClient);
1875
1907
  this.namespace = options.namespace ?? "notification";
1876
1908
  }
1877
1909
  /** Whether a Redis client was supplied.
@@ -1879,7 +1911,7 @@ var RedisOtpStorage = class {
1879
1911
  * @returns `true` when a client is present.
1880
1912
  */
1881
1913
  isConfigured() {
1882
- return Boolean(this.redis);
1914
+ return Boolean(__privateGet(this, _redis));
1883
1915
  }
1884
1916
  /**
1885
1917
  * Creates or replaces an OTP entry with a TTL derived from `expiresAt`.
@@ -1891,7 +1923,7 @@ var RedisOtpStorage = class {
1891
1923
  */
1892
1924
  async set(tenantId, recipient, purpose, entry) {
1893
1925
  const ttlSeconds = Math.max(1, Math.ceil((entry.expiresAt - Date.now()) / MS_PER_SECOND4));
1894
- await this.redis.setex(
1926
+ await __privateGet(this, _redis).setex(
1895
1927
  this.otpKey(tenantId, recipient, purpose),
1896
1928
  ttlSeconds,
1897
1929
  JSON.stringify(entry)
@@ -1906,7 +1938,7 @@ var RedisOtpStorage = class {
1906
1938
  * @returns The parsed entry, or `null` when absent/corrupted.
1907
1939
  */
1908
1940
  async get(tenantId, recipient, purpose) {
1909
- const raw = await this.redis.get(this.otpKey(tenantId, recipient, purpose));
1941
+ const raw = await __privateGet(this, _redis).get(this.otpKey(tenantId, recipient, purpose));
1910
1942
  if (!raw) {
1911
1943
  return null;
1912
1944
  }
@@ -1926,7 +1958,7 @@ var RedisOtpStorage = class {
1926
1958
  * @returns `not_found`, `max_attempts`, or `ok` with the incremented entry.
1927
1959
  */
1928
1960
  async consumeAttempt(tenantId, recipient, purpose) {
1929
- const raw = await this.redis.eval(
1961
+ const raw = await __privateGet(this, _redis).eval(
1930
1962
  RedisOtpStorage.CONSUME_ATTEMPT_LUA,
1931
1963
  1,
1932
1964
  this.otpKey(tenantId, recipient, purpose),
@@ -1944,7 +1976,7 @@ var RedisOtpStorage = class {
1944
1976
  * @param entry - The replacement entry.
1945
1977
  */
1946
1978
  async update(tenantId, recipient, purpose, entry) {
1947
- await this.redis.set(
1979
+ await __privateGet(this, _redis).set(
1948
1980
  this.otpKey(tenantId, recipient, purpose),
1949
1981
  JSON.stringify(entry),
1950
1982
  "KEEPTTL",
@@ -1959,7 +1991,7 @@ var RedisOtpStorage = class {
1959
1991
  * @param purpose - OTP purpose.
1960
1992
  */
1961
1993
  async delete(tenantId, recipient, purpose) {
1962
- await this.redis.del(this.otpKey(tenantId, recipient, purpose));
1994
+ await __privateGet(this, _redis).del(this.otpKey(tenantId, recipient, purpose));
1963
1995
  }
1964
1996
  /**
1965
1997
  * Atomic cooldown acquire with `SET … NX EX` — only the first concurrent caller wins.
@@ -1978,10 +2010,10 @@ var RedisOtpStorage = class {
1978
2010
  async tryAcquireCooldown(tenantId, recipient, purpose, ttlSeconds) {
1979
2011
  const key = this.cooldownKey(tenantId, recipient, purpose);
1980
2012
  if (ttlSeconds <= 0) {
1981
- await this.redis.del(key);
2013
+ await __privateGet(this, _redis).del(key);
1982
2014
  return true;
1983
2015
  }
1984
- const result = await this.redis.set(key, "1", "EX", ttlSeconds, "NX");
2016
+ const result = await __privateGet(this, _redis).set(key, "1", "EX", ttlSeconds, "NX");
1985
2017
  return result === "OK";
1986
2018
  }
1987
2019
  /**
@@ -1993,7 +2025,7 @@ var RedisOtpStorage = class {
1993
2025
  * @returns Remaining seconds, or `0` when there is no active cooldown.
1994
2026
  */
1995
2027
  async getCooldown(tenantId, recipient, purpose) {
1996
- const ttl = await this.redis.ttl(this.cooldownKey(tenantId, recipient, purpose));
2028
+ const ttl = await __privateGet(this, _redis).ttl(this.cooldownKey(tenantId, recipient, purpose));
1997
2029
  return ttl > 0 ? ttl : 0;
1998
2030
  }
1999
2031
  /**
@@ -2004,7 +2036,7 @@ var RedisOtpStorage = class {
2004
2036
  * @param purpose - OTP purpose.
2005
2037
  */
2006
2038
  async clearCooldown(tenantId, recipient, purpose) {
2007
- await this.redis.del(this.cooldownKey(tenantId, recipient, purpose));
2039
+ await __privateGet(this, _redis).del(this.cooldownKey(tenantId, recipient, purpose));
2008
2040
  }
2009
2041
  /** Builds the OTP entry key: `{namespace}:otp:{purpose}:{sha256(tenantId:recipient)}`. */
2010
2042
  otpKey(tenantId, recipient, purpose) {
@@ -2015,6 +2047,7 @@ var RedisOtpStorage = class {
2015
2047
  return `${this.namespace}:otp_cd:${purpose}:${hashTenantRecipient(tenantId, recipient)}`;
2016
2048
  }
2017
2049
  };
2050
+ _redis = new WeakMap();
2018
2051
  /**
2019
2052
  * Atomic verify primitive. The entire read → expiry/max check → increment → write
2020
2053
  * 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.2",
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,6 +237,7 @@
212
237
  "prettier --write"
213
238
  ]
214
239
  },
240
+ "packageManager": "pnpm@10.8.1",
215
241
  "engines": {
216
242
  "node": ">=24.0.0"
217
243
  },
@@ -219,27 +245,16 @@
219
245
  "access": "public",
220
246
  "registry": "https://registry.npmjs.org/"
221
247
  },
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"
248
+ "pnpm": {
249
+ "overrides": {
250
+ "brace-expansion@1": "^1.1.18",
251
+ "brace-expansion@2": "^2.1.4",
252
+ "brace-expansion@5": "^5.0.9",
253
+ "esbuild": "^0.28.1",
254
+ "fast-uri": "^3.1.5",
255
+ "js-yaml@3": "^3.15.0",
256
+ "js-yaml@4": "^4.3.0",
257
+ "qs": "^6.15.2"
258
+ }
244
259
  }
245
- }
260
+ }