@shad0wz7/nestjs-pdf 3.0.0 → 3.0.1

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
@@ -65,12 +65,14 @@ async function loadPdfjs() {
65
65
  pdfjsPromise = await import("pdfjs-dist/legacy/build/pdf.mjs");
66
66
  } catch (error) {
67
67
  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);
68
70
  throw new Error([
69
71
  "Failed to load pdfjs-dist.",
70
72
  "If you use anchor-based signature placement in Node.js, make sure @napi-rs/canvas is installed.",
71
73
  "Try: npm install @napi-rs/canvas",
72
74
  "",
73
- `Original error: ${error instanceof Error ? error.message : String(error)}`
75
+ `Original error: ${reason}`
74
76
  ].join("\n"), { cause: error });
75
77
  }
76
78
  return pdfjsPromise;
@@ -111,7 +113,6 @@ function addSignatureFieldAt(pdfDoc, pageIndex, opts) {
111
113
  const { fieldName, x, y, width, height } = opts;
112
114
  const context = pdfDoc.context;
113
115
  const page = pdfDoc.getPages()[pageIndex];
114
- if (!page) throw new Error(`Page ${pageIndex} not found`);
115
116
  const rectArray = context.obj([
116
117
  PDFNumber.of(x),
117
118
  PDFNumber.of(y),
@@ -168,7 +169,9 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
168
169
  const sigHeight = 50;
169
170
  if (anchor) {
170
171
  const pageIndex = anchor.pageIndex;
171
- const { width: pw, height: ph } = pdfDoc.getPages()[pageIndex].getSize();
172
+ const page = pdfDoc.getPages()[pageIndex];
173
+ if (!page) throw new Error(`Page ${pageIndex} not found`);
174
+ const { width: pw, height: ph } = page.getSize();
172
175
  const padX = 40;
173
176
  const padY = 7;
174
177
  let x = anchor.x - sigWidth / 2 + padX;
@@ -186,7 +189,10 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
186
189
  } else {
187
190
  const pages = pdfDoc.getPages();
188
191
  const pageIndex = pages.length - 1;
189
- const { width: pageWidth } = pages[pageIndex].getSize();
192
+ const page = pages.at(-1);
193
+ /* 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`);
195
+ const { width: pageWidth } = page.getSize();
190
196
  addSignatureFieldAt(pdfDoc, pageIndex, {
191
197
  fieldName,
192
198
  x: (pageWidth - sigWidth) / 2,
@@ -334,19 +340,19 @@ function mergePuppeteerParameters(defaults, overrides) {
334
340
  //#region src/helpers/tokens.ts
335
341
  const PDF_PARAMETERS = "PDF_PARAMETERS";
336
342
  //#endregion
337
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorateMetadata.js
343
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateMetadata.js
338
344
  function __decorateMetadata(k, v) {
339
345
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
340
346
  }
341
347
  //#endregion
342
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorateParam.js
348
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
343
349
  function __decorateParam(paramIndex, decorator) {
344
350
  return function(target, key) {
345
351
  decorator(target, key, paramIndex);
346
352
  };
347
353
  }
348
354
  //#endregion
349
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorate.js
355
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
350
356
  function __decorate$3(decorators, target, key, desc) {
351
357
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
352
358
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -522,9 +528,10 @@ let BrowserService = class BrowserService {
522
528
  }
523
529
  loadBrowserTag() {
524
530
  let versionTag;
525
- if (this.options?.browserTag === void 0) if (this.browser === Browser.CHROMIUM) versionTag = "latest";
526
- else versionTag = "stable";
527
- else versionTag = this.options.browserTag;
531
+ if (this.options?.browserTag === void 0) {
532
+ if (this.browser === Browser.CHROMIUM) versionTag = "latest";
533
+ else versionTag = "stable";
534
+ } else versionTag = this.options.browserTag;
528
535
  this.browserTag = versionTag;
529
536
  }
530
537
  loadBuildId() {
@@ -978,6 +985,7 @@ let PuppeteerService = class PuppeteerService {
978
985
  idleTime: 500,
979
986
  timeout: 3e4
980
987
  });
988
+ /* v8 ignore next */
981
989
  await page.evaluate(() => document.fonts.ready);
982
990
  return await page.pdf(pdfOptions);
983
991
  } catch (e) {
@@ -1285,9 +1293,10 @@ var import_main = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
1285
1293
  defaultValue = r.join(splitter);
1286
1294
  value = env[key];
1287
1295
  }
1288
- if (value) if (seen.has(value)) result = result.replace(template, defaultValue);
1289
- else result = result.replace(template, value);
1290
- else result = result.replace(template, defaultValue);
1296
+ if (value) {
1297
+ if (seen.has(value)) result = result.replace(template, defaultValue);
1298
+ else result = result.replace(template, value);
1299
+ } else result = result.replace(template, defaultValue);
1291
1300
  if (result === runningParsed[key]) break;
1292
1301
  regex.lastIndex = 0;
1293
1302
  }
@@ -1972,10 +1981,11 @@ var import_main$1 = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
1972
1981
  }
1973
1982
  function _vaultPath(options) {
1974
1983
  let possibleVaultPath = null;
1975
- if (options && options.path && options.path.length > 0) if (Array.isArray(options.path)) {
1976
- for (const filepath of options.path) if (fs$2.existsSync(filepath)) possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
1977
- } else possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
1978
- else possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
1984
+ if (options && options.path && options.path.length > 0) {
1985
+ if (Array.isArray(options.path)) {
1986
+ for (const filepath of options.path) if (fs$2.existsSync(filepath)) possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
1987
+ } else possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
1988
+ } else possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
1979
1989
  if (fs$2.existsSync(possibleVaultPath)) return possibleVaultPath;
1980
1990
  return null;
1981
1991
  }
@@ -2002,10 +2012,12 @@ var import_main$1 = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
2002
2012
  if (options && options.encoding) encoding = options.encoding;
2003
2013
  else if (debug) _debug("no encoding is specified (UTF-8 is used by default)");
2004
2014
  let optionPaths = [dotenvPath];
2005
- if (options && options.path) if (!Array.isArray(options.path)) optionPaths = [_resolveHome(options.path)];
2006
- else {
2007
- optionPaths = [];
2008
- for (const filepath of options.path) optionPaths.push(_resolveHome(filepath));
2015
+ if (options && options.path) {
2016
+ if (!Array.isArray(options.path)) optionPaths = [_resolveHome(options.path)];
2017
+ else {
2018
+ optionPaths = [];
2019
+ for (const filepath of options.path) optionPaths.push(_resolveHome(filepath));
2020
+ }
2009
2021
  }
2010
2022
  let lastError;
2011
2023
  const parsedAll = {};
@@ -2085,8 +2097,10 @@ var import_main$1 = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
2085
2097
  processEnv[key] = parsed[key];
2086
2098
  populated[key] = parsed[key];
2087
2099
  }
2088
- if (debug) if (override === true) _debug(`"${key}" is already defined and WAS overwritten`);
2089
- else _debug(`"${key}" is already defined and was NOT overwritten`);
2100
+ if (debug) {
2101
+ if (override === true) _debug(`"${key}" is already defined and WAS overwritten`);
2102
+ else _debug(`"${key}" is already defined and was NOT overwritten`);
2103
+ }
2090
2104
  } else {
2091
2105
  processEnv[key] = parsed[key];
2092
2106
  populated[key] = parsed[key];