@bymax-one/nest-notification 1.1.1 → 1.1.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
@@ -5,6 +5,37 @@ All notable changes to `@bymax-one/nest-notification` will be documented in this
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.1.2] - 2026-08-14
9
+
10
+ ### Fixed
11
+
12
+ - **A failed optional-peer import no longer always blames a missing package.** `SmtpEmailProvider`
13
+ and `ResendEmailProvider` both wrapped their lazy `import()` in a bare `catch` that mapped _every_
14
+ failure to `` `<pkg>` package is not installed. Run `pnpm add <pkg>` ``. That is worse than no
15
+ message: it names a fix that cannot work, so a consumer reinstalls a package that is already in
16
+ `node_modules` and starts doubting their dependency tree.
17
+
18
+ The case that actually bites, reported by a consumer and reproduced against the published 1.1.1
19
+ tarball: a Jest suite running **without `--experimental-vm-modules`** cannot service a dynamic
20
+ `import()` at all and fails with `ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING_FLAG` while the package
21
+ is installed. Every consumer unit test reaching `send()` hit the wrong diagnosis.
22
+
23
+ Now the install instruction requires two things: a module-resolution code —
24
+ `ERR_MODULE_NOT_FOUND` (dynamic import) or `MODULE_NOT_FOUND` (the CommonJS `require` form) — **and**
25
+ a message naming that exact specifier. The code alone is not enough: an _installed_ peer whose own
26
+ evaluation fails because one of **its** dependencies is missing rejects with the very same codes,
27
+ verified on Node 24 with a fixture package, and blaming the top-level peer there would be the same
28
+ bug one level down. The specifier check degrades safely — when it cannot confirm the name, the
29
+ honest message is used, so the worst case is a lost hint rather than a confident wrong claim.
30
+
31
+ Anything else is surfaced as ``Failed to load `<pkg>`: <the real message>`` with the original error
32
+ kept as `cause`. The loading logic now lives once in an internal `loadOptionalPeer` helper, so the
33
+ two adapters cannot drift.
34
+
35
+ **Apply to a derived backend:** none. If a unit suite needs to exercise a code path that reaches
36
+ `send()`, run Jest with `--experimental-vm-modules` — that is the supported way to service a
37
+ dynamic `import()` under Jest, and the error now says so instead of misdirecting.
38
+
8
39
  ## [1.1.1] - 2026-08-14
9
40
 
10
41
  ### Added
@@ -282,6 +313,7 @@ rejected at startup rather than failing on the first send.
282
313
  [1.0.4]: https://github.com/bymaxone/nest-notification/compare/v1.0.3...v1.0.4
283
314
  [1.0.3]: https://github.com/bymaxone/nest-notification/compare/v1.0.2...v1.0.3
284
315
  [Unreleased]: https://github.com/bymaxone/nest-notification/compare/v1.0.6...HEAD
316
+ [1.1.2]: https://github.com/bymaxone/nest-notification/compare/v1.1.1...v1.1.2
285
317
  [1.1.1]: https://github.com/bymaxone/nest-notification/compare/v1.1.0...v1.1.1
286
318
  [1.1.0]: https://github.com/bymaxone/nest-notification/compare/v1.0.6...v1.1.0
287
319
  [1.0.6]: https://github.com/bymaxone/nest-notification/compare/v1.0.5...v1.0.6
