@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.mjs CHANGED
@@ -43,6 +43,73 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
43
43
  }) : target, mod));
44
44
  var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
45
45
  //#endregion
46
+ //#region src/exceptions/nestjs-pdf.exception.ts
47
+ let NestjsPdfErrorCode = /* @__PURE__ */ function(NestjsPdfErrorCode) {
48
+ NestjsPdfErrorCode["ENGINE_NOT_AVAILABLE"] = "ENGINE_NOT_AVAILABLE";
49
+ NestjsPdfErrorCode["TEMPLATE_CONFIGURATION_ERROR"] = "TEMPLATE_CONFIGURATION_ERROR";
50
+ NestjsPdfErrorCode["TEMPLATE_RENDER_ERROR"] = "TEMPLATE_RENDER_ERROR";
51
+ NestjsPdfErrorCode["BROWSER_INSTALLATION_ERROR"] = "BROWSER_INSTALLATION_ERROR";
52
+ NestjsPdfErrorCode["BROWSER_UNAVAILABLE"] = "BROWSER_UNAVAILABLE";
53
+ NestjsPdfErrorCode["PDF_GENERATION_ERROR"] = "PDF_GENERATION_ERROR";
54
+ NestjsPdfErrorCode["SIGNATURE_DEPENDENCY_ERROR"] = "SIGNATURE_DEPENDENCY_ERROR";
55
+ NestjsPdfErrorCode["SIGNATURE_PLACEMENT_ERROR"] = "SIGNATURE_PLACEMENT_ERROR";
56
+ return NestjsPdfErrorCode;
57
+ }({});
58
+ var NestjsPdfException = class extends Error {
59
+ constructor(message, options) {
60
+ super(message, options);
61
+ this.name = this.constructor.name;
62
+ }
63
+ };
64
+ //#endregion
65
+ //#region src/exceptions/browser-installation.exception.ts
66
+ var BrowserInstallationException = class extends NestjsPdfException {
67
+ code = "BROWSER_INSTALLATION_ERROR";
68
+ };
69
+ //#endregion
70
+ //#region src/exceptions/browser-unavailable.exception.ts
71
+ var BrowserUnavailableException = class extends NestjsPdfException {
72
+ code = "BROWSER_UNAVAILABLE";
73
+ };
74
+ //#endregion
75
+ //#region src/exceptions/engine-not-available.exception.ts
76
+ var EngineNotAvailableException = class extends NestjsPdfException {
77
+ code = "ENGINE_NOT_AVAILABLE";
78
+ constructor(engineName) {
79
+ super(`${engineName} service is not available. If the problem persists, open an issue in the repo.`);
80
+ }
81
+ };
82
+ //#endregion
83
+ //#region src/exceptions/pdf-generation.exception.ts
84
+ var PdfGenerationException = class extends NestjsPdfException {
85
+ code = "PDF_GENERATION_ERROR";
86
+ };
87
+ //#endregion
88
+ //#region src/exceptions/signature-dependency.exception.ts
89
+ var SignatureDependencyException = class extends NestjsPdfException {
90
+ code = "SIGNATURE_DEPENDENCY_ERROR";
91
+ };
92
+ //#endregion
93
+ //#region src/exceptions/signature-placement.exception.ts
94
+ var SignaturePlacementException = class extends NestjsPdfException {
95
+ code = "SIGNATURE_PLACEMENT_ERROR";
96
+ };
97
+ //#endregion
98
+ //#region src/exceptions/template-configuration.exception.ts
99
+ var TemplateConfigurationException = class extends NestjsPdfException {
100
+ code = "TEMPLATE_CONFIGURATION_ERROR";
101
+ };
102
+ //#endregion
103
+ //#region src/exceptions/template-render.exception.ts
104
+ var TemplateRenderException = class extends NestjsPdfException {
105
+ engine;
106
+ code = "TEMPLATE_RENDER_ERROR";
107
+ constructor(engine, message, options) {
108
+ super(message, options);
109
+ this.engine = engine;
110
+ }
111
+ };
112
+ //#endregion
46
113
  //#region src/helpers/getRelativePath.helper.ts
