@shad0wz7/nestjs-pdf 2.5.3 → 2.5.5

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
@@ -40,12 +40,14 @@ async function loadPdfjs() {
40
40
  pdfjsPromise = await import("pdfjs-dist/legacy/build/pdf.mjs");
41
41
  } catch (error) {
42
42
  pdfjsPromise = void 0;
43
+ /* v8 ignore next -- import() rejections are always Error instances in practice */
44
+ const reason = error instanceof Error ? error.message : String(error);
43
45
  throw new Error([
44
46
  "Failed to load pdfjs-dist.",
45
47
  "If you use anchor-based signature placement in Node.js, make sure @napi-rs/canvas is installed.",
46
48
  "Try: npm install @napi-rs/canvas",
47
49
  "",
48
- `Original error: ${error instanceof Error ? error.message : String(error)}`
50
+ `Original error: ${reason}`
49
51
  ].join("\n"), { cause: error });
50
52
  }
51
53
  return pdfjsPromise;
@@ -86,7 +88,6 @@ function addSignatureFieldAt(pdfDoc, pageIndex, opts) {
86
88
  const { fieldName, x, y, width, height } = opts;
87
89
  const context = pdfDoc.context;
88
90
  const page = pdfDoc.getPages()[pageIndex];
89
- if (!page) throw new Error(`Page ${pageIndex} not found`);
90
91
  const rectArray = context.obj([
91
92
  PDFNumber.of(x),
92
93
  PDFNumber.of(y),
@@ -143,7 +144,9 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
143
144
  const sigHeight = 50;
144
145
  if (anchor) {
145
146
  const pageIndex = anchor.pageIndex;
146
- const { width: pw, height: ph } = pdfDoc.getPages()[pageIndex].getSize();
147
+ const page = pdfDoc.getPages()[pageIndex];
148
+ if (!page) throw new Error(`Page ${pageIndex} not found`);
149
+ const { width: pw, height: ph } = page.getSize();
147
150
  const padX = 40;
148
151
  const padY = 7;
149
152
  let x = anchor.x - sigWidth / 2 + padX;
@@ -161,7 +164,10 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
161
164
  } else {
162
165
  const pages = pdfDoc.getPages();
163
166
  const pageIndex = pages.length - 1;
164
- const { width: pageWidth } = pages[pageIndex].getSize();
167
+ const page = pages.at(-1);
168
+ /* v8 ignore next -- pdf-lib always produces at least one page on save/load; only a hand-crafted, malformed PDF could hit this */
169
+ if (!page) throw new Error(`Page ${pageIndex} not found`);
170
+ const { width: pageWidth } = page.getSize();
165
171
  addSignatureFieldAt(pdfDoc, pageIndex, {
166
172
  fieldName,
167
173
  x: (pageWidth - sigWidth) / 2,
@@ -183,19 +189,19 @@ function mergePuppeteerParameters(defaults, overrides) {
183
189
  const PDF_PARAMETERS = "PDF_PARAMETERS";
184
190
  const HANDLEBARS_PARAMETERS = "HANDLEBARS_PARAMETERS";
185
191
  //#endregion
186
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorateMetadata.js
192
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateMetadata.js
187
193
  function __decorateMetadata(k, v) {
188
194
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
189
195
  }
190
196
  //#endregion
191
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorateParam.js
197
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
192
198
  function __decorateParam(paramIndex, decorator) {
193
199
  return function(target, key) {
194
200
  decorator(target, key, paramIndex);
195
201
  };
196
202
  }
197
203
  //#endregion
198
- //#region \0@oxc-project+runtime@0.142.0/helpers/esm/decorate.js
204
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
199
205
  function __decorate(decorators, target, key, desc) {
200
206
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
201
207
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -374,9 +380,10 @@ let BrowserService = class BrowserService {
374
380
  }
375
381
  loadBrowserTag() {
376
382
  let versionTag;
377
- if (this.options?.browserTag === void 0) if (this.browser === Browser.CHROMIUM) versionTag = "latest";
378
- else versionTag = "stable";
379
- else versionTag = this.options.browserTag;
383
+ if (this.options?.browserTag === void 0) {
384
+ if (this.browser === Browser.CHROMIUM) versionTag = "latest";
385
+ else versionTag = "stable";
386
+ } else versionTag = this.options.browserTag;
380
387
  this.browserTag = versionTag;
381
388
  }
382
389
  loadBuildId() {
@@ -1187,10 +1194,11 @@ var require_main$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1187
1194
  }
1188
1195
  function _vaultPath(options) {
1189
1196
  let possibleVaultPath = null;
1190
- if (options && options.path && options.path.length > 0) if (Array.isArray(options.path)) {
1191
- for (const filepath of options.path) if (fs$1.existsSync(filepath)) possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
1192
- } else possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
1193
- else possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
1197
+ if (options && options.path && options.path.length > 0) {
1198
+ if (Array.isArray(options.path)) {
1199
+ for (const filepath of options.path) if (fs$1.existsSync(filepath)) possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
1200
+ } else possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
1201
+ } else possibleVaultPath = path.resolve(process.cwd(), ".env.vault");
1194
1202
  if (fs$1.existsSync(possibleVaultPath)) return possibleVaultPath;
1195
1203
  return null;
1196
1204
  }
@@ -1217,10 +1225,12 @@ var require_main$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1217
1225
  if (options && options.encoding) encoding = options.encoding;
1218
1226
  else if (debug) _debug("no encoding is specified (UTF-8 is used by default)");
1219
1227
  let optionPaths = [dotenvPath];
1220
- if (options && options.path) if (!Array.isArray(options.path)) optionPaths = [_resolveHome(options.path)];
1221
- else {
1222
- optionPaths = [];
1223
- for (const filepath of options.path) optionPaths.push(_resolveHome(filepath));
1228
+ if (options && options.path) {
1229
+ if (!Array.isArray(options.path)) optionPaths = [_resolveHome(options.path)];
1230
+ else {
1231
+ optionPaths = [];
1232
+ for (const filepath of options.path) optionPaths.push(_resolveHome(filepath));
1233
+ }
1224
1234
  }
1225
1235
  let lastError;
1226
1236
  const parsedAll = {};
@@ -1300,8 +1310,10 @@ var require_main$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1300
1310
  processEnv[key] = parsed[key];
1301
1311
  populated[key] = parsed[key];
1302
1312
  }
1303
- if (debug) if (override === true) _debug(`"${key}" is already defined and WAS overwritten`);
1304
- else _debug(`"${key}" is already defined and was NOT overwritten`);
1313
+ if (debug) {
1314
+ if (override === true) _debug(`"${key}" is already defined and WAS overwritten`);
1315
+ else _debug(`"${key}" is already defined and was NOT overwritten`);
1316
+ }
1305
1317
  } else {
1306
1318
  processEnv[key] = parsed[key];
1307
1319
  populated[key] = parsed[key];
@@ -1358,9 +1370,10 @@ var require_main = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1358
1370
  defaultValue = r.join(splitter);
1359
1371
  value = env[key];
1360
1372
  }
1361
- if (value) if (seen.has(value)) result = result.replace(template, defaultValue);
1362
- else result = result.replace(template, value);
1363
- else result = result.replace(template, defaultValue);
1373
+ if (value) {
1374
+ if (seen.has(value)) result = result.replace(template, defaultValue);
1375
+ else result = result.replace(template, value);
1376
+ } else result = result.replace(template, defaultValue);
1364
1377
  if (result === runningParsed[key]) break;
1365
1378
  regex.lastIndex = 0;
1366
1379
  }
@@ -1452,8 +1465,10 @@ var require__getRawTag = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1452
1465
  var unmasked = true;
1453
1466
  } catch (e) {}
1454
1467
  var result = nativeObjectToString.call(value);
1455
- if (unmasked) if (isOwn) value[symToStringTag] = tag;
1456
- else delete value[symToStringTag];
1468
+ if (unmasked) {
1469
+ if (isOwn) value[symToStringTag] = tag;
1470
+ else delete value[symToStringTag];
1471
+ }
1457
1472
  return result;
1458
1473
  }
1459
1474
  module.exports = getRawTag;
@@ -2417,7 +2432,7 @@ var require__baseToString = /* @__PURE__ */ __commonJSMin(((exports, module) =>
2417
2432
  var isArray = require_isArray();
2418
2433
  var isSymbol = require_isSymbol();
2419
2434
  /** Used as references for various `Number` constants. */
2420
- var INFINITY = Infinity;
2435
+ var INFINITY = 1 / 0;
2421
2436
  /** Used to convert symbols to primitives and strings. */
2422
2437
  var symbolProto = Symbol ? Symbol.prototype : void 0;
2423
2438
  var symbolToString = symbolProto ? symbolProto.toString : void 0;
@@ -2494,7 +2509,7 @@ var require__castPath = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2494
2509
  var require__toKey = /* @__PURE__ */ __commonJSMin(((exports, module) => {
2495
2510
  var isSymbol = require_isSymbol();
2496
2511
  /** Used as references for various `Number` constants. */
2497
- var INFINITY = Infinity;
2512
+ var INFINITY = 1 / 0;
2498
2513
  /**
2499
2514
  * Converts `value` to a string key if it's not a string or symbol.
2500
2515
  *