@shad0wz7/nestjs-pdf 3.0.1 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -48,6 +48,73 @@ fs = __toESM(fs, 1);
48
48
  let path = require("path");
49
49
  let rxjs = require("rxjs");
50
50
  let crypto = require("crypto");
51
+ //#region src/exceptions/nestjs-pdf.exception.ts
52
+ let NestjsPdfErrorCode = /* @__PURE__ */ function(NestjsPdfErrorCode) {
53
+ NestjsPdfErrorCode["ENGINE_NOT_AVAILABLE"] = "ENGINE_NOT_AVAILABLE";
54
+ NestjsPdfErrorCode["TEMPLATE_CONFIGURATION_ERROR"] = "TEMPLATE_CONFIGURATION_ERROR";
55
+ NestjsPdfErrorCode["TEMPLATE_RENDER_ERROR"] = "TEMPLATE_RENDER_ERROR";
56
+ NestjsPdfErrorCode["BROWSER_INSTALLATION_ERROR"] = "BROWSER_INSTALLATION_ERROR";
57
+ NestjsPdfErrorCode["BROWSER_UNAVAILABLE"] = "BROWSER_UNAVAILABLE";
58
+ NestjsPdfErrorCode["PDF_GENERATION_ERROR"] = "PDF_GENERATION_ERROR";
59
+ NestjsPdfErrorCode["SIGNATURE_DEPENDENCY_ERROR"] = "SIGNATURE_DEPENDENCY_ERROR";
60
+ NestjsPdfErrorCode["SIGNATURE_PLACEMENT_ERROR"] = "SIGNATURE_PLACEMENT_ERROR";
61
+ return NestjsPdfErrorCode;
62
+ }({});
63
+ var NestjsPdfException = class extends Error {
64
+ constructor(message, options) {
65
+ super(message, options);
66
+ this.name = this.constructor.name;
67
+ }
68
+ };
69
+ //#endregion
70
+ //#region src/exceptions/browser-installation.exception.ts
71
+ var BrowserInstallationException = class extends NestjsPdfException {
72
+ code = "BROWSER_INSTALLATION_ERROR";
73
+ };
74
+ //#endregion
75
+ //#region src/exceptions/browser-unavailable.exception.ts
76
+ var BrowserUnavailableException = class extends NestjsPdfException {
77
+ code = "BROWSER_UNAVAILABLE";
78
+ };
79
+ //#endregion
80
+ //#region src/exceptions/engine-not-available.exception.ts
81
+ var EngineNotAvailableException = class extends NestjsPdfException {
82
+ code = "ENGINE_NOT_AVAILABLE";
83
+ constructor(engineName) {
84
+ super(`${engineName} service is not available. If the problem persists, open an issue in the repo.`);
85
+ }
86
+ };
87
+ //#endregion
88
+ //#region src/exceptions/pdf-generation.exception.ts
89
+ var PdfGenerationException = class extends NestjsPdfException {
90
+ code = "PDF_GENERATION_ERROR";
91
+ };
92
+ //#endregion
93
+ //#region src/exceptions/signature-dependency.exception.ts
94
+ var SignatureDependencyException = class extends NestjsPdfException {
95
+ code = "SIGNATURE_DEPENDENCY_ERROR";
96
+ };
97
+ //#endregion
98
+ //#region src/exceptions/signature-placement.exception.ts
99
+ var SignaturePlacementException = class extends NestjsPdfException {
100
+ code = "SIGNATURE_PLACEMENT_ERROR";
101
+ };
102
+ //#endregion
103
+ //#region src/exceptions/template-configuration.exception.ts
104
+ var TemplateConfigurationException = class extends NestjsPdfException {
105
+ code = "TEMPLATE_CONFIGURATION_ERROR";
106
+ };
107
+ //#endregion
108
+ //#region src/exceptions/template-render.exception.ts
109
+ var TemplateRenderException = class extends NestjsPdfException {
110
+ engine;
111
+ code = "TEMPLATE_RENDER_ERROR";
112
+ constructor(engine, message, options) {
113
+ super(message, options);
114
+ this.engine = engine;
115
+ }
116
+ };
117
+ //#endregion
51
118
  //#region src/helpers/getRelativePath.helper.ts
