@shad0wz7/nestjs-pdf 3.0.0 → 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,7 +137,7 @@ async function loadPdfjs() {
70
137
  pdfjsPromise = await import("pdfjs-dist/legacy/build/pdf.mjs");
71
138
  } catch (error) {
72
139
  pdfjsPromise = void 0;
73
- throw new Error([
140
+ throw new SignatureDependencyException([
74
141
  "Failed to load pdfjs-dist.",
75
142
  "If you use anchor-based signature placement in Node.js, make sure @napi-rs/canvas is installed.",
76
143
  "Try: npm install @napi-rs/canvas",
@@ -116,7 +183,6 @@ function addSignatureFieldAt(pdfDoc, pageIndex, opts) {
116
183
  const { fieldName, x, y, width, height } = opts;
117
184
  const context = pdfDoc.context;
118
185
  const page = pdfDoc.getPages()[pageIndex];
119
- if (!page) throw new Error(`Page ${pageIndex} not found`);
120
186
  const rectArray = context.obj([
121
187
  pdf_lib.PDFNumber.of(x),
122
188
  pdf_lib.PDFNumber.of(y),
@@ -173,7 +239,9 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
173
239
  const sigHeight = 50;
174
240
  if (anchor) {
175
241
  const pageIndex = anchor.pageIndex;
176
- const { width: pw, height: ph } = pdfDoc.getPages()[pageIndex].getSize();
242
+ const page = pdfDoc.getPages()[pageIndex];
243
+ if (!page) throw new SignaturePlacementException(`Page ${pageIndex} not found`);
244
+ const { width: pw, height: ph } = page.getSize();
177
245
  const padX = 40;
178
246
  const padY = 7;
179
247
  let x = anchor.x - sigWidth / 2 + padX;
@@ -191,7 +259,10 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
191
259
  } else {
192
260
  const pages = pdfDoc.getPages();
193
261
  const pageIndex = pages.length - 1;
194
- const { width: pageWidth } = pages[pageIndex].getSize();
262
+ const page = pages.at(-1);
263
+ /* v8 ignore next -- pdf-lib always produces at least one page on save/load; only a hand-crafted, malformed PDF could hit this */
264
+ if (!page) throw new SignaturePlacementException(`Page ${pageIndex} not found`);
265
+ const { width: pageWidth } = page.getSize();
195
266
  addSignatureFieldAt(pdfDoc, pageIndex, {
196
267
  fieldName,
197
268
  x: (pageWidth - sigWidth) / 2,
@@ -339,19 +410,19 @@ function mergePuppeteerParameters(defaults, overrides) {
339
410
  //#region src/helpers/tokens.ts
340
411
  const PDF_PARAMETERS = "PDF_PARAMETERS";
341
412
  //#endregion
342
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorateMetadata.js
413
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateMetadata.js
343
414
  function __decorateMetadata(k, v) {
344
415
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
345
416
  }
346
417
  //#endregion
347
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorateParam.js
418
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
348
419
  function __decorateParam(paramIndex, decorator) {
349
420
  return function(target, key) {
350
421
  decorator(target, key, paramIndex);
351
422
  };
352
423
  }
353
424
  //#endregion
354
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorate.js
425
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
355
426
  function __decorate$3(decorators, target, key, desc) {
356
427
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
357
428
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -381,47 +452,47 @@ function isTargetClosedError(error) {
381
452
  return error.name === "TargetCloseError" || error.message.includes("Target closed") || error.message.includes("Target.createTarget");
382
453
  }
383
454
  let BrowserService = class BrowserService {
384
- cacheDir;
385
- options;
386
- _browserInstance = null;
387
- browser;
455
+ #cacheDir;
456
+ #options;
457
+ #browserInstance = null;
458
+ #browser;
388
459
  activeJobs = 0;
389
460
  totalJobs = 0;
390
- recycleRequested = false;
391
- recycling = false;
392
- shuttingDown = false;
461
+ #recycleRequested = false;
462
+ #recycling = false;
463
+ #shuttingDown = false;
393
464
  /** Max time to wait for in-flight PDF jobs to finish before closing the browser on shutdown. */
394
465
  shutdownDrainTimeoutMs = 15e3;
395
- browserTag;
396
- useLockedBrowser;
397
- buildId;
466
+ #browserTag;
467
+ #useLockedBrowser;
468
+ #buildId;
398
469
  constructor(pdfParams) {
399
- this.cacheDir = (0, node_path.resolve)(".cache/puppeteer-browser");
400
- this.options = pdfParams;
401
- this.loadBuildId();
402
- this.loadBrowser();
403
- this.loadBrowserTag();
404
- 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();
405
476
  }
406
477
  async onModuleDestroy() {
407
- this.shuttingDown = true;
408
- await this.waitForIdle(this.shutdownDrainTimeoutMs);
409
- if (this._browserInstance?.connected) try {
410
- 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();
411
482
  } catch (error) {
412
483
  _nestjs_common.Logger.warn(`Failed to close browser on module destroy: ${error instanceof Error ? error.message : String(error)}`);
413
484
  }
414
- if (this.options?.cleanupBrowserCacheOnExit !== false) await this.cleanupCacheBestEffort();
485
+ if (this.#options?.cleanupBrowserCacheOnExit !== false) await this.#cleanupCacheBestEffort();
415
486
  }
416
487
  /** Wait until no PDF job is in flight, or until the timeout elapses. */
417
- async waitForIdle(timeoutMs) {
488
+ async #waitForIdle(timeoutMs) {
418
489
  const start = Date.now();
419
490
  while (this.activeJobs > 0 && Date.now() - start < timeoutMs) await sleep(50);
420
491
  if (this.activeJobs > 0) _nestjs_common.Logger.warn(`Shutdown: ${this.activeJobs} PDF job(s) still running after ${timeoutMs}ms, closing the browser anyway`);
421
492
  }
422
493
  async getBrowserInstance(args, headless, executablePathBin) {
423
- if (!this._browserInstance?.connected) this._browserInstance = await this.launchBrowser(args, headless, executablePathBin);
424
- return this._browserInstance;
494
+ if (!this.#browserInstance?.connected) this.#browserInstance = await this.#launchBrowser(args, headless, executablePathBin);
495
+ return this.#browserInstance;
425
496
  }
426
497
  async createContext(args, headless, executablePath) {
427
498
  const browser = await this.getBrowserInstance(args, headless, executablePath);
@@ -430,41 +501,41 @@ let BrowserService = class BrowserService {
430
501
  } catch (error) {
431
502
  if (!isTargetClosedError(error)) throw error;
432
503
  _nestjs_common.Logger.warn("Puppeteer browser closed while creating a context, retrying once");
433
- this._browserInstance = null;
504
+ this.#browserInstance = null;
434
505
  return await (await this.getBrowserInstance(args, headless, executablePath)).createBrowserContext();
435
506
  }
436
507
  }
437
508
  markJobStarted() {
438
- 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");
439
510
  this.activeJobs += 1;
440
511
  this.totalJobs += 1;
441
- if (this.totalJobs >= 200) this.recycleRequested = true;
512
+ if (this.totalJobs >= 200) this.#recycleRequested = true;
442
513
  }
443
514
  async markJobFinished() {
444
515
  this.activeJobs = Math.max(0, this.activeJobs - 1);
445
516
  await this.recycleBrowserIfNeeded();
446
517
  }
447
518
  async recycleBrowserIfNeeded() {
448
- if (!this.recycleRequested) return;
449
- if (this.recycling) return;
519
+ if (!this.#recycleRequested) return;
520
+ if (this.#recycling) return;
450
521
  if (this.activeJobs > 0) return;
451
- if (!this._browserInstance) return;
452
- this.recycling = true;
522
+ if (!this.#browserInstance) return;
523
+ this.#recycling = true;
453
524
  try {
454
- if (this._browserInstance.connected) await this._browserInstance.close();
455
- this._browserInstance = null;
525
+ if (this.#browserInstance.connected) await this.#browserInstance.close();
526
+ this.#browserInstance = null;
456
527
  this.totalJobs = 0;
457
- this.recycleRequested = false;
528
+ this.#recycleRequested = false;
458
529
  _nestjs_common.Logger.log("Puppeteer browser recycled successfully");
459
530
  } catch (error) {
460
531
  _nestjs_common.Logger.warn(`Failed to recycle browser: ${error instanceof Error ? error.message : String(error)}`);
461
532
  } finally {
462
- this.recycling = false;
533
+ this.#recycling = false;
463
534
  }
464
535
  }
465
- async cleanupCacheBestEffort() {
536
+ async #cleanupCacheBestEffort() {
466
537
  const logger = new _nestjs_common.Logger("NestJsPdf");
467
- const dir = this.cacheDir;
538
+ const dir = this.#cacheDir;
468
539
  try {
469
540
  if (!(0, node_fs.existsSync)(dir)) return;
470
541
  logger.log(`Cleanup puppeteer cache: ${dir}`);
@@ -485,100 +556,109 @@ let BrowserService = class BrowserService {
485
556
  }
486
557
  }
487
558
  async install(lock = false) {
488
- const browser = this.browser;
489
- 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;
490
569
  const browserPlatform = (0, _puppeteer_browsers.detectBrowserPlatform)() ?? _puppeteer_browsers.BrowserPlatform.LINUX;
491
570
  let buildId;
492
- if (this.buildId === void 0) buildId = await (0, _puppeteer_browsers.resolveBuildId)(browser, browserPlatform, versionTag);
493
- else buildId = this.buildId;
571
+ if (this.#buildId === void 0) buildId = await (0, _puppeteer_browsers.resolveBuildId)(browser, browserPlatform, versionTag);
572
+ else buildId = this.#buildId;
494
573
  _nestjs_common.Logger.log(`Browser ${browser} ${versionTag} build id: ${buildId}`, "NestJsPdf");
495
574
  if (await this.hasBrowserInstalled(browser, buildId)) {
496
575
  _nestjs_common.Logger.log("Browser already installed", "NestJsPdf");
497
- if (lock) this.writeLockFile(browser, buildId);
576
+ if (lock) this.#writeLockFile(browser, buildId);
498
577
  return;
499
578
  } else {
500
579
  _nestjs_common.Logger.log("Starting browser installation", "NestJsPdf");
501
580
  const installOption = {
502
- cacheDir: this.cacheDir,
581
+ cacheDir: this.#cacheDir,
503
582
  browser,
504
583
  buildId,
505
- baseUrl: this.options?.browserInstallBaseUrl ?? void 0
584
+ baseUrl: this.#options?.browserInstallBaseUrl ?? void 0
506
585
  };
507
586
  if (await (0, _puppeteer_browsers.canDownload)(installOption)) {
508
587
  _nestjs_common.Logger.log(`Installing ${installOption.browser} ${installOption.buildId}`, "NestJsPdf");
509
588
  const installedBrowser = await (0, _puppeteer_browsers.install)(installOption);
510
589
  if (await this.hasBrowserInstalled(browser, buildId)) {
511
590
  _nestjs_common.Logger.log("Browser installed successfully", "NestJsPdf");
512
- if (lock) this.writeLockFile(browser, buildId);
591
+ if (lock) this.#writeLockFile(browser, buildId);
513
592
  return installedBrowser;
514
593
  } else _nestjs_common.Logger.error("Browser installation failed", "NestJsPdf");
515
594
  } else _nestjs_common.Logger.error(`Error, can't install ${installOption.browser} ${installOption.buildId}`, "NestJsPdf");
516
595
  }
517
596
  return null;
518
597
  }
519
- loadBrowser() {
598
+ #loadBrowser() {
520
599
  let browser;
521
- if (this.options?.browser === void 0) browser = _puppeteer_browsers.Browser.CHROMIUM;
522
- else browser = this.options.browser;
523
- 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;
524
603
  }
525
604
  getBrowser() {
526
- return this.browser;
605
+ return this.#browser;
527
606
  }
528
- loadBrowserTag() {
607
+ #loadBrowserTag() {
529
608
  let versionTag;
530
- if (this.options?.browserTag === void 0) if (this.browser === _puppeteer_browsers.Browser.CHROMIUM) versionTag = "latest";
531
- else versionTag = "stable";
532
- else versionTag = this.options.browserTag;
533
- this.browserTag = versionTag;
609
+ if (this.#options?.browserTag === void 0) {
610
+ if (this.#browser === _puppeteer_browsers.Browser.CHROMIUM) versionTag = "latest";
611
+ else versionTag = "stable";
612
+ } else versionTag = this.#options.browserTag;
613
+ this.#browserTag = versionTag;
534
614
  }
535
- loadBuildId() {
615
+ #loadBuildId() {
536
616
  let buildId;
537
- if (this.options?.buildId === void 0) buildId = void 0;
538
- else buildId = this.options.buildId;
539
- this.buildId = buildId;
617
+ if (this.#options?.buildId === void 0) buildId = void 0;
618
+ else buildId = this.#options.buildId;
619
+ this.#buildId = buildId;
540
620
  }
541
621
  setBrowserTag(browserTag) {
542
- this.browserTag = browserTag;
622
+ this.#browserTag = browserTag;
543
623
  }
544
624
  getBrowserTag() {
545
- return this.browserTag;
625
+ return this.#browserTag;
546
626
  }
547
627
  getBuildId() {
548
- return this.buildId;
628
+ return this.#buildId;
549
629
  }
550
- loadUseLockedBrowser() {
630
+ #loadUseLockedBrowser() {
551
631
  let useLockedBrowser;
552
- if (this.options?.useLockedBrowser === void 0) useLockedBrowser = false;
553
- else useLockedBrowser = this.options.useLockedBrowser;
554
- this.useLockedBrowser = useLockedBrowser;
632
+ if (this.#options?.useLockedBrowser === void 0) useLockedBrowser = false;
633
+ else useLockedBrowser = this.#options.useLockedBrowser;
634
+ this.#useLockedBrowser = useLockedBrowser;
555
635
  }
556
636
  async hasBrowserInstalled(browser, buildId) {
557
- return (await (0, _puppeteer_browsers.getInstalledBrowsers)({ cacheDir: this.cacheDir })).find((insBrowser) => {
637
+ return (await (0, _puppeteer_browsers.getInstalledBrowsers)({ cacheDir: this.#cacheDir })).find((insBrowser) => {
558
638
  return insBrowser.browser === browser && insBrowser.buildId === buildId;
559
639
  }) !== void 0;
560
640
  }
561
641
  async getExecutablePath() {
562
- const browser = this.browser;
563
- const versionTag = this.browserTag;
642
+ const browser = this.#browser;
643
+ const versionTag = this.#browserTag;
564
644
  const browserPlatform = (0, _puppeteer_browsers.detectBrowserPlatform)() ?? _puppeteer_browsers.BrowserPlatform.LINUX;
565
645
  let buildId = null;
566
- if (this.useLockedBrowser) {
646
+ if (this.#useLockedBrowser) {
567
647
  buildId = this.getLockedBuildId(browser);
568
648
  _nestjs_common.Logger.log(`Using locked browser ${buildId}`, "NestJsPdf");
569
649
  }
570
650
  buildId ??= await (0, _puppeteer_browsers.resolveBuildId)(browser, browserPlatform, versionTag);
571
- 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) => {
572
652
  return insBrowser.browser === browser && insBrowser.buildId === buildId;
573
653
  });
574
654
  if (installedBrowser === void 0) {
575
655
  const newinstalledBrowser = await this.install();
576
- 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");
577
657
  else return newinstalledBrowser.executablePath;
578
658
  }
579
659
  return installedBrowser.executablePath;
580
660
  }
581
- async launchBrowser(args, headless, executablePathBin) {
661
+ async #launchBrowser(args, headless, executablePathBin) {
582
662
  const executablePath = executablePathBin ?? await this.getExecutablePath();
583
663
  const browser = await (0, puppeteer.launch)({
584
664
  executablePath,
@@ -587,12 +667,12 @@ let BrowserService = class BrowserService {
587
667
  });
588
668
  browser.on("disconnected", () => {
589
669
  _nestjs_common.Logger.warn("Puppeteer browser disconnected");
590
- if (this._browserInstance === browser) this._browserInstance = null;
670
+ if (this.#browserInstance === browser) this.#browserInstance = null;
591
671
  });
592
672
  return browser;
593
673
  }
594
- writeLockFile(browser, buildId) {
595
- 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`);
596
676
  const data = JSON.stringify({
597
677
  browser,
598
678
  buildId,
@@ -602,7 +682,7 @@ let BrowserService = class BrowserService {
602
682
  _nestjs_common.Logger.log(`Browser ${browser} locked to build ${buildId}`, "NestJsPdf");
603
683
  }
604
684
  getLockedBuildId(browser) {
605
- const lockFile = (0, node_path.resolve)(this.cacheDir, `${browser}.lock`);
685
+ const lockFile = (0, node_path.resolve)(this.#cacheDir, `${browser}.lock`);
606
686
  if ((0, node_fs.existsSync)(lockFile)) {
607
687
  const data = (0, node_fs.readFileSync)(lockFile);
608
688
  return JSON.parse(data.toString()).buildId;
@@ -625,7 +705,7 @@ let EjsService = class EjsService {
625
705
  ...options
626
706
  });
627
707
  } catch (error) {
628
- throw new Error(`EJS rendering failed: ${String(error)}`, { cause: error });
708
+ throw new TemplateRenderException("EJS", `EJS rendering failed: ${String(error)}`, { cause: error });
629
709
  }
630
710
  }
631
711
  async renderFile(filePath, data = {}, options) {
@@ -635,7 +715,7 @@ let EjsService = class EjsService {
635
715
  ...options
636
716
  });
637
717
  } catch (error) {
638
- throw new Error(`EJS file rendering failed: ${String(error)}`, { cause: error });
718
+ throw new TemplateRenderException("EJS", `EJS file rendering failed: ${String(error)}`, { cause: error });
639
719
  }
640
720
  }
641
721
  };
@@ -643,11 +723,11 @@ EjsService = __decorate$3([(0, _nestjs_common.Injectable)()], EjsService);
643
723
  //#endregion
644
724
  //#region src/puppeteer/engines/eta/eta.service.ts
645
725
  let EtaService = class EtaService {
646
- eta;
647
- templateCache = /* @__PURE__ */ new Map();
648
- maxCacheSize = 100;
726
+ #eta;
727
+ #templateCache = /* @__PURE__ */ new Map();
728
+ #maxCacheSize = 100;
649
729
  constructor() {
650
- this.eta = new eta.Eta({
730
+ this.#eta = new eta.Eta({
651
731
  cache: true,
652
732
  autoEscape: true,
653
733
  useWith: true
@@ -668,9 +748,9 @@ let EtaService = class EtaService {
668
748
  useWith: true,
669
749
  ...options,
670
750
  varName: options.varName ?? "it"
671
- }) : this.eta).renderString(template, data);
751
+ }) : this.#eta).renderString(template, data);
672
752
  } catch (error) {
673
- throw new Error(`Eta rendering failed: ${String(error)}`, { cause: error });
753
+ throw new TemplateRenderException("Eta", `Eta rendering failed: ${String(error)}`, { cause: error });
674
754
  }
675
755
  }
676
756
  /**
@@ -684,53 +764,54 @@ let EtaService = class EtaService {
684
764
  try {
685
765
  const resolvedPath = (0, node_path.resolve)(filePath);
686
766
  const useCache = options?.cache ?? true;
687
- let template = useCache ? this.templateCache.get(resolvedPath) : void 0;
767
+ let template = useCache ? this.#templateCache.get(resolvedPath) : void 0;
688
768
  if (!template) {
689
769
  template = (0, node_fs.readFileSync)(resolvedPath, "utf-8");
690
- 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);
691
771
  }
692
772
  return this.render(template, data, options);
693
773
  } catch (error) {
694
- 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 });
695
775
  }
696
776
  }
697
777
  /**
698
778
  * Clear the template cache
699
779
  */
700
780
  clearCache() {
701
- this.templateCache.clear();
781
+ this.#templateCache.clear();
702
782
  }
703
783
  /**
704
784
  * Get the current cache size
705
785
  * @returns The number of cached templates
706
786
  */
707
787
  getCacheSize() {
708
- return this.templateCache.size;
788
+ return this.#templateCache.size;
709
789
  }
710
790
  };
711
791
  EtaService = __decorate$3([(0, _nestjs_common.Injectable)(), __decorateMetadata("design:paramtypes", [])], EtaService);
712
792
  //#endregion
713
793
  //#region src/puppeteer/engines/handlebars/handlebars.service.ts
714
794
  let HandlebarsService = class HandlebarsService {
715
- cachedOptions;
716
- cachedEnv;
795
+ #cachedOptions;
796
+ #cachedEnv;
717
797
  render(template, parameters = {}, options = {}) {
718
798
  try {
719
- return this.getEnv(options).compile(template, options.compileOptions)(parameters, options.templateOptions);
799
+ return this.#getEnv(options).compile(template, options.compileOptions)(parameters, options.templateOptions);
720
800
  } catch (error) {
721
- 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 });
722
803
  }
723
804
  }
724
805
  renderFile(file, parameters = {}, options = {}) {
725
- 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");
726
807
  const baseDir = (0, node_path.resolve)(process.cwd(), options.templateDirectory);
727
808
  const templatePath = (0, node_path.resolve)(baseDir, file);
728
- 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\``);
729
810
  let template;
730
811
  try {
731
812
  template = (0, node_fs.readFileSync)(templatePath, "utf8");
732
813
  } catch (error) {
733
- throw new Error(`Handlebars file rendering failed: ${String(error)}`, { cause: error });
814
+ throw new TemplateRenderException("Handlebars", `Handlebars file rendering failed: ${String(error)}`, { cause: error });
734
815
  }
735
816
  return this.render(template, parameters, options);
736
817
  }
@@ -739,19 +820,19 @@ let HandlebarsService = class HandlebarsService {
739
820
  * nothing leaks into the global Handlebars. Memoised for the common case where
740
821
  * the same options object is reused across calls (e.g. the module `hbsOptions`).
741
822
  */
742
- getEnv(options) {
743
- if (this.cachedEnv && this.cachedOptions === options) return this.cachedEnv;
823
+ #getEnv(options) {
824
+ if (this.#cachedEnv && this.#cachedOptions === options) return this.#cachedEnv;
744
825
  const env = handlebars.default.create();
745
826
  for (const helper of options.helpers ?? []) env.registerHelper(helper.name, helper.fn);
746
- this.registerPartials(env, options.partialDirectory);
747
- this.cachedOptions = options;
748
- this.cachedEnv = env;
827
+ this.#registerPartials(env, options.partialDirectory);
828
+ this.#cachedOptions = options;
829
+ this.#cachedEnv = env;
749
830
  return env;
750
831
  }
751
- registerPartials(env, partialDirectory) {
832
+ #registerPartials(env, partialDirectory) {
752
833
  if (partialDirectory === void 0) return;
753
834
  const partialPath = (0, node_path.join)(process.cwd(), partialDirectory);
754
- 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}`);
755
836
  for (const entry of (0, node_fs.readdirSync)(partialPath)) {
756
837
  const filePath = (0, node_path.join)(partialPath, entry);
757
838
  if (!(0, node_fs.statSync)(filePath).isFile()) continue;
@@ -764,11 +845,20 @@ HandlebarsService = __decorate$3([(0, _nestjs_common.Injectable)()], HandlebarsS
764
845
  //#region src/puppeteer/engines/mjml/mjml.service.ts
765
846
  let MjmlService = class MjmlService {
766
847
  async render(template, options) {
767
- const { html } = await (0, mjml.default)(template, options);
768
- 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
+ }
769
854
  }
770
855
  async renderFile(filePath, options) {
771
- 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
+ }
772
862
  return await this.render(template, options);
773
863
  }
774
864
  };
@@ -776,8 +866,8 @@ MjmlService = __decorate$3([(0, _nestjs_common.Injectable)()], MjmlService);
776
866
  //#endregion
777
867
  //#region src/puppeteer/engines/mustache/mustache.service.ts
778
868
  let MustacheService = class MustacheService {
779
- templateCache = /* @__PURE__ */ new Map();
780
- maxCacheSize = 100;
869
+ #templateCache = /* @__PURE__ */ new Map();
870
+ #maxCacheSize = 100;
781
871
  /**
782
872
  * Render a Mustache template from a string
783
873
  * @param template The template string to render
@@ -793,7 +883,7 @@ let MustacheService = class MustacheService {
793
883
  escape: options?.escape
794
884
  });
795
885
  } catch (error) {
796
- throw new Error(`Mustache rendering failed: ${String(error)}`, { cause: error });
886
+ throw new TemplateRenderException("Mustache", `Mustache rendering failed: ${String(error)}`, { cause: error });
797
887
  }
798
888
  }
799
889
  /**
@@ -806,28 +896,28 @@ let MustacheService = class MustacheService {
806
896
  renderFile(filePath, data = {}, options) {
807
897
  try {
808
898
  const resolvedPath = (0, node_path.resolve)(filePath);
809
- let template = this.templateCache.get(resolvedPath);
899
+ let template = this.#templateCache.get(resolvedPath);
810
900
  if (!template) {
811
901
  template = (0, node_fs.readFileSync)(resolvedPath, "utf-8");
812
- if (this.templateCache.size < this.maxCacheSize) this.templateCache.set(resolvedPath, template);
902
+ if (this.#templateCache.size < this.#maxCacheSize) this.#templateCache.set(resolvedPath, template);
813
903
  }
814
904
  return this.render(template, data, options);
815
905
  } catch (error) {
816
- 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 });
817
907
  }
818
908
  }
819
909
  /**
820
910
  * Clear the template cache
821
911
  */
822
912
  clearCache() {
823
- this.templateCache.clear();
913
+ this.#templateCache.clear();
824
914
  }
825
915
  /**
826
916
  * Get the current cache size
827
917
  * @returns The number of cached templates
828
918
  */
829
919
  getCacheSize() {
830
- return this.templateCache.size;
920
+ return this.#templateCache.size;
831
921
  }
832
922
  };
833
923
  MustacheService = __decorate$3([(0, _nestjs_common.Injectable)()], MustacheService);
@@ -855,7 +945,7 @@ let NunjucksService = class NunjucksService {
855
945
  }
856
946
  return nunjucks.default.renderString(template, data);
857
947
  } catch (error) {
858
- throw new Error(`Nunjucks rendering failed: ${String(error)}`, { cause: error });
948
+ throw new TemplateRenderException("Nunjucks", `Nunjucks rendering failed: ${String(error)}`, { cause: error });
859
949
  }
860
950
  }
861
951
  renderFile(filePath, data = {}, options) {
@@ -872,7 +962,7 @@ let NunjucksService = class NunjucksService {
872
962
  }
873
963
  return nunjucks.default.render(filePath, data);
874
964
  } catch (error) {
875
- throw new Error(`Nunjucks file rendering failed: ${String(error)}`, { cause: error });
965
+ throw new TemplateRenderException("Nunjucks", `Nunjucks file rendering failed: ${String(error)}`, { cause: error });
876
966
  }
877
967
  }
878
968
  };
@@ -884,7 +974,7 @@ let PugService = class PugService {
884
974
  try {
885
975
  return pug.default.compile(template, { ...options })(data);
886
976
  } catch (error) {
887
- throw new Error(`Pug rendering failed: ${String(error)}`, { cause: error });
977
+ throw new TemplateRenderException("Pug", `Pug rendering failed: ${String(error)}`, { cause: error });
888
978
  }
889
979
  }
890
980
  renderFile(filePath, data = {}, options) {
@@ -892,7 +982,7 @@ let PugService = class PugService {
892
982
  const template = (0, node_fs.readFileSync)(filePath, "utf-8");
893
983
  return this.render(template, data, options);
894
984
  } catch (error) {
895
- throw new Error(`Pug file rendering failed: ${String(error)}`, { cause: error });
985
+ throw new TemplateRenderException("Pug", `Pug file rendering failed: ${String(error)}`, { cause: error });
896
986
  }
897
987
  }
898
988
  };
@@ -900,36 +990,36 @@ PugService = __decorate$3([(0, _nestjs_common.Injectable)()], PugService);
900
990
  //#endregion
901
991
  //#region src/puppeteer/libs/requireService.utils.ts
902
992
  function requireService(service, name) {
903
- 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);
904
994
  return service;
905
995
  }
906
996
  //#endregion
907
997
  //#region src/puppeteer/puppeteer.service.ts
908
998
  let PuppeteerService = class PuppeteerService {
909
- browserService;
910
- options;
911
- hbsService;
912
- mjmlService;
913
- pugService;
914
- ejsService;
915
- nunjucksService;
916
- etaService;
917
- mustacheService;
999
+ #browserService;
1000
+ #options;
1001
+ #hbsService;
1002
+ #mjmlService;
1003
+ #pugService;
1004
+ #ejsService;
1005
+ #nunjucksService;
1006
+ #etaService;
1007
+ #mustacheService;
918
1008
  constructor(browserService, options, hbsService, mjmlService, pugService, ejsService, nunjucksService, etaService, mustacheService) {
919
- this.browserService = browserService;
920
- this.options = options;
921
- this.hbsService = hbsService;
922
- this.mjmlService = mjmlService;
923
- this.pugService = pugService;
924
- this.ejsService = ejsService;
925
- this.nunjucksService = nunjucksService;
926
- this.etaService = etaService;
927
- this.mustacheService = mustacheService;
928
- }
929
- 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);
930
1020
  async generatePdfFromHtml(html, options) {
931
- return this.limit(async () => {
932
- const mergePuppeteerOptions = mergePuppeteerParameters(this.options, options);
1021
+ return this.#limit(async () => {
1022
+ const mergePuppeteerOptions = mergePuppeteerParameters(this.#options, options);
933
1023
  if (mergePuppeteerOptions.chromiumRevision !== void 0) _nestjs_common.Logger.warn("Using `chromiumRevision` is no longer supported since the puppeteer update.");
934
1024
  const headless = mergePuppeteerOptions.headless ?? true;
935
1025
  const executablePath = mergePuppeteerOptions.executablePath || void 0;
@@ -971,10 +1061,10 @@ let PuppeteerService = class PuppeteerService {
971
1061
  "--no-zygote",
972
1062
  "--disable-gpu"
973
1063
  ];
974
- this.browserService.markJobStarted();
1064
+ this.#browserService.markJobStarted();
975
1065
  let context = null;
976
1066
  try {
977
- context = await this.browserService.createContext(args, headless, executablePath);
1067
+ context = await this.#browserService.createContext(args, headless, executablePath);
978
1068
  const page = await context.newPage();
979
1069
  const pdfOptions = mergePuppeteerOptions.pdfOptions ?? { format: "A4" };
980
1070
  await page.setContent(html, { waitUntil: "domcontentloaded" });
@@ -983,75 +1073,77 @@ let PuppeteerService = class PuppeteerService {
983
1073
  idleTime: 500,
984
1074
  timeout: 3e4
985
1075
  });
1076
+ /* v8 ignore next */
986
1077
  await page.evaluate(() => document.fonts.ready);
987
1078
  return await page.pdf(pdfOptions);
988
1079
  } catch (e) {
989
1080
  _nestjs_common.Logger.error(e);
990
- throw e;
1081
+ if (e instanceof NestjsPdfException) throw e;
1082
+ throw new PdfGenerationException(`PDF generation failed: ${String(e)}`, { cause: e });
991
1083
  } finally {
992
1084
  if (context) try {
993
1085
  await context.close();
994
1086
  } catch (error) {
995
1087
  _nestjs_common.Logger.error(error);
996
1088
  }
997
- await this.browserService.markJobFinished();
1089
+ await this.#browserService.markJobFinished();
998
1090
  }
999
1091
  });
1000
1092
  }
1001
1093
  async generatePdfFromTemplateHbsString(template, parameters = {}, options) {
1002
- 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);
1003
1095
  return this.generatePdfFromHtml(html, options);
1004
1096
  }
1005
1097
  async generatePdfFromTemplateHbsFile(file, parameters = {}, options) {
1006
- 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);
1007
1099
  return this.generatePdfFromHtml(html, options);
1008
1100
  }
1009
1101
  async generatePdfFromMjmlString(template, options) {
1010
- 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);
1011
1103
  return this.generatePdfFromHtml(html, options);
1012
1104
  }
1013
1105
  async generatePdfFromMjmlFile(file, options) {
1014
- 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);
1015
1107
  return this.generatePdfFromHtml(html, options);
1016
1108
  }
1017
1109
  async generatePdfFromPugString(template, data = {}, options) {
1018
- 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);
1019
1111
  return this.generatePdfFromHtml(html, options);
1020
1112
  }
1021
1113
  async generatePdfFromPugFile(file, data = {}, options) {
1022
- 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);
1023
1115
  return this.generatePdfFromHtml(html, options);
1024
1116
  }
1025
1117
  async generatePdfFromEjsString(template, data = {}, options) {
1026
- 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);
1027
1119
  return this.generatePdfFromHtml(html, options);
1028
1120
  }
1029
1121
  async generatePdfFromEjsFile(file, data = {}, options) {
1030
- 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);
1031
1123
  return this.generatePdfFromHtml(html, options);
1032
1124
  }
1033
1125
  async generatePdfFromNunjucksString(template, data = {}, options) {
1034
- 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);
1035
1127
  return this.generatePdfFromHtml(html, options);
1036
1128
  }
1037
1129
  async generatePdfFromNunjucksFile(file, data = {}, options) {
1038
- 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);
1039
1131
  return this.generatePdfFromHtml(html, options);
1040
1132
  }
1041
1133
  async generatePdfFromEtaString(template, data = {}, options) {
1042
- 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);
1043
1135
  return this.generatePdfFromHtml(html, options);
1044
1136
  }
1045
1137
  async generatePdfFromEtaFile(file, data = {}, options) {
1046
- 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);
1047
1139
  return this.generatePdfFromHtml(html, options);
1048
1140
  }
1049
1141
  async generatePdfFromMustacheString(template, data = {}, options) {
1050
- 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);
1051
1143
  return this.generatePdfFromHtml(html, options);
1052
1144
  }
1053
1145
  async generatePdfFromMustacheFile(file, data = {}, options) {
1054
- 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);
1055
1147
  return this.generatePdfFromHtml(html, options);
1056
1148
  }
1057
1149
  };
@@ -1080,9 +1172,9 @@ PuppeteerService = __decorate$3([
1080
1172
  //#endregion
1081
1173
  //#region src/nestjs-pdf.service.ts
1082
1174
  let NestjsPdfService = class NestjsPdfService {
1083
- puppeteerService;
1175
+ #puppeteerService;
1084
1176
  constructor(puppeteerService) {
1085
- this.puppeteerService = puppeteerService;
1177
+ this.#puppeteerService = puppeteerService;
1086
1178
  }
1087
1179
  /**
1088
1180
  * @param html HTML string to convert to PDF
@@ -1091,7 +1183,7 @@ let NestjsPdfService = class NestjsPdfService {
1091
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.
1092
1184
  */
1093
1185
  generatePdfFromHtml(html, options) {
1094
- return this.puppeteerService.generatePdfFromHtml(html, options);
1186
+ return this.#puppeteerService.generatePdfFromHtml(html, options);
1095
1187
  }
1096
1188
  /**
1097
1189
  * @param template Handlebars template string
@@ -1101,7 +1193,7 @@ let NestjsPdfService = class NestjsPdfService {
1101
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.
1102
1194
  */
1103
1195
  generatePdfFromTemplateHbsString(template, parameters = {}, options) {
1104
- return this.puppeteerService.generatePdfFromTemplateHbsString(template, parameters, options);
1196
+ return this.#puppeteerService.generatePdfFromTemplateHbsString(template, parameters, options);
1105
1197
  }
1106
1198
  /**
1107
1199
  * @param file Path to the Handlebars template file
@@ -1111,7 +1203,7 @@ let NestjsPdfService = class NestjsPdfService {
1111
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.
1112
1204
  */
1113
1205
  generatePdfFromTemplateHbsFile(file, parameters = {}, options) {
1114
- return this.puppeteerService.generatePdfFromTemplateHbsFile(file, parameters, options);
1206
+ return this.#puppeteerService.generatePdfFromTemplateHbsFile(file, parameters, options);
1115
1207
  }
1116
1208
  /**
1117
1209
  * @param template MJML template string
@@ -1120,7 +1212,7 @@ let NestjsPdfService = class NestjsPdfService {
1120
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.
1121
1213
  */
1122
1214
  generatePdfFromMjmlString(template, options) {
1123
- return this.puppeteerService.generatePdfFromMjmlString(template, options);
1215
+ return this.#puppeteerService.generatePdfFromMjmlString(template, options);
1124
1216
  }
1125
1217
  /**
1126
1218
  * @param file Path to the MJML template file
@@ -1129,7 +1221,7 @@ let NestjsPdfService = class NestjsPdfService {
1129
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.
1130
1222
  */
1131
1223
  generatePdfFromMjmlFile(file, options) {
1132
- return this.puppeteerService.generatePdfFromMjmlFile(file, options);
1224
+ return this.#puppeteerService.generatePdfFromMjmlFile(file, options);
1133
1225
  }
1134
1226
  /**
1135
1227
  * @param template EJS template string
@@ -1139,7 +1231,7 @@ let NestjsPdfService = class NestjsPdfService {
1139
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.
1140
1232
  */
1141
1233
  generatePdfFromEjsString(template, data = {}, options) {
1142
- return this.puppeteerService.generatePdfFromEjsString(template, data, options);
1234
+ return this.#puppeteerService.generatePdfFromEjsString(template, data, options);
1143
1235
  }
1144
1236
  /**
1145
1237
  * @param file Path to the EJS template file
@@ -1149,7 +1241,7 @@ let NestjsPdfService = class NestjsPdfService {
1149
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.
1150
1242
  */
1151
1243
  generatePdfFromEjsFile(file, data = {}, options) {
1152
- return this.puppeteerService.generatePdfFromEjsFile(file, data, options);
1244
+ return this.#puppeteerService.generatePdfFromEjsFile(file, data, options);
1153
1245
  }
1154
1246
  /**
1155
1247
  * @param template Pug template string
@@ -1159,7 +1251,7 @@ let NestjsPdfService = class NestjsPdfService {
1159
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.
1160
1252
  */
1161
1253
  generatePdfFromPugString(template, data = {}, options) {
1162
- return this.puppeteerService.generatePdfFromPugString(template, data, options);
1254
+ return this.#puppeteerService.generatePdfFromPugString(template, data, options);
1163
1255
  }
1164
1256
  /**
1165
1257
  * @param file Path to the Pug template file
@@ -1169,7 +1261,7 @@ let NestjsPdfService = class NestjsPdfService {
1169
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.
1170
1262
  */
1171
1263
  generatePdfFromPugFile(file, data = {}, options) {
1172
- return this.puppeteerService.generatePdfFromPugFile(file, data, options);
1264
+ return this.#puppeteerService.generatePdfFromPugFile(file, data, options);
1173
1265
  }
1174
1266
  /**
1175
1267
  * @param template Nunjucks template string
@@ -1179,7 +1271,7 @@ let NestjsPdfService = class NestjsPdfService {
1179
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.
1180
1272
  */
1181
1273
  generatePdfFromNunjucksString(template, data = {}, options) {
1182
- return this.puppeteerService.generatePdfFromNunjucksString(template, data, options);
1274
+ return this.#puppeteerService.generatePdfFromNunjucksString(template, data, options);
1183
1275
  }
1184
1276
  /**
1185
1277
  * @param file Path to the Nunjucks template file
@@ -1189,7 +1281,7 @@ let NestjsPdfService = class NestjsPdfService {
1189
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.
1190
1282
  */
1191
1283
  generatePdfFromNunjucksFile(file, data = {}, options) {
1192
- return this.puppeteerService.generatePdfFromNunjucksFile(file, data, options);
1284
+ return this.#puppeteerService.generatePdfFromNunjucksFile(file, data, options);
1193
1285
  }
1194
1286
  /**
1195
1287
  * @param template Eta template string
@@ -1199,7 +1291,7 @@ let NestjsPdfService = class NestjsPdfService {
1199
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.
1200
1292
  */
1201
1293
  generatePdfFromEtaString(template, data = {}, options) {
1202
- return this.puppeteerService.generatePdfFromEtaString(template, data, options);
1294
+ return this.#puppeteerService.generatePdfFromEtaString(template, data, options);
1203
1295
  }
1204
1296
  /**
1205
1297
  * @param file Path to the Eta template file
@@ -1209,7 +1301,7 @@ let NestjsPdfService = class NestjsPdfService {
1209
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.
1210
1302
  */
1211
1303
  generatePdfFromEtaFile(file, data = {}, options) {
1212
- return this.puppeteerService.generatePdfFromEtaFile(file, data, options);
1304
+ return this.#puppeteerService.generatePdfFromEtaFile(file, data, options);
1213
1305
  }
1214
1306
  /**
1215
1307
  * @param template Mustache template string
@@ -1219,7 +1311,7 @@ let NestjsPdfService = class NestjsPdfService {
1219
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.
1220
1312
  */
1221
1313
  generatePdfFromMustacheString(template, data = {}, options) {
1222
- return this.puppeteerService.generatePdfFromMustacheString(template, data, options);
1314
+ return this.#puppeteerService.generatePdfFromMustacheString(template, data, options);
1223
1315
  }
1224
1316
  /**
1225
1317
  * @param file Path to the Mustache template file
@@ -1229,7 +1321,7 @@ let NestjsPdfService = class NestjsPdfService {
1229
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.
1230
1322
  */
1231
1323
  generatePdfFromMustacheFile(file, data = {}, options) {
1232
- return this.puppeteerService.generatePdfFromMustacheFile(file, data, options);
1324
+ return this.#puppeteerService.generatePdfFromMustacheFile(file, data, options);
1233
1325
  }
1234
1326
  /**
1235
1327
  * @param pdf The PDF bytes to modify
@@ -1290,9 +1382,10 @@ var import_main = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
1290
1382
  defaultValue = r.join(splitter);
1291
1383
  value = env[key];
1292
1384
  }
1293
- if (value) if (seen.has(value)) result = result.replace(template, defaultValue);
1294
- else result = result.replace(template, value);
1295
- else result = result.replace(template, defaultValue);
1385
+ if (value) {
1386
+ if (seen.has(value)) result = result.replace(template, defaultValue);
1387
+ else result = result.replace(template, value);
1388
+ } else result = result.replace(template, defaultValue);
1296
1389
  if (result === runningParsed[key]) break;
1297
1390
  regex.lastIndex = 0;
1298
1391
  }
@@ -1977,10 +2070,11 @@ var import_main$1 = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
1977
2070
  }
1978
2071
  function _vaultPath(options) {
1979
2072
  let possibleVaultPath = null;
1980
- if (options && options.path && options.path.length > 0) if (Array.isArray(options.path)) {
1981
- for (const filepath of options.path) if (fs$2.existsSync(filepath)) possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
1982
- } else possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
1983
- else possibleVaultPath = path$1.resolve(process.cwd(), ".env.vault");
2073
+ if (options && options.path && options.path.length > 0) {
2074
+ if (Array.isArray(options.path)) {
2075
+ for (const filepath of options.path) if (fs$2.existsSync(filepath)) possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
2076
+ } else possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
2077
+ } else possibleVaultPath = path$1.resolve(process.cwd(), ".env.vault");
1984
2078
  if (fs$2.existsSync(possibleVaultPath)) return possibleVaultPath;
1985
2079
  return null;
1986
2080
  }
@@ -2007,10 +2101,12 @@ var import_main$1 = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
2007
2101
  if (options && options.encoding) encoding = options.encoding;
2008
2102
  else if (debug) _debug("no encoding is specified (UTF-8 is used by default)");
2009
2103
  let optionPaths = [dotenvPath];
2010
- if (options && options.path) if (!Array.isArray(options.path)) optionPaths = [_resolveHome(options.path)];
2011
- else {
2012
- optionPaths = [];
2013
- for (const filepath of options.path) optionPaths.push(_resolveHome(filepath));
2104
+ if (options && options.path) {
2105
+ if (!Array.isArray(options.path)) optionPaths = [_resolveHome(options.path)];
2106
+ else {
2107
+ optionPaths = [];
2108
+ for (const filepath of options.path) optionPaths.push(_resolveHome(filepath));
2109
+ }
2014
2110
  }
2015
2111
  let lastError;
2016
2112
  const parsedAll = {};
@@ -2090,8 +2186,10 @@ var import_main$1 = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
2090
2186
  processEnv[key] = parsed[key];
2091
2187
  populated[key] = parsed[key];
2092
2188
  }
2093
- if (debug) if (override === true) _debug(`"${key}" is already defined and WAS overwritten`);
2094
- else _debug(`"${key}" is already defined and was NOT overwritten`);
2189
+ if (debug) {
2190
+ if (override === true) _debug(`"${key}" is already defined and WAS overwritten`);
2191
+ else _debug(`"${key}" is already defined and was NOT overwritten`);
2192
+ }
2095
2193
  } else {
2096
2194
  processEnv[key] = parsed[key];
2097
2195
  populated[key] = parsed[key];
@@ -2524,14 +2622,14 @@ ConfigModule = ConfigModule_1 = __decorate([(0, _nestjs_common.Module)({
2524
2622
  //#region src/puppeteer/puppeteer.module.ts
2525
2623
  var _PuppeteerModule;
2526
2624
  let PuppeteerModule = _PuppeteerModule = class PuppeteerModule {
2527
- browserService;
2528
- pdfParams;
2625
+ #browserService;
2626
+ #pdfParams;
2529
2627
  constructor(browserService, pdfParams) {
2530
- this.browserService = browserService;
2531
- this.pdfParams = pdfParams;
2628
+ this.#browserService = browserService;
2629
+ this.#pdfParams = pdfParams;
2532
2630
  }
2533
2631
  async onModuleInit() {
2534
- 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);
2535
2633
  }
2536
2634
  static forRoot(pdfParameters) {
2537
2635
  const providers = [
@@ -2643,12 +2741,15 @@ let NestjsPdfModule = _NestjsPdfModule = class NestjsPdfModule {
2643
2741
  };
2644
2742
  NestjsPdfModule = _NestjsPdfModule = __decorate$3([(0, _nestjs_common.Module)({})], NestjsPdfModule);
2645
2743
  //#endregion
2744
+ exports.BrowserInstallationException = BrowserInstallationException;
2745
+ exports.BrowserUnavailableException = BrowserUnavailableException;
2646
2746
  Object.defineProperty(exports, "EjsService", {
2647
2747
  enumerable: true,
2648
2748
  get: function() {
2649
2749
  return EjsService;
2650
2750
  }
2651
2751
  });
2752
+ exports.EngineNotAvailableException = EngineNotAvailableException;
2652
2753
  Object.defineProperty(exports, "EtaService", {
2653
2754
  enumerable: true,
2654
2755
  get: function() {
@@ -2673,6 +2774,8 @@ Object.defineProperty(exports, "MustacheService", {
2673
2774
  return MustacheService;
2674
2775
  }
2675
2776
  });
2777
+ exports.NestjsPdfErrorCode = NestjsPdfErrorCode;
2778
+ exports.NestjsPdfException = NestjsPdfException;
2676
2779
  Object.defineProperty(exports, "NestjsPdfModule", {
2677
2780
  enumerable: true,
2678
2781
  get: function() {
@@ -2691,6 +2794,7 @@ Object.defineProperty(exports, "NunjucksService", {
2691
2794
  return NunjucksService;
2692
2795
  }
2693
2796
  });
2797
+ exports.PdfGenerationException = PdfGenerationException;
2694
2798
  Object.defineProperty(exports, "PugService", {
2695
2799
  enumerable: true,
2696
2800
  get: function() {
@@ -2709,4 +2813,8 @@ Object.defineProperty(exports, "PuppeteerService", {
2709
2813
  return PuppeteerService;
2710
2814
  }
2711
2815
  });
2816
+ exports.SignatureDependencyException = SignatureDependencyException;
2817
+ exports.SignaturePlacementException = SignaturePlacementException;
2818
+ exports.TemplateConfigurationException = TemplateConfigurationException;
2819
+ exports.TemplateRenderException = TemplateRenderException;
2712
2820
  exports.getRelativePathToValue = getRelativePathToValue;