47
114
  /**
48
115
  * Get the relative path to a value from the module directory.
@@ -65,14 +132,12 @@ async function loadPdfjs() {
65
132
  pdfjsPromise = await import("pdfjs-dist/legacy/build/pdf.mjs");
66
133
  } catch (error) {
67
134
  pdfjsPromise = void 0;
68
- /* v8 ignore next -- import() rejections are always Error instances in practice */
69
- const reason = error instanceof Error ? error.message : String(error);
70
- throw new Error([
135
+ throw new SignatureDependencyException([
71
136
  "Failed to load pdfjs-dist.",
72
137
  "If you use anchor-based signature placement in Node.js, make sure @napi-rs/canvas is installed.",
73
138
  "Try: npm install @napi-rs/canvas",
74
139
  "",
75
- `Original error: ${reason}`
140
+ `Original error: ${error instanceof Error ? error.message : String(error)}`
76
141
  ].join("\n"), { cause: error });
77
142
  }
78
143
  return pdfjsPromise;
@@ -170,7 +235,7 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
170
235
  if (anchor) {
171
236
  const pageIndex = anchor.pageIndex;
172
237
  const page = pdfDoc.getPages()[pageIndex];
173
- if (!page) throw new Error(`Page ${pageIndex} not found`);
238
+ if (!page) throw new SignaturePlacementException(`Page ${pageIndex} not found`);
174
239
  const { width: pw, height: ph } = page.getSize();
175
240
  const padX = 40;
176
241
  const padY = 7;
@@ -191,7 +256,7 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
191
256
  const pageIndex = pages.length - 1;
192
257
  const page = pages.at(-1);
193
258
  /* v8 ignore next -- pdf-lib always produces at least one page on save/load; only a hand-crafted, malformed PDF could hit this */
194
- if (!page) throw new Error(`Page ${pageIndex} not found`);
259
+ if (!page) throw new SignaturePlacementException(`Page ${pageIndex} not found`);
195
260
  const { width: pageWidth } = page.getSize();
196
261
  addSignatureFieldAt(pdfDoc, pageIndex, {
197
262
  fieldName,
@@ -382,47 +447,47 @@ function isTargetClosedError(error) {
382
447
  return error.name === "TargetCloseError" || error.message.includes("Target closed") || error.message.includes("Target.createTarget");
383
448
  }
384
449
  let BrowserService = class BrowserService {
385
- cacheDir;
386
- options;
387
- _browserInstance = null;
388
- browser;
450
+ #cacheDir;
451
+ #options;
452
+ #browserInstance = null;
453
+ #browser;
389
454
  activeJobs = 0;
390
455
  totalJobs = 0;
391
- recycleRequested = false;
392
- recycling = false;
393
- shuttingDown = false;
456
+ #recycleRequested = false;
457
+ #recycling = false;
458
+ #shuttingDown = false;
394
459
  /** Max time to wait for in-flight PDF jobs to finish before closing the browser on shutdown. */
395
460
  shutdownDrainTimeoutMs = 15e3;
396
- browserTag;
397
- useLockedBrowser;
398
- buildId;
461
+ #browserTag;
462
+ #useLockedBrowser;
463
+ #buildId;
399
464
  constructor(pdfParams) {
400
- this.cacheDir = resolve(".cache/puppeteer-browser");
401
- this.options = pdfParams;
402
- this.loadBuildId();
403
- this.loadBrowser();
404
- this.loadBrowserTag();
405
- this.loadUseLockedBrowser();
465
+ this.#cacheDir = resolve(".cache/puppeteer-browser");
466
+ this.#options = pdfParams;
467
+ this.#loadBuildId();
468
+ this.#loadBrowser();
469
+ this.#loadBrowserTag();
470
+ this.#loadUseLockedBrowser();
406
471
  }
407
472
  async onModuleDestroy() {
408
- this.shuttingDown = true;
409
- await this.waitForIdle(this.shutdownDrainTimeoutMs);
410
- if (this._browserInstance?.connected) try {
411
- await this._browserInstance.close();
473
+ this.#shuttingDown = true;
474
+ await this.#waitForIdle(this.shutdownDrainTimeoutMs);
475
+ if (this.#browserInstance?.connected) try {
476
+ await this.#browserInstance.close();
412
477
  } catch (error) {
413
478
  Logger.warn(`Failed to close browser on module destroy: ${error instanceof Error ? error.message : String(error)}`);
414
479
  }
415
- if (this.options?.cleanupBrowserCacheOnExit !== false) await this.cleanupCacheBestEffort();
480
+ if (this.#options?.cleanupBrowserCacheOnExit !== false) await this.#cleanupCacheBestEffort();
416
481
  }
417
482
  /** Wait until no PDF job is in flight, or until the timeout elapses. */
418
- async waitForIdle(timeoutMs) {
483
+ async #waitForIdle(timeoutMs) {
419
484
  const start = Date.now();
420
485
  while (this.activeJobs > 0 && Date.now() - start < timeoutMs) await sleep(50);
421
486
  if (this.activeJobs > 0) Logger.warn(`Shutdown: ${this.activeJobs} PDF job(s) still running after ${timeoutMs}ms, closing the browser anyway`);
422
487
  }
423
488
  async getBrowserInstance(args, headless, executablePathBin) {
424
- if (!this._browserInstance?.connected) this._browserInstance = await this.launchBrowser(args, headless, executablePathBin);
425
- return this._browserInstance;
489
+ if (!this.#browserInstance?.connected) this.#browserInstance = await this.#launchBrowser(args, headless, executablePathBin);
490
+ return this.#browserInstance;
426
491
  }
427
492
  async createContext(args, headless, executablePath) {
428
493
  const browser = await this.getBrowserInstance(args, headless, executablePath);
@@ -431,41 +496,41 @@ let BrowserService = class BrowserService {
431
496
  } catch (error) {
432
497
  if (!isTargetClosedError(error)) throw error;
433
498
  Logger.warn("Puppeteer browser closed while creating a context, retrying once");
434
- this._browserInstance = null;
499
+ this.#browserInstance = null;
435
500
  return await (await this.getBrowserInstance(args, headless, executablePath)).createBrowserContext();
436
501
  }
437
502
  }
438
503
  markJobStarted() {
439
- if (this.shuttingDown) throw new Error("nestjs-pdf is shutting down, refusing new PDF jobs");
504
+ if (this.#shuttingDown) throw new BrowserUnavailableException("nestjs-pdf is shutting down, refusing new PDF jobs");
440
505
  this.activeJobs += 1;
441
506
  this.totalJobs += 1;
442
- if (this.totalJobs >= 200) this.recycleRequested = true;
507
+ if (this.totalJobs >= 200) this.#recycleRequested = true;
443
508
  }
444
509
  async markJobFinished() {
445
510
  this.activeJobs = Math.max(0, this.activeJobs - 1);
446
511
  await this.recycleBrowserIfNeeded();
447
512
  }
448
513
  async recycleBrowserIfNeeded() {
449
- if (!this.recycleRequested) return;
450
- if (this.recycling) return;
514
+ if (!this.#recycleRequested) return;
515
+ if (this.#recycling) return;
451
516
  if (this.activeJobs > 0) return;
452
- if (!this._browserInstance) return;
453
- this.recycling = true;
517
+ if (!this.#browserInstance) return;
518
+ this.#recycling = true;
454
519
  try {
455
- if (this._browserInstance.connected) await this._browserInstance.close();
456
- this._browserInstance = null;
520
+ if (this.#browserInstance.connected) await this.#browserInstance.close();
521
+ this.#browserInstance = null;
457
522
  this.totalJobs = 0;
458
- this.recycleRequested = false;
523
+ this.#recycleRequested = false;
459
524
  Logger.log("Puppeteer browser recycled successfully");
460
525
  } catch (error) {
461
526
  Logger.warn(`Failed to recycle browser: ${error instanceof Error ? error.message : String(error)}`);
462
527
  } finally {
463
- this.recycling = false;
528
+ this.#recycling = false;
464
529
  }
465
530
  }
466
- async cleanupCacheBestEffort() {
531
+ async #cleanupCacheBestEffort() {
467
532
  const logger = new Logger("NestJsPdf");
468
- const dir = this.cacheDir;
533
+ const dir = this.#cacheDir;
469
534
  try {
470
535
  if (!existsSync(dir)) return;
471
536
  logger.log(`Cleanup puppeteer cache: ${dir}`);
@@ -486,101 +551,109 @@ let BrowserService = class BrowserService {
486
551
  }
487
552
  }
488
553
  async install(lock = false) {
489
- const browser = this.browser;
490
- const versionTag = this.browserTag;
554
+ try {
555
+ return await this.#doInstall(lock);
556
+ } catch (error) {
557
+ if (error instanceof NestjsPdfException) throw error;
558
+ throw new BrowserInstallationException(`Could not install browser: ${String(error)}`, { cause: error });
559
+ }
560
+ }
561
+ async #doInstall(lock) {
562
+ const browser = this.#browser;
563
+ const versionTag = this.#browserTag;
491
564
  const browserPlatform = detectBrowserPlatform() ?? BrowserPlatform.LINUX;
492
565
  let buildId;
493
- if (this.buildId === void 0) buildId = await resolveBuildId(browser, browserPlatform, versionTag);
494
- else buildId = this.buildId;
566
+ if (this.#buildId === void 0) buildId = await resolveBuildId(browser, browserPlatform, versionTag);
567
+ else buildId = this.#buildId;
495
568
  Logger.log(`Browser ${browser} ${versionTag} build id: ${buildId}`, "NestJsPdf");
496
569
  if (await this.hasBrowserInstalled(browser, buildId)) {
497
570
  Logger.log("Browser already installed", "NestJsPdf");
498
- if (lock) this.writeLockFile(browser, buildId);
571
+ if (lock) this.#writeLockFile(browser, buildId);
499
572
  return;
500
573
  } else {
501
574
  Logger.log("Starting browser installation", "NestJsPdf");
502
575
  const installOption = {
503
- cacheDir: this.cacheDir,
576
+ cacheDir: this.#cacheDir,
504
577
  browser,
505
578
  buildId,
506
- baseUrl: this.options?.browserInstallBaseUrl ?? void 0
579
+ baseUrl: this.#options?.browserInstallBaseUrl ?? void 0
507
580
  };
508
581
  if (await canDownload(installOption)) {
509
582
  Logger.log(`Installing ${installOption.browser} ${installOption.buildId}`, "NestJsPdf");
510
583
  const installedBrowser = await install(installOption);
511
584
  if (await this.hasBrowserInstalled(browser, buildId)) {
512
585
  Logger.log("Browser installed successfully", "NestJsPdf");
513
- if (lock) this.writeLockFile(browser, buildId);
586
+ if (lock) this.#writeLockFile(browser, buildId);
514
587
  return installedBrowser;
515
588
  } else Logger.error("Browser installation failed", "NestJsPdf");
516
589
  } else Logger.error(`Error, can't install ${installOption.browser} ${installOption.buildId}`, "NestJsPdf");
517
590
  }
518
591
  return null;
519
592
  }
520
- loadBrowser() {
593
+ #loadBrowser() {
521
594
  let browser;
522
- if (this.options?.browser === void 0) browser = Browser.CHROMIUM;
523
- else browser = this.options.browser;
524
- this.browser = browser;
595
+ if (this.#options?.browser === void 0) browser = Browser.CHROMIUM;
596
+ else browser = this.#options.browser;
597
+ this.#browser = browser;
525
598
  }
526
599
  getBrowser() {
527
- return this.browser;
600
+ return this.#browser;
528
601
  }
529
- loadBrowserTag() {
602
+ #loadBrowserTag() {
530
603
  let versionTag;
531
- if (this.options?.browserTag === void 0) {
532
- if (this.browser === Browser.CHROMIUM) versionTag = "latest";
604
+ if (this.#options?.browserTag === void 0) {
605
+ if (this.#browser === Browser.CHROMIUM) versionTag = "latest";
533
606
  else versionTag = "stable";
534
- } else versionTag = this.options.browserTag;
535
- this.browserTag = versionTag;
607
+ } else versionTag = this.#options.browserTag;
608
+ this.#browserTag = versionTag;
536
609
  }
537
- loadBuildId() {
610
+ #loadBuildId() {
538
611
  let buildId;
539
- if (this.options?.buildId === void 0) buildId = void 0;
540
- else buildId = this.options.buildId;
541
- this.buildId = buildId;
612
+ if (this.#options?.buildId === void 0) buildId = void 0;
613
+ else buildId = this.#options.buildId;
614
+ this.#buildId = buildId;
542
615
  }
543
616
  setBrowserTag(browserTag) {
544
- this.browserTag = browserTag;
617
+ this.#browserTag = browserTag;
545
618
  }
546
619
  getBrowserTag() {
547
- return this.browserTag;
620
+ return this.#browserTag;
548
621
  }
549
622
  getBuildId() {
550
- return this.buildId;
623
+ return this.#buildId;
551
624
  }
552
- loadUseLockedBrowser() {
625
+ #loadUseLockedBrowser() {
553
626
  let useLockedBrowser;
554
- if (this.options?.useLockedBrowser === void 0) useLockedBrowser = false;
555
- else useLockedBrowser = this.options.useLockedBrowser;
556
- this.useLockedBrowser = useLockedBrowser;
627
+ if (this.#options?.useLockedBrowser === void 0) useLockedBrowser = false;
628
+ else useLockedBrowser = this.#options.useLockedBrowser;
629
+ this.#useLockedBrowser = useLockedBrowser;
557
630
  }
558
631
  async hasBrowserInstalled(browser, buildId) {
559
- return (await getInstalledBrowsers({ cacheDir: this.cacheDir })).find((insBrowser) => {
632
+ return (await getInstalledBrowsers({ cacheDir: this.#cacheDir })).find((insBrowser) => {
560
633
  return insBrowser.browser === browser && insBrowser.buildId === buildId;
561
634
  }) !== void 0;
562
635
  }
563
636
  async getExecutablePath() {
564
- const browser = this.browser;
565
- const versionTag = this.browserTag;
637
+ const browser = this.#browser;
638
+ const versionTag = this.#browserTag;
566
639
  const browserPlatform = detectBrowserPlatform() ?? BrowserPlatform.LINUX;
567
640
  let buildId = null;
568
- if (this.useLockedBrowser) {
641
+ if (this.#useLockedBrowser) {
569
642
  buildId = this.getLockedBuildId(browser);
570
643
  Logger.log(`Using locked browser ${buildId}`, "NestJsPdf");
571
644
  }
572
645
  buildId ??= await resolveBuildId(browser, browserPlatform, versionTag);
573
- const installedBrowser = (await getInstalledBrowsers({ cacheDir: this.cacheDir })).find((insBrowser) => {
646
+ const installedBrowser = (await getInstalledBrowsers({ cacheDir: this.#cacheDir })).find((insBrowser) => {
574
647
  return insBrowser.browser === browser && insBrowser.buildId === buildId;
575
648
  });
576
649
  if (installedBrowser === void 0) {
577
650
  const newinstalledBrowser = await this.install();
578
- if (newinstalledBrowser === null || newinstalledBrowser === void 0) throw new Error("Could not install browser");
651
+ if (newinstalledBrowser === null || newinstalledBrowser === void 0) throw new BrowserInstallationException("Could not install browser");
579
652
  else return newinstalledBrowser.executablePath;
580
653
  }
581
654
  return installedBrowser.executablePath;
582
655
  }
583
- async launchBrowser(args, headless, executablePathBin) {
656
+ async #launchBrowser(args, headless, executablePathBin) {
584
657
  const executablePath = executablePathBin ?? await this.getExecutablePath();
585
658
  const browser = await launch({
586
659
  executablePath,
@@ -589,12 +662,12 @@ let BrowserService = class BrowserService {
589
662
  });
590
663
  browser.on("disconnected", () => {
591
664
  Logger.warn("Puppeteer browser disconnected");
592
- if (this._browserInstance === browser) this._browserInstance = null;
665
+ if (this.#browserInstance === browser) this.#browserInstance = null;
593
666
  });
594
667
  return browser;
595
668
  }
596
- writeLockFile(browser, buildId) {
597
- const lockFile = resolve(this.cacheDir, `${browser}.lock`);
669
+ #writeLockFile(browser, buildId) {
670
+ const lockFile = resolve(this.#cacheDir, `${browser}.lock`);
598
671
  const data = JSON.stringify({
599
672
  browser,
600
673
  buildId,
@@ -604,7 +677,7 @@ let BrowserService = class BrowserService {
604
677
  Logger.log(`Browser ${browser} locked to build ${buildId}`, "NestJsPdf");
605
678
  }
606
679
  getLockedBuildId(browser) {
607
- const lockFile = resolve(this.cacheDir, `${browser}.lock`);
680
+ const lockFile = resolve(this.#cacheDir, `${browser}.lock`);
608
681
  if (existsSync(lockFile)) {
609
682
  const data = readFileSync(lockFile);
610
683
  return JSON.parse(data.toString()).buildId;
@@ -627,7 +700,7 @@ let EjsService = class EjsService {
627
700
  ...options
628
701
  });
629
702
  } catch (error) {
630
- throw new Error(`EJS rendering failed: ${String(error)}`, { cause: error });
703
+ throw new TemplateRenderException("EJS", `EJS rendering failed: ${String(error)}`, { cause: error });
631
704
  }
632
705
  }
633
706
  async renderFile(filePath, data = {}, options) {
@@ -637,7 +710,7 @@ let EjsService = class EjsService {
637
710
  ...options
638
711
  });
639
712
  } catch (error) {
640
- throw new Error(`EJS file rendering failed: ${String(error)}`, { cause: error });
713
+ throw new TemplateRenderException("EJS", `EJS file rendering failed: ${String(error)}`, { cause: error });
641
714
  }
642
715
  }
643
716
  };
@@ -645,11 +718,11 @@ EjsService = __decorate$3([Injectable()], EjsService);
645
718
  //#endregion
646
719
  //#region src/puppeteer/engines/eta/eta.service.ts
647
720
  let EtaService = class EtaService {
648
- eta;
649
- templateCache = /* @__PURE__ */ new Map();
650
- maxCacheSize = 100;
721
+ #eta;
722
+ #templateCache = /* @__PURE__ */ new Map();
723
+ #maxCacheSize = 100;
651
724
  constructor() {
652
- this.eta = new Eta({
725
+ this.#eta = new Eta({
653
726
  cache: true,
654
727
  autoEscape: true,
655
728
  useWith: true
@@ -670,9 +743,9 @@ let EtaService = class EtaService {
670
743
  useWith: true,
671
744
  ...options,
672
745
  varName: options.varName ?? "it"
673
- }) : this.eta).renderString(template, data);
746
+ }) : this.#eta).renderString(template, data);
674
747
  } catch (error) {
675
- throw new Error(`Eta rendering failed: ${String(error)}`, { cause: error });
748
+ throw new TemplateRenderException("Eta", `Eta rendering failed: ${String(error)}`, { cause: error });
676
749
  }
677
750
  }
678
751
  /**
@@ -686,53 +759,54 @@ let EtaService = class EtaService {
686
759
  try {
687
760
  const resolvedPath = resolve(filePath);
688
761
  const useCache = options?.cache ?? true;
689
- let template = useCache ? this.templateCache.get(resolvedPath) : void 0;
762
+ let template = useCache ? this.#templateCache.get(resolvedPath) : void 0;
690
763
  if (!template) {
691
764
  template = readFileSync(resolvedPath, "utf-8");
692
- if (useCache && this.templateCache.size < this.maxCacheSize) this.templateCache.set(resolvedPath, template);
765
+ if (useCache && this.#templateCache.size < this.#maxCacheSize) this.#templateCache.set(resolvedPath, template);
693
766
  }
694
767
  return this.render(template, data, options);
695
768
  } catch (error) {
696
- throw new Error(`Eta file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
769
+ throw new TemplateRenderException("Eta", `Eta file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
697
770
  }
698
771
  }
699
772
  /**
700
773
  * Clear the template cache
701
774
  */
702
775
  clearCache() {
703
- this.templateCache.clear();
776
+ this.#templateCache.clear();
704
777
  }
705
778
  /**
706
779
  * Get the current cache size
707
780
  * @returns The number of cached templates
708
781
  */
709
782
  getCacheSize() {
710
- return this.templateCache.size;
783
+ return this.#templateCache.size;
711
784
  }
712
785
  };
713
786
  EtaService = __decorate$3([Injectable(), __decorateMetadata("design:paramtypes", [])], EtaService);
714
787
  //#endregion
715
788
  //#region src/puppeteer/engines/handlebars/handlebars.service.ts
716
789
  let HandlebarsService = class HandlebarsService {
717
- cachedOptions;
718
- cachedEnv;
790
+ #cachedOptions;
791
+ #cachedEnv;
719
792
  render(template, parameters = {}, options = {}) {
720
793
  try {
721
- return this.getEnv(options).compile(template, options.compileOptions)(parameters, options.templateOptions);
794
+ return this.#getEnv(options).compile(template, options.compileOptions)(parameters, options.templateOptions);
722
795
  } catch (error) {
723
- throw new Error(`Handlebars rendering failed: ${String(error)}`, { cause: error });
796
+ if (error instanceof NestjsPdfException) throw error;
797
+ throw new TemplateRenderException("Handlebars", `Handlebars rendering failed: ${String(error)}`, { cause: error });
724
798
  }
725
799
  }
726
800
  renderFile(file, parameters = {}, options = {}) {
727
- if (options.templateDirectory === void 0) throw new Error("Handlebars file rendering failed: option `templateDirectory` is not set");
801
+ if (options.templateDirectory === void 0) throw new TemplateConfigurationException("Handlebars file rendering failed: option `templateDirectory` is not set");
728
802
  const baseDir = resolve(process.cwd(), options.templateDirectory);
729
803
  const templatePath = resolve(baseDir, file);
730
- if (templatePath !== baseDir && !templatePath.startsWith(baseDir + sep)) throw new Error(`Handlebars file rendering failed: ’${file}’ resolves outside \`templateDirectory\``);
804
+ if (templatePath !== baseDir && !templatePath.startsWith(baseDir + sep)) throw new TemplateConfigurationException(`Handlebars file rendering failed: ’${file}’ resolves outside \`templateDirectory\``);
731
805
  let template;
732
806
  try {
733
807
  template = readFileSync(templatePath, "utf8");
734
808
  } catch (error) {
735
- throw new Error(`Handlebars file rendering failed: ${String(error)}`, { cause: error });
809
+ throw new TemplateRenderException("Handlebars", `Handlebars file rendering failed: ${String(error)}`, { cause: error });
736
810
  }
737
811
  return this.render(template, parameters, options);
738
812
  }
@@ -741,19 +815,19 @@ let HandlebarsService = class HandlebarsService {
741
815
  * nothing leaks into the global Handlebars. Memoised for the common case where
742
816
  * the same options object is reused across calls (e.g. the module `hbsOptions`).
743
817
  */
744
- getEnv(options) {
745
- if (this.cachedEnv && this.cachedOptions === options) return this.cachedEnv;
818
+ #getEnv(options) {
819
+ if (this.#cachedEnv && this.#cachedOptions === options) return this.#cachedEnv;
746
820
  const env = Handlebars.create();
747
821
  for (const helper of options.helpers ?? []) env.registerHelper(helper.name, helper.fn);
748
- this.registerPartials(env, options.partialDirectory);
749
- this.cachedOptions = options;
750
- this.cachedEnv = env;
822
+ this.#registerPartials(env, options.partialDirectory);
823
+ this.#cachedOptions = options;
824
+ this.#cachedEnv = env;
751
825
  return env;
752
826
  }
753
- registerPartials(env, partialDirectory) {
827
+ #registerPartials(env, partialDirectory) {
754
828
  if (partialDirectory === void 0) return;
755
829
  const partialPath = join(process.cwd(), partialDirectory);
756
- if (!existsSync(partialPath)) throw new Error(`Handlebars partial directory does not exist: ${partialPath}`);
830
+ if (!existsSync(partialPath)) throw new TemplateConfigurationException(`Handlebars partial directory does not exist: ${partialPath}`);
757
831
  for (const entry of readdirSync(partialPath)) {
758
832
  const filePath = join(partialPath, entry);
759
833
  if (!statSync(filePath).isFile()) continue;
@@ -766,11 +840,20 @@ HandlebarsService = __decorate$3([Injectable()], HandlebarsService);
766
840
  //#region src/puppeteer/engines/mjml/mjml.service.ts
767
841
  let MjmlService = class MjmlService {
768
842
  async render(template, options) {
769
- const { html } = await mjml(template, options);
770
- return html;
843
+ try {
844
+ const { html } = await mjml(template, options);
845
+ return html;
846
+ } catch (error) {
847
+ throw new TemplateRenderException("MJML", `MJML rendering failed: ${String(error)}`, { cause: error });
848
+ }
771
849
  }
772
850
  async renderFile(filePath, options) {
773
- const template = readFileSync(filePath, "utf-8");
851
+ let template;
852
+ try {
853
+ template = readFileSync(filePath, "utf-8");
854
+ } catch (error) {
855
+ throw new TemplateRenderException("MJML", `MJML file rendering failed: ${String(error)}`, { cause: error });
856
+ }
774
857
  return await this.render(template, options);
775
858
  }
776
859
  };
@@ -778,8 +861,8 @@ MjmlService = __decorate$3([Injectable()], MjmlService);
778
861
  //#endregion
779
862
  //#region src/puppeteer/engines/mustache/mustache.service.ts
780
863
  let MustacheService = class MustacheService {
781
- templateCache = /* @__PURE__ */ new Map();
782
- maxCacheSize = 100;
864
+ #templateCache = /* @__PURE__ */ new Map();
865
+ #maxCacheSize = 100;
783
866
  /**
784
867
  * Render a Mustache template from a string
785
868
  * @param template The template string to render
@@ -795,7 +878,7 @@ let MustacheService = class MustacheService {
795
878
  escape: options?.escape
796
879
  });
797
880
  } catch (error) {
798
- throw new Error(`Mustache rendering failed: ${String(error)}`, { cause: error });
881
+ throw new TemplateRenderException("Mustache", `Mustache rendering failed: ${String(error)}`, { cause: error });
799
882
  }
800
883
  }
801
884
  /**
@@ -808,28 +891,28 @@ let MustacheService = class MustacheService {
808
891
  renderFile(filePath, data = {}, options) {
809
892
  try {
810
893
  const resolvedPath = resolve(filePath);
811
- let template = this.templateCache.get(resolvedPath);
894
+ let template = this.#templateCache.get(resolvedPath);
812
895
  if (!template) {
813
896
  template = readFileSync(resolvedPath, "utf-8");
814
- if (this.templateCache.size < this.maxCacheSize) this.templateCache.set(resolvedPath, template);
897
+ if (this.#templateCache.size < this.#maxCacheSize) this.#templateCache.set(resolvedPath, template);
815
898
  }
816
899
  return this.render(template, data, options);
817
900
  } catch (error) {
818
- throw new Error(`Mustache file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
901
+ throw new TemplateRenderException("Mustache", `Mustache file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
819
902
  }
820
903
  }
821
904
  /**
822
905
  * Clear the template cache
823
906
  */
824
907
  clearCache() {
825
- this.templateCache.clear();
908
+ this.#templateCache.clear();
826
909
  }
827
910
  /**
828
911
  * Get the current cache size
829
912
  * @returns The number of cached templates
830
913
  */
831
914
  getCacheSize() {
832
- return this.templateCache.size;
915
+ return this.#templateCache.size;
833
916
  }
834
917
  };
835
918
  MustacheService = __decorate$3([Injectable()], MustacheService);
@@ -857,7 +940,7 @@ let NunjucksService = class NunjucksService {
857
940
  }
858
941
  return nunjucks.renderString(template, data);
859
942
  } catch (error) {
860
- throw new Error(`Nunjucks rendering failed: ${String(error)}`, { cause: error });
943
+ throw new TemplateRenderException("Nunjucks", `Nunjucks rendering failed: ${String(error)}`, { cause: error });
861
944
  }
862
945
  }
863
946
  renderFile(filePath, data = {}, options) {
@@ -874,7 +957,7 @@ let NunjucksService = class NunjucksService {
874
957
  }
875
958
  return nunjucks.render(filePath, data);
876
959
  } catch (error) {
877
- throw new Error(`Nunjucks file rendering failed: ${String(error)}`, { cause: error });
960
+ throw new TemplateRenderException("Nunjucks", `Nunjucks file rendering failed: ${String(error)}`, { cause: error });
878
961
  }
879
962
  }
880
963
  };
@@ -886,7 +969,7 @@ let PugService = class PugService {
886
969
  try {
887
970
  return pug.compile(template, { ...options })(data);
888
971
  } catch (error) {
889
- throw new Error(`Pug rendering failed: ${String(error)}`, { cause: error });
972
+ throw new TemplateRenderException("Pug", `Pug rendering failed: ${String(error)}`, { cause: error });
890
973
  }
891
974
  }
892
975
  renderFile(filePath, data = {}, options) {
@@ -894,7 +977,7 @@ let PugService = class PugService {
894
977
  const template = readFileSync(filePath, "utf-8");
895
978
  return this.render(template, data, options);
896
979
  } catch (error) {
897
- throw new Error(`Pug file rendering failed: ${String(error)}`, { cause: error });
980
+ throw new TemplateRenderException("Pug", `Pug file rendering failed: ${String(error)}`, { cause: error });
898
981
  }
899
982
  }
900
983
  };
@@ -902,36 +985,36 @@ PugService = __decorate$3([Injectable()], PugService);
902
985
  //#endregion
903
986
  //#region src/puppeteer/libs/requireService.utils.ts
904
987
  function requireService(service, name) {
905
- if (!service) throw new Error(`${name} service is not available. If the problem persists, open an issue in the repo.`);
988
+ if (!service) throw new EngineNotAvailableException(name);
906
989
  return service;
907
990
  }
908
991
  //#endregion
909
992
  //#region src/puppeteer/puppeteer.service.ts
910
993
  let PuppeteerService = class PuppeteerService {
911
- browserService;
912
- options;
913
- hbsService;
914
- mjmlService;
915
- pugService;
916
- ejsService;
917
- nunjucksService;
918
- etaService;
919
- mustacheService;
994
+ #browserService;
995
+ #options;
996
+ #hbsService;
997
+ #mjmlService;
998
+ #pugService;
999
+ #ejsService;
1000
+ #nunjucksService;
1001
+ #etaService;
1002
+ #mustacheService;
920
1003
  constructor(browserService, options, hbsService, mjmlService, pugService, ejsService, nunjucksService, etaService, mustacheService) {
921
- this.browserService = browserService;
922
- this.options = options;
923
- this.hbsService = hbsService;
924
- this.mjmlService = mjmlService;
925
- this.pugService = pugService;
926
- this.ejsService = ejsService;
927
- this.nunjucksService = nunjucksService;
928
- this.etaService = etaService;
929
- this.mustacheService = mustacheService;
930
- }
931
- limit = pLimit(3);
1004
+ this.#browserService = browserService;
1005
+ this.#options = options;
1006
+ this.#hbsService = hbsService;
1007
+ this.#mjmlService = mjmlService;
1008
+ this.#pugService = pugService;
1009
+ this.#ejsService = ejsService;
1010
+ this.#nunjucksService = nunjucksService;
1011
+ this.#etaService = etaService;
1012
+ this.#mustacheService = mustacheService;
1013
+ }
1014
+ #limit = pLimit(3);
932
1015
  async generatePdfFromHtml(html, options) {
933
- return this.limit(async () => {
934
- const mergePuppeteerOptions = mergePuppeteerParameters(this.options, options);
1016
+ return this.#limit(async () => {
1017
+ const mergePuppeteerOptions = mergePuppeteerParameters(this.#options, options);
935
1018
  if (mergePuppeteerOptions.chromiumRevision !== void 0) Logger.warn("Using `chromiumRevision` is no longer supported since the puppeteer update.");
936
1019
  const headless = mergePuppeteerOptions.headless ?? true;
937
1020
  const executablePath = mergePuppeteerOptions.executablePath || void 0;
@@ -973,10 +1056,10 @@ let PuppeteerService = class PuppeteerService {
973
1056
  "--no-zygote",
974
1057
  "--disable-gpu"
975
1058
  ];
976
- this.browserService.markJobStarted();
1059
+ this.#browserService.markJobStarted();
977
1060
  let context = null;
978
1061
  try {
979
- context = await this.browserService.createContext(args, headless, executablePath);
1062
+ context = await this.#browserService.createContext(args, headless, executablePath);
980
1063
  const page = await context.newPage();
981
1064
  const pdfOptions = mergePuppeteerOptions.pdfOptions ?? { format: "A4" };
982
1065
  await page.setContent(html, { waitUntil: "domcontentloaded" });
@@ -990,71 +1073,72 @@ let PuppeteerService = class PuppeteerService {
990
1073
  return await page.pdf(pdfOptions);
991
1074
  } catch (e) {
992
1075
  Logger.error(e);
993
- throw e;
1076
+ if (e instanceof NestjsPdfException) throw e;
1077
+ throw new PdfGenerationException(`PDF generation failed: ${String(e)}`, { cause: e });
994
1078
  } finally {
995
1079
  if (context) try {
996
1080
  await context.close();
997
1081
  } catch (error) {
998
1082
  Logger.error(error);
999
1083
  }
1000
- await this.browserService.markJobFinished();
1084
+ await this.#browserService.markJobFinished();
1001
1085
  }
1002
1086
  });
1003
1087
  }
1004
1088
  async generatePdfFromTemplateHbsString(template, parameters = {}, options) {
1005
- const html = requireService(this.hbsService, "Handlebars").render(template, parameters, options?.hbsOptions ?? this.options.hbsOptions);
1089
+ const html = requireService(this.#hbsService, "Handlebars").render(template, parameters, options?.hbsOptions ?? this.#options.hbsOptions);
1006
1090
  return this.generatePdfFromHtml(html, options);
1007
1091
  }
1008
1092
  async generatePdfFromTemplateHbsFile(file, parameters = {}, options) {
1009
- const html = requireService(this.hbsService, "Handlebars").renderFile(file, parameters, options?.hbsOptions ?? this.options.hbsOptions);
1093
+ const html = requireService(this.#hbsService, "Handlebars").renderFile(file, parameters, options?.hbsOptions ?? this.#options.hbsOptions);
1010
1094
  return this.generatePdfFromHtml(html, options);
1011
1095
  }
1012
1096
  async generatePdfFromMjmlString(template, options) {
1013
- const html = await requireService(this.mjmlService, "MJML").render(template, options?.mjmlOptions ?? this.options.mjmlOptions);
1097
+ const html = await requireService(this.#mjmlService, "MJML").render(template, options?.mjmlOptions ?? this.#options.mjmlOptions);
1014
1098
  return this.generatePdfFromHtml(html, options);
1015
1099
  }
1016
1100
  async generatePdfFromMjmlFile(file, options) {
1017
- const html = await requireService(this.mjmlService, "MJML").renderFile(file, options?.mjmlOptions ?? this.options.mjmlOptions);
1101
+ const html = await requireService(this.#mjmlService, "MJML").renderFile(file, options?.mjmlOptions ?? this.#options.mjmlOptions);
1018
1102
  return this.generatePdfFromHtml(html, options);
1019
1103
  }
1020
1104
  async generatePdfFromPugString(template, data = {}, options) {
1021
- const html = requireService(this.pugService, "Pug").render(template, data, options?.pugOptions ?? this.options.pugOptions);
1105
+ const html = requireService(this.#pugService, "Pug").render(template, data, options?.pugOptions ?? this.#options.pugOptions);
1022
1106
  return this.generatePdfFromHtml(html, options);
1023
1107
  }
1024
1108
  async generatePdfFromPugFile(file, data = {}, options) {
1025
- const html = requireService(this.pugService, "Pug").renderFile(file, data, options?.pugOptions ?? this.options.pugOptions);
1109
+ const html = requireService(this.#pugService, "Pug").renderFile(file, data, options?.pugOptions ?? this.#options.pugOptions);
1026
1110
  return this.generatePdfFromHtml(html, options);
1027
1111
  }
1028
1112
  async generatePdfFromEjsString(template, data = {}, options) {
1029
- const html = await requireService(this.ejsService, "EJS").render(template, data, options?.ejsOptions ?? this.options.ejsOptions);
1113
+ const html = await requireService(this.#ejsService, "EJS").render(template, data, options?.ejsOptions ?? this.#options.ejsOptions);
1030
1114
  return this.generatePdfFromHtml(html, options);
1031
1115
  }
1032
1116
  async generatePdfFromEjsFile(file, data = {}, options) {
1033
- const html = await requireService(this.ejsService, "EJS").renderFile(file, data, options?.ejsOptions ?? this.options.ejsOptions);
1117
+ const html = await requireService(this.#ejsService, "EJS").renderFile(file, data, options?.ejsOptions ?? this.#options.ejsOptions);
1034
1118
  return this.generatePdfFromHtml(html, options);
1035
1119
  }
1036
1120
  async generatePdfFromNunjucksString(template, data = {}, options) {
1037
- const html = requireService(this.nunjucksService, "Nunjucks").render(template, data, options?.nunjucksOptions ?? this.options.nunjucksOptions);
1121
+ const html = requireService(this.#nunjucksService, "Nunjucks").render(template, data, options?.nunjucksOptions ?? this.#options.nunjucksOptions);
1038
1122
  return this.generatePdfFromHtml(html, options);
1039
1123
  }
1040
1124
  async generatePdfFromNunjucksFile(file, data = {}, options) {
1041
- const html = requireService(this.nunjucksService, "Nunjucks").renderFile(file, data, options?.nunjucksOptions ?? this.options.nunjucksOptions);
1125
+ const html = requireService(this.#nunjucksService, "Nunjucks").renderFile(file, data, options?.nunjucksOptions ?? this.#options.nunjucksOptions);
1042
1126
  return this.generatePdfFromHtml(html, options);
1043
1127
  }
1044
1128
  async generatePdfFromEtaString(template, data = {}, options) {
1045
- const html = requireService(this.etaService, "Eta").render(template, data, options?.etaOptions ?? this.options.etaOptions);
1129
+ const html = requireService(this.#etaService, "Eta").render(template, data, options?.etaOptions ?? this.#options.etaOptions);
1046
1130
  return this.generatePdfFromHtml(html, options);
1047
1131
  }
1048
1132
  async generatePdfFromEtaFile(file, data = {}, options) {
1049
- const html = requireService(this.etaService, "Eta").renderFile(file, data, options?.etaOptions ?? this.options.etaOptions);
1133
+ const html = requireService(this.#etaService, "Eta").renderFile(file, data, options?.etaOptions ?? this.#options.etaOptions);
1050
1134
  return this.generatePdfFromHtml(html, options);
1051
1135
  }
1052
1136
  async generatePdfFromMustacheString(template, data = {}, options) {
1053
- const html = requireService(this.mustacheService, "Mustache").render(template, data, options?.mustacheOptions ?? this.options.mustacheOptions);
1137
+ const html = requireService(this.#mustacheService, "Mustache").render(template, data, options?.mustacheOptions ?? this.#options.mustacheOptions);
1054
1138
  return this.generatePdfFromHtml(html, options);
1055
1139
  }
1056
1140
  async generatePdfFromMustacheFile(file, data = {}, options) {
1057
- const html = requireService(this.mustacheService, "Mustache").renderFile(file, data, options?.mustacheOptions ?? this.options.mustacheOptions);
1141
+ const html = requireService(this.#mustacheService, "Mustache").renderFile(file, data, options?.mustacheOptions ?? this.#options.mustacheOptions);
1058
1142
  return this.generatePdfFromHtml(html, options);
1059
1143
  }
1060
1144
  };
@@ -1083,9 +1167,9 @@ PuppeteerService = __decorate$3([
1083
1167
  //#endregion
1084
1168
  //#region src/nestjs-pdf.service.ts
1085
1169
  let NestjsPdfService = class NestjsPdfService {
1086
- puppeteerService;
1170
+ #puppeteerService;
1087
1171
  constructor(puppeteerService) {
1088
- this.puppeteerService = puppeteerService;
1172
+ this.#puppeteerService = puppeteerService;
1089
1173
  }
1090
1174
  /**
1091
1175
  * @param html HTML string to convert to PDF
@@ -1094,7 +1178,7 @@ let NestjsPdfService = class NestjsPdfService {
1094
1178
  * @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.
1095
1179
  */
1096
1180
  generatePdfFromHtml(html, options) {
1097
- return this.puppeteerService.generatePdfFromHtml(html, options);
1181
+ return this.#puppeteerService.generatePdfFromHtml(html, options);
1098
1182
  }
1099
1183
  /**
1100
1184
  * @param template Handlebars template string
@@ -1104,7 +1188,7 @@ let NestjsPdfService = class NestjsPdfService {
1104
1188
  * @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.
1105
1189
  */
1106
1190
  generatePdfFromTemplateHbsString(template, parameters = {}, options) {
1107
- return this.puppeteerService.generatePdfFromTemplateHbsString(template, parameters, options);
1191
+ return this.#puppeteerService.generatePdfFromTemplateHbsString(template, parameters, options);
1108
1192
  }
1109
1193
  /**
1110
1194
  * @param file Path to the Handlebars template file
@@ -1114,7 +1198,7 @@ let NestjsPdfService = class NestjsPdfService {
1114
1198
  * @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.
1115
1199
  */
1116
1200
  generatePdfFromTemplateHbsFile(file, parameters = {}, options) {
1117
- return this.puppeteerService.generatePdfFromTemplateHbsFile(file, parameters, options);
1201
+ return this.#puppeteerService.generatePdfFromTemplateHbsFile(file, parameters, options);
1118
1202
  }
1119
1203
  /**
1120
1204
  * @param template MJML template string
@@ -1123,7 +1207,7 @@ let NestjsPdfService = class NestjsPdfService {
1123
1207
  * @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.
1124
1208
  */
1125
1209
  generatePdfFromMjmlString(template, options) {
1126
- return this.puppeteerService.generatePdfFromMjmlString(template, options);
1210
+ return this.#puppeteerService.generatePdfFromMjmlString(template, options);
1127
1211
  }
1128
1212
  /**
1129
1213
  * @param file Path to the MJML template file
@@ -1132,7 +1216,7 @@ let NestjsPdfService = class NestjsPdfService {
1132
1216
  * @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.
1133
1217
  */
1134
1218
  generatePdfFromMjmlFile(file, options) {
1135
- return this.puppeteerService.generatePdfFromMjmlFile(file, options);
1219
+ return this.#puppeteerService.generatePdfFromMjmlFile(file, options);
1136
1220
  }
1137
1221
  /**
1138
1222
  * @param template EJS template string
@@ -1142,7 +1226,7 @@ let NestjsPdfService = class NestjsPdfService {
1142
1226
  * @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.
1143
1227
  */
1144
1228
  generatePdfFromEjsString(template, data = {}, options) {
1145
- return this.puppeteerService.generatePdfFromEjsString(template, data, options);
1229
+ return this.#puppeteerService.generatePdfFromEjsString(template, data, options);
1146
1230
  }
1147
1231
  /**
1148
1232
  * @param file Path to the EJS template file
@@ -1152,7 +1236,7 @@ let NestjsPdfService = class NestjsPdfService {
1152
1236
  * @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.
1153
1237
  */
1154
1238
  generatePdfFromEjsFile(file, data = {}, options) {
1155
- return this.puppeteerService.generatePdfFromEjsFile(file, data, options);
1239
+ return this.#puppeteerService.generatePdfFromEjsFile(file, data, options);
1156
1240
  }
1157
1241
  /**
1158
1242
  * @param template Pug template string
@@ -1162,7 +1246,7 @@ let NestjsPdfService = class NestjsPdfService {
1162
1246
  * @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.
1163
1247
  */
1164
1248
  generatePdfFromPugString(template, data = {}, options) {
1165
- return this.puppeteerService.generatePdfFromPugString(template, data, options);
1249
+ return this.#puppeteerService.generatePdfFromPugString(template, data, options);
1166
1250
  }
1167
1251
  /**
1168
1252
  * @param file Path to the Pug template file
@@ -1172,7 +1256,7 @@ let NestjsPdfService = class NestjsPdfService {
1172
1256
  * @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.
1173
1257
  */
1174
1258
  generatePdfFromPugFile(file, data = {}, options) {
1175
- return this.puppeteerService.generatePdfFromPugFile(file, data, options);
1259
+ return this.#puppeteerService.generatePdfFromPugFile(file, data, options);
1176
1260
  }
1177
1261
  /**
1178
1262
  * @param template Nunjucks template string
@@ -1182,7 +1266,7 @@ let NestjsPdfService = class NestjsPdfService {
1182
1266
  * @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.
1183
1267
  */
1184
1268
  generatePdfFromNunjucksString(template, data = {}, options) {
1185
- return this.puppeteerService.generatePdfFromNunjucksString(template, data, options);
1269
+ return this.#puppeteerService.generatePdfFromNunjucksString(template, data, options);
1186
1270
  }
1187
1271
  /**
1188
1272
  * @param file Path to the Nunjucks template file
@@ -1192,7 +1276,7 @@ let NestjsPdfService = class NestjsPdfService {
1192
1276
  * @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.
1193
1277
  */
1194
1278
  generatePdfFromNunjucksFile(file, data = {}, options) {
1195
- return this.puppeteerService.generatePdfFromNunjucksFile(file, data, options);
1279
+ return this.#puppeteerService.generatePdfFromNunjucksFile(file, data, options);
1196
1280
  }
1197
1281
  /**
1198
1282
  * @param template Eta template string
@@ -1202,7 +1286,7 @@ let NestjsPdfService = class NestjsPdfService {
1202
1286
  * @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.
1203
1287
  */
1204
1288
  generatePdfFromEtaString(template, data = {}, options) {
1205
- return this.puppeteerService.generatePdfFromEtaString(template, data, options);
1289
+ return this.#puppeteerService.generatePdfFromEtaString(template, data, options);
1206
1290
  }
1207
1291
  /**
1208
1292
  * @param file Path to the Eta template file
@@ -1212,7 +1296,7 @@ let NestjsPdfService = class NestjsPdfService {
1212
1296
  * @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.
1213
1297
  */
1214
1298
  generatePdfFromEtaFile(file, data = {}, options) {
1215
- return this.puppeteerService.generatePdfFromEtaFile(file, data, options);
1299
+ return this.#puppeteerService.generatePdfFromEtaFile(file, data, options);
1216
1300
  }
1217
1301
  /**
1218
1302
  * @param template Mustache template string
@@ -1222,7 +1306,7 @@ let NestjsPdfService = class NestjsPdfService {
1222
1306
  * @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.
1223
1307
  */
1224
1308
  generatePdfFromMustacheString(template, data = {}, options) {
1225
- return this.puppeteerService.generatePdfFromMustacheString(template, data, options);
1309
+ return this.#puppeteerService.generatePdfFromMustacheString(template, data, options);
1226
1310
  }
1227
1311
  /**
1228
1312
  * @param file Path to the Mustache template file
@@ -1232,7 +1316,7 @@ let NestjsPdfService = class NestjsPdfService {
1232
1316
  * @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.
1233
1317
  */
1234
1318
  generatePdfFromMustacheFile(file, data = {}, options) {
1235
- return this.puppeteerService.generatePdfFromMustacheFile(file, data, options);
1319
+ return this.#puppeteerService.generatePdfFromMustacheFile(file, data, options);
1236
1320
  }
1237
1321
  /**
1238
1322
  * @param pdf The PDF bytes to modify
@@ -2533,14 +2617,14 @@ ConfigModule = ConfigModule_1 = __decorate([Module({
2533
2617
  //#region src/puppeteer/puppeteer.module.ts
2534
2618
  var _PuppeteerModule;
2535
2619
  let PuppeteerModule = _PuppeteerModule = class PuppeteerModule {
2536
- browserService;
2537
- pdfParams;
2620
+ #browserService;
2621
+ #pdfParams;
2538
2622
  constructor(browserService, pdfParams) {
2539
- this.browserService = browserService;
2540
- this.pdfParams = pdfParams;
2623
+ this.#browserService = browserService;
2624
+ this.#pdfParams = pdfParams;
2541
2625
  }
2542
2626
  async onModuleInit() {
2543
- if (!this.pdfParams.executablePath) await this.browserService.install(this.pdfParams.useLockedBrowser ?? false);
2627
+ if (!this.#pdfParams.executablePath) await this.#browserService.install(this.#pdfParams.useLockedBrowser ?? false);
2544
2628
  }
2545
2629
  static forRoot(pdfParameters) {
2546
2630
  const providers = [
@@ -2652,6 +2736,6 @@ let NestjsPdfModule = _NestjsPdfModule = class NestjsPdfModule {
2652
2736
  };
2653
2737
  NestjsPdfModule = _NestjsPdfModule = __decorate$3([Module({})], NestjsPdfModule);
2654
2738
  //#endregion
2655
- export { EjsService, EtaService, HandlebarsService, MjmlService, MustacheService, NestjsPdfModule, NestjsPdfService, NunjucksService, PugService, PuppeteerModule, PuppeteerService, getRelativePathToValue };
2739
+ export { BrowserInstallationException, BrowserUnavailableException, EjsService, EngineNotAvailableException, EtaService, HandlebarsService, MjmlService, MustacheService, NestjsPdfErrorCode, NestjsPdfException, NestjsPdfModule, NestjsPdfService, NunjucksService, PdfGenerationException, PugService, PuppeteerModule, PuppeteerService, SignatureDependencyException, SignaturePlacementException, TemplateConfigurationException, TemplateRenderException, getRelativePathToValue };
2656
2740
 
2657
2741
  //# sourceMappingURL=index.mjs.map