@@ -1586,6 +1586,34 @@ exports.NoOpEmailProvider = class NoOpEmailProvider {
1586
1586
  exports.NoOpEmailProvider = __decorateClass([
1587
1587
  common.Injectable()
1588
1588
  ], exports.NoOpEmailProvider);
1589
+
1590
+ // src/server/utils/load-optional-peer.ts
1591
+ var MODULE_NOT_FOUND_CODES = /* @__PURE__ */ new Set([
1592
+ "ERR_MODULE_NOT_FOUND",
1593
+ "MODULE_NOT_FOUND"
1594
+ ]);
1595
+ function isModuleNotFound(error, moduleName) {
1596
+ const candidate = error;
1597
+ if (typeof candidate?.code !== "string" || !MODULE_NOT_FOUND_CODES.has(candidate.code)) {
1598
+ return false;
1599
+ }
1600
+ return typeof candidate.message === "string" && candidate.message.includes(`'${moduleName}'`);
1601
+ }
1602
+ async function loadOptionalPeer(moduleName) {
1603
+ try {
1604
+ return await import(moduleName);
1605
+ } catch (error) {
1606
+ if (isModuleNotFound(error, moduleName)) {
1607
+ throw new Error(
1608
+ `\`${moduleName}\` package is not installed. Run \`pnpm add ${moduleName}\` in the consumer app.`
1609
+ );
1610
+ }
1611
+ const reason = error instanceof Error ? error.message : String(error);
1612
+ throw new Error(`Failed to load \`${moduleName}\`: ${reason}`, { cause: error });
1613
+ }
1614
+ }
1615
+
1616
+ // src/server/providers/resend-email.provider.ts
1589
1617
  var RESEND_MODULE = "resend";
1590
1618
  var _clientPromise, _options;
1591
1619
  exports.ResendEmailProvider = class ResendEmailProvider {
@@ -1710,17 +1738,12 @@ exports.ResendEmailProvider = class ResendEmailProvider {
1710
1738
  * Dynamically imports the optional `resend` peer dependency.
1711
1739
  *
1712
1740
  * @returns The SDK's `Resend` constructor.
1713
- * @throws Error When the package is not installed in the consumer app.
1741
+ * @throws Error When the package is not installed, or — reported as itself rather
1742
+ * than as a missing package — when the import fails for any other reason.
1714
1743
  */
1715
1744
  async loadResendConstructor() {
1716
- try {
1717
- const mod = await import(RESEND_MODULE);
1718
- return mod.Resend;
1719
- } catch {
1720
- throw new Error(
1721
- "`resend` package is not installed. Run `pnpm add resend` in the consumer app."
1722
- );
1723
- }
1745
+ const mod = await loadOptionalPeer(RESEND_MODULE);
1746
+ return mod.Resend;
1724
1747
  }
1725
1748
  };
1726
1749
  _clientPromise = new WeakMap();
@@ -2077,17 +2100,11 @@ exports.SmtpEmailProvider = class SmtpEmailProvider {
2077
2100
  * a named export, and one where the CommonJS module lands under `default`.
2078
2101
  *
2079
2102
  * @returns The module's callable surface.
2080
- * @throws Error When the package is not installed in the consumer app.
2103
+ * @throws Error When the package is not installed, or — reported as itself rather
2104
+ * than as a missing package — when the import fails for any other reason.
2081
2105
  */
2082
2106
  async loadNodemailer() {
2083
- let mod;
2084
- try {
2085
- mod = await import(NODEMAILER_MODULE);
2086
- } catch {
2087
- throw new Error(
2088
- "`nodemailer` package is not installed. Run `pnpm add nodemailer` in the consumer app."
2089
- );
2090
- }
2107
+ const mod = await loadOptionalPeer(NODEMAILER_MODULE);
2091
2108
  const candidate = mod.createTransport ? mod : mod.default;
2092
2109
  if (!candidate?.createTransport) {
2093
2110
  throw new Error("`nodemailer` package exposes no createTransport export");
@@ -1485,7 +1485,8 @@ declare class ResendEmailProvider implements IEmailProvider {
1485
1485
  * Dynamically imports the optional `resend` peer dependency.
1486
1486
  *
1487
1487
  * @returns The SDK's `Resend` constructor.
1488
- * @throws Error When the package is not installed in the consumer app.
1488
+ * @throws Error When the package is not installed, or — reported as itself rather
1489
+ * than as a missing package — when the import fails for any other reason.
1489
1490
  */
1490
1491
  private loadResendConstructor;
1491
1492
  }
@@ -1798,7 +1799,8 @@ declare class SmtpEmailProvider implements IEmailProvider {
1798
1799
  * a named export, and one where the CommonJS module lands under `default`.
1799
1800
  *
1800
1801
  * @returns The module's callable surface.
1801
- * @throws Error When the package is not installed in the consumer app.
1802
+ * @throws Error When the package is not installed, or — reported as itself rather
1803
+ * than as a missing package — when the import fails for any other reason.
1802
1804
  */
1803
1805
  private loadNodemailer;
1804
1806
  }
@@ -1485,7 +1485,8 @@ declare class ResendEmailProvider implements IEmailProvider {
1485
1485
  * Dynamically imports the optional `resend` peer dependency.
1486
1486
  *
1487
1487
  * @returns The SDK's `Resend` constructor.
1488
- * @throws Error When the package is not installed in the consumer app.
1488
+ * @throws Error When the package is not installed, or — reported as itself rather
1489
+ * than as a missing package — when the import fails for any other reason.
1489
1490
  */
1490
1491
  private loadResendConstructor;
1491
1492
  }
@@ -1798,7 +1799,8 @@ declare class SmtpEmailProvider implements IEmailProvider {
1798
1799
  * a named export, and one where the CommonJS module lands under `default`.
1799
1800
  *
1800
1801
  * @returns The module's callable surface.
1801
- * @throws Error When the package is not installed in the consumer app.
1802
+ * @throws Error When the package is not installed, or — reported as itself rather
1803
+ * than as a missing package — when the import fails for any other reason.
1802
1804
  */
1803
1805
  private loadNodemailer;
1804
1806
  }
@@ -1584,6 +1584,34 @@ var NoOpEmailProvider = class {
1584
1584
  NoOpEmailProvider = __decorateClass([
1585
1585
  Injectable()
1586
1586
  ], NoOpEmailProvider);
1587
+
1588
+ // src/server/utils/load-optional-peer.ts
1589
+ var MODULE_NOT_FOUND_CODES = /* @__PURE__ */ new Set([
1590
+ "ERR_MODULE_NOT_FOUND",
1591
+ "MODULE_NOT_FOUND"
1592
+ ]);
1593
+ function isModuleNotFound(error, moduleName) {
1594
+ const candidate = error;
1595
+ if (typeof candidate?.code !== "string" || !MODULE_NOT_FOUND_CODES.has(candidate.code)) {
1596
+ return false;
1597
+ }
1598
+ return typeof candidate.message === "string" && candidate.message.includes(`'${moduleName}'`);
1599
+ }
1600
+ async function loadOptionalPeer(moduleName) {
1601
+ try {
1602
+ return await import(moduleName);
1603
+ } catch (error) {
1604
+ if (isModuleNotFound(error, moduleName)) {
1605
+ throw new Error(
1606
+ `\`${moduleName}\` package is not installed. Run \`pnpm add ${moduleName}\` in the consumer app.`
1607
+ );
1608
+ }
1609
+ const reason = error instanceof Error ? error.message : String(error);
1610
+ throw new Error(`Failed to load \`${moduleName}\`: ${reason}`, { cause: error });
1611
+ }
1612
+ }
1613
+
1614
+ // src/server/providers/resend-email.provider.ts
1587
1615
  var RESEND_MODULE = "resend";
1588
1616
  var _clientPromise, _options;
1589
1617
  var ResendEmailProvider = class {
@@ -1708,17 +1736,12 @@ var ResendEmailProvider = class {
1708
1736
  * Dynamically imports the optional `resend` peer dependency.
1709
1737
  *
1710
1738
  * @returns The SDK's `Resend` constructor.
1711
- * @throws Error When the package is not installed in the consumer app.
1739
+ * @throws Error When the package is not installed, or — reported as itself rather
1740
+ * than as a missing package — when the import fails for any other reason.
1712
1741
  */
1713
1742
  async loadResendConstructor() {
1714
- try {
1715
- const mod = await import(RESEND_MODULE);
1716
- return mod.Resend;
1717
- } catch {
1718
- throw new Error(
1719
- "`resend` package is not installed. Run `pnpm add resend` in the consumer app."
1720
- );
1721
- }
1743
+ const mod = await loadOptionalPeer(RESEND_MODULE);
1744
+ return mod.Resend;
1722
1745
  }
1723
1746
  };
1724
1747
  _clientPromise = new WeakMap();
@@ -2075,17 +2098,11 @@ var SmtpEmailProvider = class {
2075
2098
  * a named export, and one where the CommonJS module lands under `default`.
2076
2099
  *
2077
2100
  * @returns The module's callable surface.
2078
- * @throws Error When the package is not installed in the consumer app.
2101
+ * @throws Error When the package is not installed, or — reported as itself rather
2102
+ * than as a missing package — when the import fails for any other reason.
2079
2103
  */
2080
2104
  async loadNodemailer() {
2081
- let mod;
2082
- try {
2083
- mod = await import(NODEMAILER_MODULE);
2084
- } catch {
2085
- throw new Error(
2086
- "`nodemailer` package is not installed. Run `pnpm add nodemailer` in the consumer app."
2087
- );
2088
- }
2105
+ const mod = await loadOptionalPeer(NODEMAILER_MODULE);
2089
2106
  const candidate = mod.createTransport ? mod : mod.default;
2090
2107
  if (!candidate?.createTransport) {
2091
2108
  throw new Error("`nodemailer` package exposes no createTransport export");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-notification",
3
- "version": "1.1.1",
3
+ "version": "1.1.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",