52
119
  /**
53
120
  * Get the relative path to a value from the module directory.
@@ -70,14 +137,12 @@ async function loadPdfjs() {
70
137
  pdfjsPromise = await import("pdfjs-dist/legacy/build/pdf.mjs");
71
138
  } catch (error) {
72
139
  pdfjsPromise = void 0;
73
- /* v8 ignore next -- import() rejections are always Error instances in practice */
74
- const reason = error instanceof Error ? error.message : String(error);
75
- throw new Error([
140
+ throw new SignatureDependencyException([
76
141
  "Failed to load pdfjs-dist.",
77
142
  "If you use anchor-based signature placement in Node.js, make sure @napi-rs/canvas is installed.",
78
143
  "Try: npm install @napi-rs/canvas",
79
144
  "",
80
- `Original error: ${reason}`
145
+ `Original error: ${error instanceof Error ? error.message : String(error)}`
81
146
  ].join("\n"), { cause: error });
82
147
  }
83
148
  return pdfjsPromise;
@@ -175,7 +240,7 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
175
240
  if (anchor) {
176
241
  const pageIndex = anchor.pageIndex;
177
242
  const page = pdfDoc.getPages()[pageIndex];
178
- if (!page) throw new Error(`Page ${pageIndex} not found`);
243
+ if (!page) throw new SignaturePlacementException(`Page ${pageIndex} not found`);
179
244
  const { width: pw, height: ph } = page.getSize();
180
245
  const padX = 40;
181
246
  const padY = 7;
@@ -196,7 +261,7 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
196
261
  const pageIndex = pages.length - 1;
197
262
  const page = pages.at(-1);
198
263
  /* v8 ignore next -- pdf-lib always produces at least one page on save/load; only a hand-crafted, malformed PDF could hit this */
199
- if (!page) throw new Error(`Page ${pageIndex} not found`);
264
+ if (!page) throw new SignaturePlacementException(`Page ${pageIndex} not found`);
200
265
  const { width: pageWidth } = page.getSize();
201
266
  addSignatureFieldAt(pdfDoc, pageIndex, {
202
267
  fieldName,
@@ -387,47 +452,47 @@ function isTargetClosedError(error) {
387
452
  return error.name === "TargetCloseError" || error.message.includes("Target closed") || error.message.includes("Target.createTarget");
388
453
  }
389
454
  let BrowserService = class BrowserService {
390
- cacheDir;
391
- options;
392
- _browserInstance = null;
393
- browser;
455
+ #cacheDir;
456
+ #options;
457
+ #browserInstance = null;
458
+ #browser;
394
459
  activeJobs = 0;
395
460
  totalJobs = 0;
396
- recycleRequested = false;
397
- recycling = false;
398
- shuttingDown = false;
461
+ #recycleRequested = false;
462
+ #recycling = false;
463
+ #shuttingDown = false;
399
464
  /** Max time to wait for in-flight PDF jobs to finish before closing the browser on shutdown. */
400
465
  shutdownDrainTimeoutMs = 15e3;
401
- browserTag;
402
- useLockedBrowser;
403
- buildId;
466
+ #browserTag;
467
+ #useLockedBrowser;
468
+ #buildId;
404
469
  constructor(pdfParams) {
405
- this.cacheDir = (0, node_path.resolve)(".cache/puppeteer-browser");
406
- this.options = pdfParams;
407
- this.loadBuildId();
408
- this.loadBrowser();
409
- this.loadBrowserTag();
410
- this.loadUseLockedBrowser();
470
+ this.#cacheDir = (0, node_path.resolve)(".cache/puppeteer-browser");
471
+ this.#options = pdfParams;
472
+ this.#loadBuildId();
473
+ this.#loadBrowser();
474
+ this.#loadBrowserTag();
475
+ this.#loadUseLockedBrowser();
411
476
  }
412
477
  async onModuleDestroy() {
413
- this.shuttingDown = true;
414
- await this.waitForIdle(this.shutdownDrainTimeoutMs);
415
- if (this._browserInstance?.connected) try {
416
- await this._browserInstance.close();
478
+ this.#shuttingDown = true;
479
+ await this.#waitForIdle(this.shutdownDrainTimeoutMs);
480
+ if (this.#browserInstance?.connected) try {
481
+ await this.#browserInstance.close();
417
482
  } catch (error) {
418
483
  _nestjs_common.Logger.warn(`Failed to close browser on module destroy: ${error instanceof Error ? error.message : String(error)}`);
419
484
  }
420
- if (this.options?.cleanupBrowserCacheOnExit !== false) await this.cleanupCacheBestEffort();
485
+ if (this.#options?.cleanupBrowserCacheOnExit !== false) await this.#cleanupCacheBestEffort();
421
486
  }
422
487
  /** Wait until no PDF job is in flight, or until the timeout elapses. */
423
- async waitForIdle(timeoutMs) {
488
+ async #waitForIdle(timeoutMs) {
424
489
  const start = Date.now();
425
490
  while (this.activeJobs > 0 && Date.now() - start < timeoutMs) await sleep(50);
426
491
  if (this.activeJobs > 0) _nestjs_common.Logger.warn(`Shutdown: ${this.activeJobs} PDF job(s) still running after ${timeoutMs}ms, closing the browser anyway`);
427
492
  }
428
493
  async getBrowserInstance(args, headless, executablePathBin) {
429
- if (!this._browserInstance?.connected) this._browserInstance = await this.launchBrowser(args, headless, executablePathBin);
430
- return this._browserInstance;
494
+ if (!this.#browserInstance?.connected) this.#browserInstance = await this.#launchBrowser(args, headless, executablePathBin);
495
+ return this.#browserInstance;
431
496
  }
432
497
  async createContext(args, headless, executablePath) {
433
498
  const browser = await this.getBrowserInstance(args, headless, executablePath);
@@ -436,41 +501,41 @@ let BrowserService = class BrowserService {
436
501
  } catch (error) {
437
502
  if (!isTargetClosedError(error)) throw error;
438
503
  _nestjs_common.Logger.warn("Puppeteer browser closed while creating a context, retrying once");
439
- this._browserInstance = null;
504
+ this.#browserInstance = null;
440
505
  return await (await this.getBrowserInstance(args, headless, executablePath)).createBrowserContext();
441
506
  }
442
507
  }
443
508
  markJobStarted() {
444
- if (this.shuttingDown) throw new Error("nestjs-pdf is shutting down, refusing new PDF jobs");
509
+ if (this.#shuttingDown) throw new BrowserUnavailableException("nestjs-pdf is shutting down, refusing new PDF jobs");
445
510
  this.activeJobs += 1;
446
511
  this.totalJobs += 1;
447
- if (this.totalJobs >= 200) this.recycleRequested = true;
512
+ if (this.totalJobs >= 200) this.#recycleRequested = true;
448
513
  }
449
514
  async markJobFinished() {
450
515
  this.activeJobs = Math.max(0, this.activeJobs - 1);
451
516
  await this.recycleBrowserIfNeeded();
452
517
  }
453
518
  async recycleBrowserIfNeeded() {
454
- if (!this.recycleRequested) return;
455
- if (this.recycling) return;
519
+ if (!this.#recycleRequested) return;
520
+ if (this.#recycling) return;
456
521
  if (this.activeJobs > 0) return;
457
- if (!this._browserInstance) return;
458
- this.recycling = true;
522
+ if (!this.#browserInstance) return;
523
+ this.#recycling = true;
459
524
  try {
460
- if (this._browserInstance.connected) await this._browserInstance.close();
461
- this._browserInstance = null;
525
+ if (this.#browserInstance.connected) await this.#browserInstance.close();
526
+ this.#browserInstance = null;
462
527
  this.totalJobs = 0;
463
- this.recycleRequested = false;
528
+ this.#recycleRequested = false;
464
529
  _nestjs_common.Logger.log("Puppeteer browser recycled successfully");
465
530
  } catch (error) {
466
531
  _nestjs_common.Logger.warn(`Failed to recycle browser: ${error instanceof Error ? error.message : String(error)}`);
467
532
  } finally {
468
- this.recycling = false;
533
+ this.#recycling = false;
469
534
  }
470
535
  }
471
- async cleanupCacheBestEffort() {
536
+ async #cleanupCacheBestEffort() {
472
537
  const logger = new _nestjs_common.Logger("NestJsPdf");
473
- const dir = this.cacheDir;
538
+ const dir = this.#cacheDir;
474
539
  try {
475
540
  if (!(0, node_fs.existsSync)(dir)) return;
476
541
  logger.log(`Cleanup puppeteer cache: ${dir}`);
@@ -491,101 +556,109 @@ let BrowserService = class BrowserService {
491
556
  }
492
557
  }
493
558
  async install(lock = false) {
494
- const browser = this.browser;
495
- const versionTag = this.browserTag;
559
+ try {
560
+ return await this.#doInstall(lock);
561
+ } catch (error) {
562
+ if (error instanceof NestjsPdfException) throw error;
563
+ throw new BrowserInstallationException(`Could not install browser: ${String(error)}`, { cause: error });
564
+ }
565
+ }
566
+ async #doInstall(lock) {
567
+ const browser = this.#browser;
568
+ const versionTag = this.#browserTag;
496
569
  const browserPlatform = (0, _puppeteer_browsers.detectBrowserPlatform)() ?? _puppeteer_browsers.BrowserPlatform.LINUX;
497
570
  let buildId;
498
- if (this.buildId === void 0) buildId = await (0, _puppeteer_browsers.resolveBuildId)(browser, browserPlatform, versionTag);
499
- else buildId = this.buildId;
571
+ if (this.#buildId === void 0) buildId = await (0, _puppeteer_browsers.resolveBuildId)(browser, browserPlatform, versionTag);
572
+ else buildId = this.#buildId;
500
573
  _nestjs_common.Logger.log(`Browser ${browser} ${versionTag} build id: ${buildId}`, "NestJsPdf");
501
574
  if (await this.hasBrowserInstalled(browser, buildId)) {
502
575
  _nestjs_common.Logger.log("Browser already installed", "NestJsPdf");
503
- if (lock) this.writeLockFile(browser, buildId);
576
+ if (lock) this.#writeLockFile(browser, buildId);
504
577
  return;
505
578
  } else {
506
579
  _nestjs_common.Logger.log("Starting browser installation", "NestJsPdf");
507
580
  const installOption = {
508
- cacheDir: this.cacheDir,
581
+ cacheDir: this.#cacheDir,
509
582
  browser,
510
583
  buildId,
511
- baseUrl: this.options?.browserInstallBaseUrl ?? void 0
584
+ baseUrl: this.#options?.browserInstallBaseUrl ?? void 0
512
585
  };
513
586
  if (await (0, _puppeteer_browsers.canDownload)(installOption)) {
514
587
  _nestjs_common.Logger.log(`Installing ${installOption.browser} ${installOption.buildId}`, "NestJsPdf");
515
588
  const installedBrowser = await (0, _puppeteer_browsers.install)(installOption);
516
589
  if (await this.hasBrowserInstalled(browser, buildId)) {
517
590
  _nestjs_common.Logger.log("Browser installed successfully", "NestJsPdf");
518
- if (lock) this.writeLockFile(browser, buildId);
591
+ if (lock) this.#writeLockFile(browser, buildId);
519
592
  return installedBrowser;
520
593
  } else _nestjs_common.Logger.error("Browser installation failed", "NestJsPdf");
521
594
  } else _nestjs_common.Logger.error(`Error, can't install ${installOption.browser} ${installOption.buildId}`, "NestJsPdf");
522
595
  }
523
596
  return null;
524
597
  }
525
- loadBrowser() {
598
+ #loadBrowser() {
526
599
  let browser;
527
- if (this.options?.browser === void 0) browser = _puppeteer_browsers.Browser.CHROMIUM;
528
- else browser = this.options.browser;
529
- this.browser = browser;
600
+ if (this.#options?.browser === void 0) browser = _puppeteer_browsers.Browser.CHROMIUM;
601
+ else browser = this.#options.browser;
602
+ this.#browser = browser;
530
603
  }
531
604
  getBrowser() {
532
- return this.browser;
605
+ return this.#browser;
533
606
  }
534
- loadBrowserTag() {
607
+ #loadBrowserTag() {
535
608
  let versionTag;
536
- if (this.options?.browserTag === void 0) {
537
- if (this.browser === _puppeteer_browsers.Browser.CHROMIUM) versionTag = "latest";
609
+ if (this.#options?.browserTag === void 0) {
610
+ if (this.#browser === _puppeteer_browsers.Browser.CHROMIUM) versionTag = "latest";
538
611
  else versionTag = "stable";
539
- } else versionTag = this.options.browserTag;
540
- this.browserTag = versionTag;
612
+ } else versionTag = this.#options.browserTag;
613
+ this.#browserTag = versionTag;
541
614
  }
542
- loadBuildId() {
615
+ #loadBuildId() {
543
616
  let buildId;
544
- if (this.options?.buildId === void 0) buildId = void 0;
545
- else buildId = this.options.buildId;
546
- this.buildId = buildId;
617
+ if (this.#options?.buildId === void 0) buildId = void 0;
618
+ else buildId = this.#options.buildId;
619
+ this.#buildId = buildId;
547
620
  }
548
621
  setBrowserTag(browserTag) {
549
- this.browserTag = browserTag;
622
+ this.#browserTag = browserTag;
550
623
  }
551
624
  getBrowserTag() {
552
- return this.browserTag;
625
+ return this.#browserTag;
553
626
  }
554
627
  getBuildId() {
555
- return this.buildId;
628
+ return this.#buildId;
556
629
  }
557
- loadUseLockedBrowser() {
630
+ #loadUseLockedBrowser() {
558
631
  let useLockedBrowser;
559
- if (this.options?.useLockedBrowser === void 0) useLockedBrowser = false;
560
- else useLockedBrowser = this.options.useLockedBrowser;
561
- this.useLockedBrowser = useLockedBrowser;
632
+ if (this.#options?.useLockedBrowser === void 0) useLockedBrowser = false;
633
+ else useLockedBrowser = this.#options.useLockedBrowser;
634
+ this.#useLockedBrowser = useLockedBrowser;
562
635
  }
563
636
  async hasBrowserInstalled(browser, buildId) {
564
- return (await (0, _puppeteer_browsers.getInstalledBrowsers)({ cacheDir: this.cacheDir })).find((insBrowser) => {
637
+ return (await (0, _puppeteer_browsers.getInstalledBrowsers)({ cacheDir: this.#cacheDir })).find((insBrowser) => {
565
638
  return insBrowser.browser === browser && insBrowser.buildId === buildId;
566
639
  }) !== void 0;
567
640
  }
568
641
  async getExecutablePath() {
569
- const browser = this.browser;
570
- const versionTag = this.browserTag;
642
+ const browser = this.#browser;
643
+ const versionTag = this.#browserTag;
571
644
  const browserPlatform = (0, _puppeteer_browsers.detectBrowserPlatform)() ?? _puppeteer_browsers.BrowserPlatform.LINUX;
572
645
  let buildId = null;
573
- if (this.useLockedBrowser) {
646
+ if (this.#useLockedBrowser) {
574
647
  buildId = this.getLockedBuildId(browser);
575
648
  _nestjs_common.Logger.log(`Using locked browser ${buildId}`, "NestJsPdf");
576
649
  }
577
650
  buildId ??= await (0, _puppeteer_browsers.resolveBuildId)(browser, browserPlatform, versionTag);
578
- const installedBrowser = (await (0, _puppeteer_browsers.getInstalledBrowsers)({ cacheDir: this.cacheDir })).find((insBrowser) => {
651
+ const installedBrowser = (await (0, _puppeteer_browsers.getInstalledBrowsers)({ cacheDir: this.#cacheDir })).find((insBrowser) => {
579
652
  return insBrowser.browser === browser && insBrowser.buildId === buildId;
580
653
  });
581
654
  if (installedBrowser === void 0) {
582
655
  const newinstalledBrowser = await this.install();
583
- if (newinstalledBrowser === null || newinstalledBrowser === void 0) throw new Error("Could not install browser");
656
+ if (newinstalledBrowser === null || newinstalledBrowser === void 0) throw new BrowserInstallationException("Could not install browser");
584
657
  else return newinstalledBrowser.executablePath;
585
658
  }
586
659
  return installedBrowser.executablePath;
587
660
  }
588
- async launchBrowser(args, headless, executablePathBin) {
661
+ async #launchBrowser(args, headless, executablePathBin) {
589
662
  const executablePath = executablePathBin ?? await this.getExecutablePath();
590
663
  const browser = await (0, puppeteer.launch)({
591
664
  executablePath,
@@ -594,12 +667,12 @@ let BrowserService = class BrowserService {
594
667
  });
595
668
  browser.on("disconnected", () => {
596
669
  _nestjs_common.Logger.warn("Puppeteer browser disconnected");
597
- if (this._browserInstance === browser) this._browserInstance = null;
670
+ if (this.#browserInstance === browser) this.#browserInstance = null;
598
671
  });
599
672
  return browser;
600
673
  }
601
- writeLockFile(browser, buildId) {
602
- const lockFile = (0, node_path.resolve)(this.cacheDir, `${browser}.lock`);
674
+ #writeLockFile(browser, buildId) {
675
+ const lockFile = (0, node_path.resolve)(this.#cacheDir, `${browser}.lock`);
603
676
  const data = JSON.stringify({
604
677
  browser,
605
678
  buildId,
@@ -609,7 +682,7 @@ let BrowserService = class BrowserService {
609
682
  _nestjs_common.Logger.log(`Browser ${browser} locked to build ${buildId}`, "NestJsPdf");
610
683
  }
611
684
  getLockedBuildId(browser) {
612
- const lockFile = (0, node_path.resolve)(this.cacheDir, `${browser}.lock`);
685
+ const lockFile = (0, node_path.resolve)(this.#cacheDir, `${browser}.lock`);
613
686
  if ((0, node_fs.existsSync)(lockFile)) {
614
687
  const data = (0, node_fs.readFileSync)(lockFile);
615
688
  return JSON.parse(data.toString()).buildId;
@@ -632,7 +705,7 @@ let EjsService = class EjsService {
632
705
  ...options
633
706
  });
634
707
  } catch (error) {
635
- throw new Error(`EJS rendering failed: ${String(error)}`, { cause: error });
708
+ throw new TemplateRenderException("EJS", `EJS rendering failed: ${String(error)}`, { cause: error });
636
709
  }
637
710
  }
638
711
  async renderFile(filePath, data = {}, options) {
@@ -642,7 +715,7 @@ let EjsService = class EjsService {
642
715
  ...options
643
716
  });
644
717
  } catch (error) {
645
- throw new Error(`EJS file rendering failed: ${String(error)}`, { cause: error });
718
+ throw new TemplateRenderException("EJS", `EJS file rendering failed: ${String(error)}`, { cause: error });
646
719
  }
647
720
  }
648
721
  };
@@ -650,11 +723,11 @@ EjsService = __decorate$3([(0, _nestjs_common.Injectable)()], EjsService);
650
723
  //#endregion
651
724
  //#region src/puppeteer/engines/eta/eta.service.ts
652
725
  let EtaService = class EtaService {
653
- eta;
654
- templateCache = /* @__PURE__ */ new Map();
655
- maxCacheSize = 100;
726
+ #eta;
727
+ #templateCache = /* @__PURE__ */ new Map();
728
+ #maxCacheSize = 100;
656
729
  constructor() {
657
- this.eta = new eta.Eta({
730
+ this.#eta = new eta.Eta({
658
731
  cache: true,
659
732
  autoEscape: true,
660
733
  useWith: true
@@ -675,9 +748,9 @@ let EtaService = class EtaService {
675
748
  useWith: true,
676
749
  ...options,
677
750
  varName: options.varName ?? "it"
678
- }) : this.eta).renderString(template, data);
751
+ }) : this.#eta).renderString(template, data);
679
752
  } catch (error) {
680
- throw new Error(`Eta rendering failed: ${String(error)}`, { cause: error });
753
+ throw new TemplateRenderException("Eta", `Eta rendering failed: ${String(error)}`, { cause: error });
681
754
  }
682
755
  }
683
756
  /**
@@ -691,53 +764,54 @@ let EtaService = class EtaService {
691
764
  try {
692
765
  const resolvedPath = (0, node_path.resolve)(filePath);
693
766
  const useCache = options?.cache ?? true;
694
- let template = useCache ? this.templateCache.get(resolvedPath) : void 0;
767
+ let template = useCache ? this.#templateCache.get(resolvedPath) : void 0;
695
768
  if (!template) {
696
769
  template = (0, node_fs.readFileSync)(resolvedPath, "utf-8");
697
- if (useCache && this.templateCache.size < this.maxCacheSize) this.templateCache.set(resolvedPath, template);
770
+ if (useCache && this.#templateCache.size < this.#maxCacheSize) this.#templateCache.set(resolvedPath, template);
698
771
  }
699
772
  return this.render(template, data, options);
700
773
  } catch (error) {
701
- throw new Error(`Eta file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
774
+ throw new TemplateRenderException("Eta", `Eta file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
702
775
  }
703
776
  }
704
777
  /**
705
778
  * Clear the template cache
706
779
  */
707
780
  clearCache() {
708
- this.templateCache.clear();
781
+ this.#templateCache.clear();
709
782
  }
710
783
  /**
711
784
  * Get the current cache size
712
785
  * @returns The number of cached templates
713
786
  */
714
787
  getCacheSize() {
715
- return this.templateCache.size;
788
+ return this.#templateCache.size;
716
789
  }
717
790
  };
718
791
  EtaService = __decorate$3([(0, _nestjs_common.Injectable)(), __decorateMetadata("design:paramtypes", [])], EtaService);
719
792
  //#endregion
720
793
  //#region src/puppeteer/engines/handlebars/handlebars.service.ts
721
794
  let HandlebarsService = class HandlebarsService {
722
- cachedOptions;
723
- cachedEnv;
795
+ #cachedOptions;
796
+ #cachedEnv;
724
797
  render(template, parameters = {}, options = {}) {
725
798
  try {
726
- return this.getEnv(options).compile(template, options.compileOptions)(parameters, options.templateOptions);
799
+ return this.#getEnv(options).compile(template, options.compileOptions)(parameters, options.templateOptions);
727
800
  } catch (error) {
728
- throw new Error(`Handlebars rendering failed: ${String(error)}`, { cause: error });
801
+ if (error instanceof NestjsPdfException) throw error;
802
+ throw new TemplateRenderException("Handlebars", `Handlebars rendering failed: ${String(error)}`, { cause: error });
729
803
  }
730
804
  }
731
805
  renderFile(file, parameters = {}, options = {}) {
732
- if (options.templateDirectory === void 0) throw new Error("Handlebars file rendering failed: option `templateDirectory` is not set");
806
+ if (options.templateDirectory === void 0) throw new TemplateConfigurationException("Handlebars file rendering failed: option `templateDirectory` is not set");
733
807
  const baseDir = (0, node_path.resolve)(process.cwd(), options.templateDirectory);
734
808
  const templatePath = (0, node_path.resolve)(baseDir, file);
735
- if (templatePath !== baseDir && !templatePath.startsWith(baseDir + node_path.sep)) throw new Error(`Handlebars file rendering failed: ’${file}’ resolves outside \`templateDirectory\``);
809
+ if (templatePath !== baseDir && !templatePath.startsWith(baseDir + node_path.sep)) throw new TemplateConfigurationException(`Handlebars file rendering failed: ’${file}’ resolves outside \`templateDirectory\``);
736
810
  let template;
737
811
  try {
738
812
  template = (0, node_fs.readFileSync)(templatePath, "utf8");
739
813
  } catch (error) {
740
- throw new Error(`Handlebars file rendering failed: ${String(error)}`, { cause: error });
814
+ throw new TemplateRenderException("Handlebars", `Handlebars file rendering failed: ${String(error)}`, { cause: error });
741
815
  }
742
816
  return this.render(template, parameters, options);
743
817
  }
@@ -746,19 +820,19 @@ let HandlebarsService = class HandlebarsService {
746
820
  * nothing leaks into the global Handlebars. Memoised for the common case where
747
821
  * the same options object is reused across calls (e.g. the module `hbsOptions`).
748
822
  */
749
- getEnv(options) {
750
- if (this.cachedEnv && this.cachedOptions === options) return this.cachedEnv;
823
+ #getEnv(options) {
824
+ if (this.#cachedEnv && this.#cachedOptions === options) return this.#cachedEnv;
751
825
  const env = handlebars.default.create();
752
826
  for (const helper of options.helpers ?? []) env.registerHelper(helper.name, helper.fn);
753
- this.registerPartials(env, options.partialDirectory);
754
- this.cachedOptions = options;
755
- this.cachedEnv = env;
827
+ this.#registerPartials(env, options.partialDirectory);
828
+ this.#cachedOptions = options;
829
+ this.#cachedEnv = env;
756
830
  return env;
757
831
  }
758
- registerPartials(env, partialDirectory) {
832
+ #registerPartials(env, partialDirectory) {
759
833
  if (partialDirectory === void 0) return;
760
834
  const partialPath = (0, node_path.join)(process.cwd(), partialDirectory);
761
- if (!(0, node_fs.existsSync)(partialPath)) throw new Error(`Handlebars partial directory does not exist: ${partialPath}`);
835
+ if (!(0, node_fs.existsSync)(partialPath)) throw new TemplateConfigurationException(`Handlebars partial directory does not exist: ${partialPath}`);
762
836
  for (const entry of (0, node_fs.readdirSync)(partialPath)) {
763
837
  const filePath = (0, node_path.join)(partialPath, entry);
764
838
  if (!(0, node_fs.statSync)(filePath).isFile()) continue;
@@ -771,11 +845,20 @@ HandlebarsService = __decorate$3([(0, _nestjs_common.Injectable)()], HandlebarsS
771
845
  //#region src/puppeteer/engines/mjml/mjml.service.ts
772
846
  let MjmlService = class MjmlService {
773
847
  async render(template, options) {
774
- const { html } = await (0, mjml.default)(template, options);
775
- return html;
848
+ try {
849
+ const { html } = await (0, mjml.default)(template, options);
850
+ return html;
851
+ } catch (error) {
852
+ throw new TemplateRenderException("MJML", `MJML rendering failed: ${String(error)}`, { cause: error });
853
+ }
776
854
  }
777
855
  async renderFile(filePath, options) {
778
- const template = (0, node_fs.readFileSync)(filePath, "utf-8");
856
+ let template;
857
+ try {
858
+ template = (0, node_fs.readFileSync)(filePath, "utf-8");
859
+ } catch (error) {
860
+ throw new TemplateRenderException("MJML", `MJML file rendering failed: ${String(error)}`, { cause: error });
861
+ }
779
862
  return await this.render(template, options);
780
863
  }
781
864
  };
@@ -783,8 +866,8 @@ MjmlService = __decorate$3([(0, _nestjs_common.Injectable)()], MjmlService);
783
866
  //#endregion
784
867
  //#region src/puppeteer/engines/mustache/mustache.service.ts
785
868
  let MustacheService = class MustacheService {
786
- templateCache = /* @__PURE__ */ new Map();
787
- maxCacheSize = 100;
869
+ #templateCache = /* @__PURE__ */ new Map();
870
+ #maxCacheSize = 100;
788
871
  /**
789
872
  * Render a Mustache template from a string
790
873
  * @param template The template string to render
@@ -800,7 +883,7 @@ let MustacheService = class MustacheService {
800
883
  escape: options?.escape
801
884
  });
802
885
  } catch (error) {
803
- throw new Error(`Mustache rendering failed: ${String(error)}`, { cause: error });
886
+ throw new TemplateRenderException("Mustache", `Mustache rendering failed: ${String(error)}`, { cause: error });
804
887
  }
805
888
  }
806
889
  /**
@@ -813,28 +896,28 @@ let MustacheService = class MustacheService {
813
896
  renderFile(filePath, data = {}, options) {
814
897
  try {
815
898
  const resolvedPath = (0, node_path.resolve)(filePath);
816
- let template = this.templateCache.get(resolvedPath);
899
+ let template = this.#templateCache.get(resolvedPath);
817
900
  if (!template) {
818
901
  template = (0, node_fs.readFileSync)(resolvedPath, "utf-8");
819
- if (this.templateCache.size < this.maxCacheSize) this.templateCache.set(resolvedPath, template);
902
+ if (this.#templateCache.size < this.#maxCacheSize) this.#templateCache.set(resolvedPath, template);
820
903
  }
821
904
  return this.render(template, data, options);
822
905
  } catch (error) {
823
- throw new Error(`Mustache file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
906
+ throw new TemplateRenderException("Mustache", `Mustache file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
824
907
  }
825
908
  }
826
909
  /**
827
910
  * Clear the template cache
828
911
  */
829
912
  clearCache() {
830
- this.templateCache.clear();
913
+ this.#templateCache.clear();
831
914
  }
832
915
  /**
833
916
  * Get the current cache size
834
917
  * @returns The number of cached templates
835
918
  */
836
919
  getCacheSize() {
837
- return this.templateCache.size;
920
+ return this.#templateCache.size;
838
921
  }
839
922
  };
840
923
  MustacheService = __decorate$3([(0, _nestjs_common.Injectable)()], MustacheService);
@@ -862,7 +945,7 @@ let NunjucksService = class NunjucksService {
862
945
  }
863
946
  return nunjucks.default.renderString(template, data);
864
947
  } catch (error) {
865
- throw new Error(`Nunjucks rendering failed: ${String(error)}`, { cause: error });
948
+ throw new TemplateRenderException("Nunjucks", `Nunjucks rendering failed: ${String(error)}`, { cause: error });
866
949
  }
867
950
  }
868
951
  renderFile(filePath, data = {}, options) {
@@ -879,7 +962,7 @@ let NunjucksService = class NunjucksService {
879
962
  }
880
963
  return nunjucks.default.render(filePath, data);
881
964
  } catch (error) {
882
- throw new Error(`Nunjucks file rendering failed: ${String(error)}`, { cause: error });
965
+ throw new TemplateRenderException("Nunjucks", `Nunjucks file rendering failed: ${String(error)}`, { cause: error });
883
966
  }
884
967
  }
885
968
  };
@@ -891,7 +974,7 @@ let PugService = class PugService {
891
974
  try {
892
975
  return pug.default.compile(template, { ...options })(data);
893
976
  } catch (error) {
894
- throw new Error(`Pug rendering failed: ${String(error)}`, { cause: error });
977
+ throw new TemplateRenderException("Pug", `Pug rendering failed: ${String(error)}`, { cause: error });
895
978
  }
896
979
  }
897
980
  renderFile(filePath, data = {}, options) {
@@ -899,7 +982,7 @@ let PugService = class PugService {
899
982
  const template = (0, node_fs.readFileSync)(filePath, "utf-8");
900
983
  return this.render(template, data, options);
901
984
  } catch (error) {
902
- throw new Error(`Pug file rendering failed: ${String(error)}`, { cause: error });
985
+ throw new TemplateRenderException("Pug", `Pug file rendering failed: ${String(error)}`, { cause: error });
903
986
  }
904
987
  }
905
988
  };
@@ -907,36 +990,36 @@ PugService = __decorate$3([(0, _nestjs_common.Injectable)()], PugService);
907
990
  //#endregion
908
991
  //#region src/puppeteer/libs/requireService.utils.ts
909
992
  function requireService(service, name) {
910
- if (!service) throw new Error(`${name} service is not available. If the problem persists, open an issue in the repo.`);
993
+ if (!service) throw new EngineNotAvailableException(name);
911
994
  return service;
912
995
  }
913
996
  //#endregion
914
997
  //#region src/puppeteer/puppeteer.service.ts
915
998
  let PuppeteerService = class PuppeteerService {
916
- browserService;
917
- options;
918
- hbsService;
919
- mjmlService;
920
- pugService;
921
- ejsService;
922
- nunjucksService;
923
- etaService;
924
- mustacheService;
999
+ #browserService;
1000
+ #options;
1001
+ #hbsService;
1002
+ #mjmlService;
1003
+ #pugService;
1004
+ #ejsService;
1005
+ #nunjucksService;
1006
+ #etaService;
1007
+ #mustacheService;
925
1008
  constructor(browserService, options, hbsService, mjmlService, pugService, ejsService, nunjucksService, etaService, mustacheService) {
926
- this.browserService = browserService;
927
- this.options = options;
928
- this.hbsService = hbsService;
929
- this.mjmlService = mjmlService;
930
- this.pugService = pugService;
931
- this.ejsService = ejsService;
932
- this.nunjucksService = nunjucksService;
933
- this.etaService = etaService;
934
- this.mustacheService = mustacheService;
935
- }
936
- limit = pLimit(3);
1009
+ this.#browserService = browserService;
1010
+ this.#options = options;
1011
+ this.#hbsService = hbsService;
1012
+ this.#mjmlService = mjmlService;
1013
+ this.#pugService = pugService;
1014
+ this.#ejsService = ejsService;
1015
+ this.#nunjucksService = nunjucksService;
1016
+ this.#etaService = etaService;
1017
+ this.#mustacheService = mustacheService;
1018
+ }
1019
+ #limit = pLimit(3);
937
1020
  async generatePdfFromHtml(html, options) {
938
- return this.limit(async () => {
939
- const mergePuppeteerOptions = mergePuppeteerParameters(this.options, options);
1021
+ return this.#limit(async () => {
1022
+ const mergePuppeteerOptions = mergePuppeteerParameters(this.#options, options);
940
1023
  if (mergePuppeteerOptions.chromiumRevision !== void 0) _nestjs_common.Logger.warn("Using `chromiumRevision` is no longer supported since the puppeteer update.");
941
1024
  const headless = mergePuppeteerOptions.headless ?? true;
942
1025
  const executablePath = mergePuppeteerOptions.executablePath || void 0;
@@ -978,10 +1061,10 @@ let PuppeteerService = class PuppeteerService {
978
1061
  "--no-zygote",
979
1062
  "--disable-gpu"
980
1063
  ];
981
- this.browserService.markJobStarted();
1064
+ this.#browserService.markJobStarted();
982
1065
  let context = null;
983
1066
  try {
984
- context = await this.browserService.createContext(args, headless, executablePath);
1067
+ context = await this.#browserService.createContext(args, headless, executablePath);
985
1068
  const page = await context.newPage();
986
1069
  const pdfOptions = mergePuppeteerOptions.pdfOptions ?? { format: "A4" };
987
1070
  await page.setContent(html, { waitUntil: "domcontentloaded" });
@@ -995,71 +1078,72 @@ let PuppeteerService = class PuppeteerService {
995
1078
  return await page.pdf(pdfOptions);
996
1079
  } catch (e) {
997
1080
  _nestjs_common.Logger.error(e);
998
- throw e;
1081
+ if (e instanceof NestjsPdfException) throw e;
1082
+ throw new PdfGenerationException(`PDF generation failed: ${String(e)}`, { cause: e });
999
1083
  } finally {
1000
1084
  if (context) try {
1001
1085
  await context.close();
1002
1086
  } catch (error) {
1003
1087
  _nestjs_common.Logger.error(error);
1004
1088
  }
1005
- await this.browserService.markJobFinished();
1089
+ await this.#browserService.markJobFinished();
1006
1090
  }
1007
1091
  });
1008
1092
  }
1009
1093
  async generatePdfFromTemplateHbsString(template, parameters = {}, options) {
1010
- const html = requireService(this.hbsService, "Handlebars").render(template, parameters, options?.hbsOptions ?? this.options.hbsOptions);
1094
+ const html = requireService(this.#hbsService, "Handlebars").render(template, parameters, options?.hbsOptions ?? this.#options.hbsOptions);
1011
1095
  return this.generatePdfFromHtml(html, options);
1012
1096
  }
1013
1097
  async generatePdfFromTemplateHbsFile(file, parameters = {}, options) {
1014
- const html = requireService(this.hbsService, "Handlebars").renderFile(file, parameters, options?.hbsOptions ?? this.options.hbsOptions);
1098
+ const html = requireService(this.#hbsService, "Handlebars").renderFile(file, parameters, options?.hbsOptions ?? this.#options.hbsOptions);
1015
1099
  return this.generatePdfFromHtml(html, options);
1016
1100
  }
1017
1101
  async generatePdfFromMjmlString(template, options) {
1018
- const html = await requireService(this.mjmlService, "MJML").render(template, options?.mjmlOptions ?? this.options.mjmlOptions);
1102
+ const html = await requireService(this.#mjmlService, "MJML").render(template, options?.mjmlOptions ?? this.#options.mjmlOptions);
1019
1103
  return this.generatePdfFromHtml(html, options);
1020
1104
  }
1021
1105
  async generatePdfFromMjmlFile(file, options) {
1022
- const html = await requireService(this.mjmlService, "MJML").renderFile(file, options?.mjmlOptions ?? this.options.mjmlOptions);
1106
+ const html = await requireService(this.#mjmlService, "MJML").renderFile(file, options?.mjmlOptions ?? this.#options.mjmlOptions);
1023
1107
  return this.generatePdfFromHtml(html, options);
1024
1108
  }
1025
1109
  async generatePdfFromPugString(template, data = {}, options) {
1026
- const html = requireService(this.pugService, "Pug").render(template, data, options?.pugOptions ?? this.options.pugOptions);
1110
+ const html = requireService(this.#pugService, "Pug").render(template, data, options?.pugOptions ?? this.#options.pugOptions);
1027
1111
  return this.generatePdfFromHtml(html, options);
1028
1112
  }
1029
1113
  async generatePdfFromPugFile(file, data = {}, options) {
1030
- const html = requireService(this.pugService, "Pug").renderFile(file, data, options?.pugOptions ?? this.options.pugOptions);
1114
+ const html = requireService(this.#pugService, "Pug").renderFile(file, data, options?.pugOptions ?? this.#options.pugOptions);
1031
1115
  return this.generatePdfFromHtml(html, options);
1032
1116
  }
1033
1117
  async generatePdfFromEjsString(template, data = {}, options) {
1034
- const html = await requireService(this.ejsService, "EJS").render(template, data, options?.ejsOptions ?? this.options.ejsOptions);
1118
+ const html = await requireService(this.#ejsService, "EJS").render(template, data, options?.ejsOptions ?? this.#options.ejsOptions);
1035
1119
  return this.generatePdfFromHtml(html, options);
1036
1120
  }
1037
1121
  async generatePdfFromEjsFile(file, data = {}, options) {
1038
- const html = await requireService(this.ejsService, "EJS").renderFile(file, data, options?.ejsOptions ?? this.options.ejsOptions);
1122
+ const html = await requireService(this.#ejsService, "EJS").renderFile(file, data, options?.ejsOptions ?? this.#options.ejsOptions);
1039
1123
  return this.generatePdfFromHtml(html, options);
1040
1124
  }
1041
1125
  async generatePdfFromNunjucksString(template, data = {}, options) {
1042
- const html = requireService(this.nunjucksService, "Nunjucks").render(template, data, options?.nunjucksOptions ?? this.options.nunjucksOptions);
1126
+ const html = requireService(this.#nunjucksService, "Nunjucks").render(template, data, options?.nunjucksOptions ?? this.#options.nunjucksOptions);
1043
1127
  return this.generatePdfFromHtml(html, options);
1044
1128
  }
1045
1129
  async generatePdfFromNunjucksFile(file, data = {}, options) {
1046
- const html = requireService(this.nunjucksService, "Nunjucks").renderFile(file, data, options?.nunjucksOptions ?? this.options.nunjucksOptions);
1130
+ const html = requireService(this.#nunjucksService, "Nunjucks").renderFile(file, data, options?.nunjucksOptions ?? this.#options.nunjucksOptions);
1047
1131
  return this.generatePdfFromHtml(html, options);
1048
1132
  }
1049
1133
  async generatePdfFromEtaString(template, data = {}, options) {
1050
- const html = requireService(this.etaService, "Eta").render(template, data, options?.etaOptions ?? this.options.etaOptions);
1134
+ const html = requireService(this.#etaService, "Eta").render(template, data, options?.etaOptions ?? this.#options.etaOptions);
1051
1135
  return this.generatePdfFromHtml(html, options);
1052
1136
  }
1053
1137
  async generatePdfFromEtaFile(file, data = {}, options) {
1054
- const html = requireService(this.etaService, "Eta").renderFile(file, data, options?.etaOptions ?? this.options.etaOptions);
1138
+ const html = requireService(this.#etaService, "Eta").renderFile(file, data, options?.etaOptions ?? this.#options.etaOptions);
1055
1139
  return this.generatePdfFromHtml(html, options);
1056
1140
  }
1057
1141
  async generatePdfFromMustacheString(template, data = {}, options) {
1058
- const html = requireService(this.mustacheService, "Mustache").render(template, data, options?.mustacheOptions ?? this.options.mustacheOptions);
1142
+ const html = requireService(this.#mustacheService, "Mustache").render(template, data, options?.mustacheOptions ?? this.#options.mustacheOptions);
1059
1143
  return this.generatePdfFromHtml(html, options);
1060
1144
  }
1061
1145
  async generatePdfFromMustacheFile(file, data = {}, options) {
1062
- const html = requireService(this.mustacheService, "Mustache").renderFile(file, data, options?.mustacheOptions ?? this.options.mustacheOptions);
1146
+ const html = requireService(this.#mustacheService, "Mustache").renderFile(file, data, options?.mustacheOptions ?? this.#options.mustacheOptions);
1063
1147
  return this.generatePdfFromHtml(html, options);
1064
1148
  }
1065
1149
  };
@@ -1088,9 +1172,9 @@ PuppeteerService = __decorate$3([
1088
1172
  //#endregion
1089
1173
  //#region src/nestjs-pdf.service.ts
1090
1174
  let NestjsPdfService = class NestjsPdfService {
1091
- puppeteerService;
1175
+ #puppeteerService;
1092
1176
  constructor(puppeteerService) {
1093
- this.puppeteerService = puppeteerService;
1177
+ this.#puppeteerService = puppeteerService;
1094
1178
  }
1095
1179
  /**
1096
1180
  * @param html HTML string to convert to PDF
@@ -1099,7 +1183,7 @@ let NestjsPdfService = class NestjsPdfService {
1099
1183
  * @description This method uses the Puppeteer service to generate a PDF from an HTML string. Generation options can be customized by passing a `PuppeteerParameters` object as the second argument. This allows you to control various aspects of PDF rendering, such as page size, margins, background display, etc. If no options are provided, the default parameters defined in the Puppeteer service will be used.
1100
1184
  */
1101
1185
  generatePdfFromHtml(html, options) {
1102
- return this.puppeteerService.generatePdfFromHtml(html, options);
1186
+ return this.#puppeteerService.generatePdfFromHtml(html, options);
1103
1187
  }
1104
1188
  /**
1105
1189
  * @param template Handlebars template string
@@ -1109,7 +1193,7 @@ let NestjsPdfService = class NestjsPdfService {
1109
1193
  * @description This method generates a PDF from a Handlebars template provided as a string. The parameters to inject into the template are passed in the `parameters` object, which is used to render the template before converting it to PDF. PDF generation options can also be customized by passing a `PuppeteerParameters` object as the third argument. This allows you to control various aspects of PDF rendering, such as page size, margins, background display, etc. If no options are provided, the default parameters defined in the Puppeteer service will be used.
1110
1194
  */
1111
1195
  generatePdfFromTemplateHbsString(template, parameters = {}, options) {
1112
- return this.puppeteerService.generatePdfFromTemplateHbsString(template, parameters, options);
1196
+ return this.#puppeteerService.generatePdfFromTemplateHbsString(template, parameters, options);
1113
1197
  }
1114
1198
  /**
1115
1199
  * @param file Path to the Handlebars template file
@@ -1119,7 +1203,7 @@ let NestjsPdfService = class NestjsPdfService {
1119
1203
  * @description This method generates a PDF from a Handlebars template located at the specified file path. The file path is passed as a string in the `file` parameter. The parameters to inject into the template are passed in the `parameters` object, which is used to render the template before converting it to PDF. PDF generation options can also be customized by passing a `PuppeteerParameters` object as the third argument. This allows you to control various aspects of PDF rendering, such as page size, margins, background display, etc. If no options are provided, the default parameters defined in the Puppeteer service will be used.
1120
1204
  */
1121
1205
  generatePdfFromTemplateHbsFile(file, parameters = {}, options) {
1122
- return this.puppeteerService.generatePdfFromTemplateHbsFile(file, parameters, options);
1206
+ return this.#puppeteerService.generatePdfFromTemplateHbsFile(file, parameters, options);
1123
1207
  }
1124
1208
  /**
1125
1209
  * @param template MJML template string
@@ -1128,7 +1212,7 @@ let NestjsPdfService = class NestjsPdfService {
1128
1212
  * @description This method generates a PDF from an MJML template provided as a string. MJML (MJML Markup Language) is a markup language designed to reduce the pain of coding a responsive email. The template is first rendered to HTML using the MJML renderer, then converted to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the second argument.
1129
1213
  */
1130
1214
  generatePdfFromMjmlString(template, options) {
1131
- return this.puppeteerService.generatePdfFromMjmlString(template, options);
1215
+ return this.#puppeteerService.generatePdfFromMjmlString(template, options);
1132
1216
  }
1133
1217
  /**
1134
1218
  * @param file Path to the MJML template file
@@ -1137,7 +1221,7 @@ let NestjsPdfService = class NestjsPdfService {
1137
1221
  * @description This method generates a PDF from an MJML template located at the specified file path. The file path is passed as a string in the `file` parameter. The template is first rendered to HTML using the MJML renderer, then converted to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the second argument.
1138
1222
  */
1139
1223
  generatePdfFromMjmlFile(file, options) {
1140
- return this.puppeteerService.generatePdfFromMjmlFile(file, options);
1224
+ return this.#puppeteerService.generatePdfFromMjmlFile(file, options);
1141
1225
  }
1142
1226
  /**
1143
1227
  * @param template EJS template string
@@ -1147,7 +1231,7 @@ let NestjsPdfService = class NestjsPdfService {
1147
1231
  * @description This method generates a PDF from an EJS (Embedded JavaScript) template provided as a string. EJS is a templating language with a simple, straightforward syntax. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
1148
1232
  */
1149
1233
  generatePdfFromEjsString(template, data = {}, options) {
1150
- return this.puppeteerService.generatePdfFromEjsString(template, data, options);
1234
+ return this.#puppeteerService.generatePdfFromEjsString(template, data, options);
1151
1235
  }
1152
1236
  /**
1153
1237
  * @param file Path to the EJS template file
@@ -1157,7 +1241,7 @@ let NestjsPdfService = class NestjsPdfService {
1157
1241
  * @description This method generates a PDF from an EJS template located at the specified file path. The file path is passed as a string in the `file` parameter. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
1158
1242
  */
1159
1243
  generatePdfFromEjsFile(file, data = {}, options) {
1160
- return this.puppeteerService.generatePdfFromEjsFile(file, data, options);
1244
+ return this.#puppeteerService.generatePdfFromEjsFile(file, data, options);
1161
1245
  }
1162
1246
  /**
1163
1247
  * @param template Pug template string
@@ -1167,7 +1251,7 @@ let NestjsPdfService = class NestjsPdfService {
1167
1251
  * @description This method generates a PDF from a Pug template provided as a string. Pug is a clean, whitespace-sensitive syntax for writing HTML. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
1168
1252
  */
1169
1253
  generatePdfFromPugString(template, data = {}, options) {
1170
- return this.puppeteerService.generatePdfFromPugString(template, data, options);
1254
+ return this.#puppeteerService.generatePdfFromPugString(template, data, options);
1171
1255
  }
1172
1256
  /**
1173
1257
  * @param file Path to the Pug template file
@@ -1177,7 +1261,7 @@ let NestjsPdfService = class NestjsPdfService {
1177
1261
  * @description This method generates a PDF from a Pug template located at the specified file path. The file path is passed as a string in the `file` parameter. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
1178
1262
  */
1179
1263
  generatePdfFromPugFile(file, data = {}, options) {
1180
- return this.puppeteerService.generatePdfFromPugFile(file, data, options);
1264
+ return this.#puppeteerService.generatePdfFromPugFile(file, data, options);
1181
1265
  }
1182
1266
  /**
1183
1267
  * @param template Nunjucks template string
@@ -1187,7 +1271,7 @@ let NestjsPdfService = class NestjsPdfService {
1187
1271
  * @description This method generates a PDF from a Nunjucks template provided as a string. Nunjucks is a powerful templating language with support for inheritance, macros, and filters. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
1188
1272
  */
1189
1273
  generatePdfFromNunjucksString(template, data = {}, options) {
1190
- return this.puppeteerService.generatePdfFromNunjucksString(template, data, options);
1274
+ return this.#puppeteerService.generatePdfFromNunjucksString(template, data, options);
1191
1275
  }
1192
1276
  /**
1193
1277
  * @param file Path to the Nunjucks template file
@@ -1197,7 +1281,7 @@ let NestjsPdfService = class NestjsPdfService {
1197
1281
  * @description This method generates a PDF from a Nunjucks template located at the specified file path. The file path is passed as a string in the `file` parameter. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
1198
1282
  */
1199
1283
  generatePdfFromNunjucksFile(file, data = {}, options) {
1200
- return this.puppeteerService.generatePdfFromNunjucksFile(file, data, options);
1284
+ return this.#puppeteerService.generatePdfFromNunjucksFile(file, data, options);
1201
1285
  }
1202
1286
  /**
1203
1287
  * @param template Eta template string
@@ -1207,7 +1291,7 @@ let NestjsPdfService = class NestjsPdfService {
1207
1291
  * @description This method generates a PDF from an Eta template provided as a string. Eta is a fast and lightweight embedded templating language with a syntax similar to EJS but with better performance. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
1208
1292
  */
1209
1293
  generatePdfFromEtaString(template, data = {}, options) {
1210
- return this.puppeteerService.generatePdfFromEtaString(template, data, options);
1294
+ return this.#puppeteerService.generatePdfFromEtaString(template, data, options);
1211
1295
  }
1212
1296
  /**
1213
1297
  * @param file Path to the Eta template file
@@ -1217,7 +1301,7 @@ let NestjsPdfService = class NestjsPdfService {
1217
1301
  * @description This method generates a PDF from an Eta template located at the specified file path. The file path is passed as a string in the `file` parameter. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
1218
1302
  */
1219
1303
  generatePdfFromEtaFile(file, data = {}, options) {
1220
- return this.puppeteerService.generatePdfFromEtaFile(file, data, options);
1304
+ return this.#puppeteerService.generatePdfFromEtaFile(file, data, options);
1221
1305
  }
1222
1306
  /**
1223
1307
  * @param template Mustache template string
@@ -1227,7 +1311,7 @@ let NestjsPdfService = class NestjsPdfService {
1227
1311
  * @description This method generates a PDF from a Mustache template provided as a string. Mustache is a logic-less template language that emphasizes readable and simple templates. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
1228
1312
  */
1229
1313
  generatePdfFromMustacheString(template, data = {}, options) {
1230
- return this.puppeteerService.generatePdfFromMustacheString(template, data, options);
1314
+ return this.#puppeteerService.generatePdfFromMustacheString(template, data, options);
1231
1315
  }
1232
1316
  /**
1233
1317
  * @param file Path to the Mustache template file
@@ -1237,7 +1321,7 @@ let NestjsPdfService = class NestjsPdfService {
1237
1321
  * @description This method generates a PDF from a Mustache template located at the specified file path. The file path is passed as a string in the `file` parameter. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
1238
1322
  */
1239
1323
  generatePdfFromMustacheFile(file, data = {}, options) {
1240
- return this.puppeteerService.generatePdfFromMustacheFile(file, data, options);
1324
+ return this.#puppeteerService.generatePdfFromMustacheFile(file, data, options);
1241
1325
  }
1242
1326
  /**
1243
1327
  * @param pdf The PDF bytes to modify
@@ -2538,14 +2622,14 @@ ConfigModule = ConfigModule_1 = __decorate([(0, _nestjs_common.Module)({
2538
2622
  //#region src/puppeteer/puppeteer.module.ts
2539
2623
  var _PuppeteerModule;
2540
2624
  let PuppeteerModule = _PuppeteerModule = class PuppeteerModule {
2541
- browserService;
2542
- pdfParams;
2625
+ #browserService;
2626
+ #pdfParams;
2543
2627
  constructor(browserService, pdfParams) {
2544
- this.browserService = browserService;
2545
- this.pdfParams = pdfParams;
2628
+ this.#browserService = browserService;
2629
+ this.#pdfParams = pdfParams;
2546
2630
  }
2547
2631
  async onModuleInit() {
2548
- if (!this.pdfParams.executablePath) await this.browserService.install(this.pdfParams.useLockedBrowser ?? false);
2632
+ if (!this.#pdfParams.executablePath) await this.#browserService.install(this.#pdfParams.useLockedBrowser ?? false);
2549
2633
  }
2550
2634
  static forRoot(pdfParameters) {
2551
2635
  const providers = [
@@ -2657,12 +2741,15 @@ let NestjsPdfModule = _NestjsPdfModule = class NestjsPdfModule {
2657
2741
  };
2658
2742
  NestjsPdfModule = _NestjsPdfModule = __decorate$3([(0, _nestjs_common.Module)({})], NestjsPdfModule);
2659
2743
  //#endregion
2744
+ exports.BrowserInstallationException = BrowserInstallationException;
2745
+ exports.BrowserUnavailableException = BrowserUnavailableException;
2660
2746
  Object.defineProperty(exports, "EjsService", {
2661
2747
  enumerable: true,
2662
2748
  get: function() {
2663
2749
  return EjsService;
2664
2750
  }
2665
2751
  });
2752
+ exports.EngineNotAvailableException = EngineNotAvailableException;
2666
2753
  Object.defineProperty(exports, "EtaService", {
2667
2754
  enumerable: true,
2668
2755
  get: function() {
@@ -2687,6 +2774,8 @@ Object.defineProperty(exports, "MustacheService", {
2687
2774
  return MustacheService;
2688
2775
  }
2689
2776
  });
2777
+ exports.NestjsPdfErrorCode = NestjsPdfErrorCode;
2778
+ exports.NestjsPdfException = NestjsPdfException;
2690
2779
  Object.defineProperty(exports, "NestjsPdfModule", {
2691
2780
  enumerable: true,
2692
2781
  get: function() {
@@ -2705,6 +2794,7 @@ Object.defineProperty(exports, "NunjucksService", {
2705
2794
  return NunjucksService;
2706
2795
  }
2707
2796
  });
2797
+ exports.PdfGenerationException = PdfGenerationException;
2708
2798
  Object.defineProperty(exports, "PugService", {
2709
2799
  enumerable: true,
2710
2800
  get: function() {
@@ -2723,4 +2813,8 @@ Object.defineProperty(exports, "PuppeteerService", {
2723
2813
  return PuppeteerService;
2724
2814
  }
2725
2815
  });
2816
+ exports.SignatureDependencyException = SignatureDependencyException;
2817
+ exports.SignaturePlacementException = SignaturePlacementException;
2818
+ exports.TemplateConfigurationException = TemplateConfigurationException;
2819
+ exports.TemplateRenderException = TemplateRenderException;
2726
2820
  exports.getRelativePathToValue = getRelativePathToValue;