@shad0wz7/nestjs-pdf 3.0.1 → 3.2.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/README.md +121 -6
- package/dist/index.cjs +665 -1494
- package/dist/index.d.cts +163 -54
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +163 -54
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +656 -1520
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -21
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
10
9
|
var __copyProps = (to, from, except, desc) => {
|
|
11
10
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
11
|
key = keys[i];
|
|
@@ -26,9 +25,12 @@ let node_path = require("node:path");
|
|
|
26
25
|
let _nestjs_common = require("@nestjs/common");
|
|
27
26
|
let pdf_lib = require("pdf-lib");
|
|
28
27
|
let deepmerge_ts = require("deepmerge-ts");
|
|
28
|
+
let node_dns_promises = require("node:dns/promises");
|
|
29
29
|
let node_fs = require("node:fs");
|
|
30
|
-
let
|
|
30
|
+
let node_net = require("node:net");
|
|
31
|
+
let node_url = require("node:url");
|
|
31
32
|
let puppeteer = require("puppeteer");
|
|
33
|
+
let _puppeteer_browsers = require("@puppeteer/browsers");
|
|
32
34
|
let ejs = require("ejs");
|
|
33
35
|
ejs = __toESM(ejs, 1);
|
|
34
36
|
let eta = require("eta");
|
|
@@ -42,12 +44,79 @@ let nunjucks = require("nunjucks");
|
|
|
42
44
|
nunjucks = __toESM(nunjucks, 1);
|
|
43
45
|
let pug = require("pug");
|
|
44
46
|
pug = __toESM(pug, 1);
|
|
45
|
-
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
//#region src/exceptions/nestjs-pdf.exception.ts
|
|
48
|
+
let NestjsPdfErrorCode = /* @__PURE__ */ function(NestjsPdfErrorCode) {
|
|
49
|
+
NestjsPdfErrorCode["ENGINE_NOT_AVAILABLE"] = "ENGINE_NOT_AVAILABLE";
|
|
50
|
+
NestjsPdfErrorCode["TEMPLATE_CONFIGURATION_ERROR"] = "TEMPLATE_CONFIGURATION_ERROR";
|
|
51
|
+
NestjsPdfErrorCode["TEMPLATE_RENDER_ERROR"] = "TEMPLATE_RENDER_ERROR";
|
|
52
|
+
NestjsPdfErrorCode["BROWSER_INSTALLATION_ERROR"] = "BROWSER_INSTALLATION_ERROR";
|
|
53
|
+
NestjsPdfErrorCode["BROWSER_UNAVAILABLE"] = "BROWSER_UNAVAILABLE";
|
|
54
|
+
NestjsPdfErrorCode["PDF_GENERATION_ERROR"] = "PDF_GENERATION_ERROR";
|
|
55
|
+
NestjsPdfErrorCode["SIGNATURE_DEPENDENCY_ERROR"] = "SIGNATURE_DEPENDENCY_ERROR";
|
|
56
|
+
NestjsPdfErrorCode["SIGNATURE_PLACEMENT_ERROR"] = "SIGNATURE_PLACEMENT_ERROR";
|
|
57
|
+
NestjsPdfErrorCode["WATERMARK_ERROR"] = "WATERMARK_ERROR";
|
|
58
|
+
return NestjsPdfErrorCode;
|
|
59
|
+
}({});
|
|
60
|
+
var NestjsPdfException = class extends Error {
|
|
61
|
+
constructor(message, options) {
|
|
62
|
+
super(message, options);
|
|
63
|
+
this.name = this.constructor.name;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/exceptions/browser-installation.exception.ts
|
|
68
|
+
var BrowserInstallationException = class extends NestjsPdfException {
|
|
69
|
+
code = "BROWSER_INSTALLATION_ERROR";
|
|
70
|
+
};
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/exceptions/browser-unavailable.exception.ts
|
|
73
|
+
var BrowserUnavailableException = class extends NestjsPdfException {
|
|
74
|
+
code = "BROWSER_UNAVAILABLE";
|
|
75
|
+
};
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/exceptions/engine-not-available.exception.ts
|
|
78
|
+
var EngineNotAvailableException = class extends NestjsPdfException {
|
|
79
|
+
code = "ENGINE_NOT_AVAILABLE";
|
|
80
|
+
constructor(engineName) {
|
|
81
|
+
super(`${engineName} service is not available. If the problem persists, open an issue in the repo.`);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/exceptions/pdf-generation.exception.ts
|
|
86
|
+
var PdfGenerationException = class extends NestjsPdfException {
|
|
87
|
+
code = "PDF_GENERATION_ERROR";
|
|
88
|
+
};
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/exceptions/signature-dependency.exception.ts
|
|
91
|
+
var SignatureDependencyException = class extends NestjsPdfException {
|
|
92
|
+
code = "SIGNATURE_DEPENDENCY_ERROR";
|
|
93
|
+
};
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region src/exceptions/signature-placement.exception.ts
|
|
96
|
+
var SignaturePlacementException = class extends NestjsPdfException {
|
|
97
|
+
code = "SIGNATURE_PLACEMENT_ERROR";
|
|
98
|
+
};
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/exceptions/template-configuration.exception.ts
|
|
101
|
+
var TemplateConfigurationException = class extends NestjsPdfException {
|
|
102
|
+
code = "TEMPLATE_CONFIGURATION_ERROR";
|
|
103
|
+
};
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/exceptions/template-render.exception.ts
|
|
106
|
+
var TemplateRenderException = class extends NestjsPdfException {
|
|
107
|
+
engine;
|
|
108
|
+
code = "TEMPLATE_RENDER_ERROR";
|
|
109
|
+
constructor(engine, message, options) {
|
|
110
|
+
super(message, options);
|
|
111
|
+
this.engine = engine;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/exceptions/watermark.exception.ts
|
|
116
|
+
var WatermarkException = class extends NestjsPdfException {
|
|
117
|
+
code = "WATERMARK_ERROR";
|
|
118
|
+
};
|
|
119
|
+
//#endregion
|
|
51
120
|
//#region src/helpers/getRelativePath.helper.ts
|
|
52
121
|
/**
|
|
53
122
|
* Get the relative path to a value from the module directory.
|
|
@@ -70,14 +139,12 @@ async function loadPdfjs() {
|
|
|
70
139
|
pdfjsPromise = await import("pdfjs-dist/legacy/build/pdf.mjs");
|
|
71
140
|
} catch (error) {
|
|
72
141
|
pdfjsPromise = void 0;
|
|
73
|
-
|
|
74
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
75
|
-
throw new Error([
|
|
142
|
+
throw new SignatureDependencyException([
|
|
76
143
|
"Failed to load pdfjs-dist.",
|
|
77
144
|
"If you use anchor-based signature placement in Node.js, make sure @napi-rs/canvas is installed.",
|
|
78
145
|
"Try: npm install @napi-rs/canvas",
|
|
79
146
|
"",
|
|
80
|
-
`Original error: ${
|
|
147
|
+
`Original error: ${error instanceof Error ? error.message : String(error)}`
|
|
81
148
|
].join("\n"), { cause: error });
|
|
82
149
|
}
|
|
83
150
|
return pdfjsPromise;
|
|
@@ -175,7 +242,7 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
|
|
|
175
242
|
if (anchor) {
|
|
176
243
|
const pageIndex = anchor.pageIndex;
|
|
177
244
|
const page = pdfDoc.getPages()[pageIndex];
|
|
178
|
-
if (!page) throw new
|
|
245
|
+
if (!page) throw new SignaturePlacementException(`Page ${pageIndex} not found`);
|
|
179
246
|
const { width: pw, height: ph } = page.getSize();
|
|
180
247
|
const padX = 40;
|
|
181
248
|
const padY = 7;
|
|
@@ -196,7 +263,7 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
|
|
|
196
263
|
const pageIndex = pages.length - 1;
|
|
197
264
|
const page = pages.at(-1);
|
|
198
265
|
/* v8 ignore next -- pdf-lib always produces at least one page on save/load; only a hand-crafted, malformed PDF could hit this */
|
|
199
|
-
if (!page) throw new
|
|
266
|
+
if (!page) throw new SignaturePlacementException(`Page ${pageIndex} not found`);
|
|
200
267
|
const { width: pageWidth } = page.getSize();
|
|
201
268
|
addSignatureFieldAt(pdfDoc, pageIndex, {
|
|
202
269
|
fieldName,
|
|
@@ -209,6 +276,150 @@ async function addSignatureFieldUsingAnchor(pdf, fieldName = "SignatureDebtor",
|
|
|
209
276
|
return await pdfDoc.save();
|
|
210
277
|
}
|
|
211
278
|
//#endregion
|
|
279
|
+
//#region src/helpers/watermark.helper.ts
|
|
280
|
+
const DEFAULT_OPACITY = .15;
|
|
281
|
+
const DEFAULT_ROTATION = 45;
|
|
282
|
+
const DEFAULT_FONT_SIZE = 60;
|
|
283
|
+
const DEFAULT_FONT = "HelveticaBold";
|
|
284
|
+
const DEFAULT_COLOR = "#808080";
|
|
285
|
+
const DEFAULT_TILE_SPACING = 100;
|
|
286
|
+
function parseHexColor(color) {
|
|
287
|
+
const match = /^#([\da-f]{3}|[\da-f]{6})$/i.exec(color);
|
|
288
|
+
if (!match) throw new WatermarkException(`Invalid watermark color "${color}", expected #rgb or #rrggbb`);
|
|
289
|
+
const hex = match[1].length === 3 ? [...match[1]].map((c) => c + c).join("") : match[1];
|
|
290
|
+
const channel = (i) => Number.parseInt(hex.slice(i, i + 2), 16) / 255;
|
|
291
|
+
return (0, pdf_lib.rgb)(channel(0), channel(2), channel(4));
|
|
292
|
+
}
|
|
293
|
+
function embedImage(pdfDoc, bytes) {
|
|
294
|
+
const isPng = bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78;
|
|
295
|
+
const isJpeg = bytes[0] === 255 && bytes[1] === 216;
|
|
296
|
+
if (isPng) return pdfDoc.embedPng(bytes);
|
|
297
|
+
if (isJpeg) return pdfDoc.embedJpg(bytes);
|
|
298
|
+
throw new WatermarkException("Watermark image must be a PNG or JPEG");
|
|
299
|
+
}
|
|
300
|
+
function validate(options) {
|
|
301
|
+
const { text, image, opacity, fontSize, imageWidth, tileSpacing } = options;
|
|
302
|
+
if (!text && !image) throw new WatermarkException("A watermark requires at least a `text` or an `image`");
|
|
303
|
+
if (opacity !== void 0 && !(opacity >= 0 && opacity <= 1)) throw new WatermarkException("Watermark `opacity` must be between 0 and 1");
|
|
304
|
+
if (fontSize !== void 0 && !(fontSize > 0)) throw new WatermarkException("Watermark `fontSize` must be greater than 0");
|
|
305
|
+
if (imageWidth !== void 0 && !(imageWidth > 0)) throw new WatermarkException("Watermark `imageWidth` must be greater than 0");
|
|
306
|
+
if (tileSpacing !== void 0 && !(tileSpacing >= 0)) throw new WatermarkException("Watermark `tileSpacing` must be at least 0");
|
|
307
|
+
}
|
|
308
|
+
function resolvePageIndexes(pages, total) {
|
|
309
|
+
if (!pages) return Array.from({ length: total }, (_, i) => i);
|
|
310
|
+
for (const page of pages) if (!Number.isInteger(page) || page < 1 || page > total) throw new WatermarkException(`Watermark page ${page} is out of range (the PDF has ${total} page(s))`);
|
|
311
|
+
return [...new Set(pages)].map((page) => page - 1);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Centers of the marks for one page, in page coordinates. Tiles follow the
|
|
315
|
+
* rotated axes so rotated marks never overlap each other.
|
|
316
|
+
*/
|
|
317
|
+
function markCenters(pageWidth, pageHeight, mark, options) {
|
|
318
|
+
const cx = pageWidth / 2;
|
|
319
|
+
const cy = pageHeight / 2;
|
|
320
|
+
if (options.position === "center") return [{
|
|
321
|
+
x: cx,
|
|
322
|
+
y: cy
|
|
323
|
+
}];
|
|
324
|
+
const theta = options.rotation * Math.PI / 180;
|
|
325
|
+
const cos = Math.cos(theta);
|
|
326
|
+
const sin = Math.sin(theta);
|
|
327
|
+
const stepX = mark.width + options.spacing;
|
|
328
|
+
const stepY = mark.height + options.spacing;
|
|
329
|
+
const reach = Math.hypot(mark.width, mark.height) / 2;
|
|
330
|
+
const n = Math.ceil((Math.hypot(pageWidth, pageHeight) / 2 + reach) / Math.min(stepX, stepY));
|
|
331
|
+
const centers = [];
|
|
332
|
+
for (let i = -n; i <= n; i++) for (let j = -n; j <= n; j++) {
|
|
333
|
+
const x = cx + i * stepX * cos - j * stepY * sin;
|
|
334
|
+
const y = cy + i * stepX * sin + j * stepY * cos;
|
|
335
|
+
if (x >= -reach && x <= pageWidth + reach && y >= -reach && y <= pageHeight + reach) centers.push({
|
|
336
|
+
x,
|
|
337
|
+
y
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return centers;
|
|
341
|
+
}
|
|
342
|
+
async function buildMark(pdfDoc, options, pageWidth) {
|
|
343
|
+
const opacity = options.opacity ?? DEFAULT_OPACITY;
|
|
344
|
+
const rotate = (0, pdf_lib.degrees)(options.rotation ?? DEFAULT_ROTATION);
|
|
345
|
+
if (options.image) {
|
|
346
|
+
const image = await embedImage(pdfDoc, new Uint8Array(options.image));
|
|
347
|
+
const width = options.imageWidth ?? pageWidth / 2;
|
|
348
|
+
const height = image.height / image.width * width;
|
|
349
|
+
return {
|
|
350
|
+
width,
|
|
351
|
+
height,
|
|
352
|
+
draw: (page, x, y) => page.drawImage(image, {
|
|
353
|
+
x,
|
|
354
|
+
y,
|
|
355
|
+
width,
|
|
356
|
+
height,
|
|
357
|
+
opacity,
|
|
358
|
+
rotate
|
|
359
|
+
})
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
const font = await pdfDoc.embedFont(pdf_lib.StandardFonts[options.font ?? DEFAULT_FONT]);
|
|
363
|
+
const size = options.fontSize ?? DEFAULT_FONT_SIZE;
|
|
364
|
+
const text = options.text;
|
|
365
|
+
const color = parseHexColor(options.color ?? DEFAULT_COLOR);
|
|
366
|
+
let width;
|
|
367
|
+
try {
|
|
368
|
+
width = font.widthOfTextAtSize(text, size);
|
|
369
|
+
} catch (error) {
|
|
370
|
+
throw new WatermarkException(`Watermark text cannot be rendered with the ${options.font ?? DEFAULT_FONT} font (only WinAnsi characters are supported)`, { cause: error });
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
width,
|
|
374
|
+
height: font.heightAtSize(size, { descender: false }),
|
|
375
|
+
draw: (page, x, y) => page.drawText(text, {
|
|
376
|
+
x,
|
|
377
|
+
y,
|
|
378
|
+
size,
|
|
379
|
+
font,
|
|
380
|
+
color,
|
|
381
|
+
opacity,
|
|
382
|
+
rotate
|
|
383
|
+
})
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Stamps a text or image watermark on the pages of an existing PDF.
|
|
388
|
+
*/
|
|
389
|
+
async function addWatermark(pdf, options) {
|
|
390
|
+
validate(options);
|
|
391
|
+
try {
|
|
392
|
+
const pdfDoc = await pdf_lib.PDFDocument.load(new Uint8Array(pdf));
|
|
393
|
+
const pages = pdfDoc.getPages();
|
|
394
|
+
const indexes = resolvePageIndexes(options.pages, pages.length);
|
|
395
|
+
const position = options.position ?? "center";
|
|
396
|
+
const rotation = options.rotation ?? DEFAULT_ROTATION;
|
|
397
|
+
const spacing = options.tileSpacing ?? DEFAULT_TILE_SPACING;
|
|
398
|
+
const theta = rotation * Math.PI / 180;
|
|
399
|
+
const cos = Math.cos(theta);
|
|
400
|
+
const sin = Math.sin(theta);
|
|
401
|
+
const marks = /* @__PURE__ */ new Map();
|
|
402
|
+
for (const index of indexes) {
|
|
403
|
+
const page = pages[index];
|
|
404
|
+
const { width: pageWidth, height: pageHeight } = page.getSize();
|
|
405
|
+
let mark = marks.get(pageWidth);
|
|
406
|
+
if (!mark) {
|
|
407
|
+
mark = await buildMark(pdfDoc, options, pageWidth);
|
|
408
|
+
marks.set(pageWidth, mark);
|
|
409
|
+
}
|
|
410
|
+
for (const center of markCenters(pageWidth, pageHeight, mark, {
|
|
411
|
+
position,
|
|
412
|
+
rotation,
|
|
413
|
+
spacing
|
|
414
|
+
})) mark.draw(page, center.x - (mark.width / 2 * cos - mark.height / 2 * sin), center.y - (mark.width / 2 * sin + mark.height / 2 * cos));
|
|
415
|
+
}
|
|
416
|
+
return await pdfDoc.save();
|
|
417
|
+
} catch (error) {
|
|
418
|
+
if (error instanceof WatermarkException) throw error;
|
|
419
|
+
throw new WatermarkException(`Failed to add watermark: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
//#endregion
|
|
212
423
|
//#region node_modules/.pnpm/yocto-queue@1.2.2/node_modules/yocto-queue/index.js
|
|
213
424
|
var Node = class {
|
|
214
425
|
value;
|
|
@@ -342,6 +553,154 @@ function mergePuppeteerParameters(defaults, overrides) {
|
|
|
342
553
|
return (0, deepmerge_ts.deepmerge)(defaults, overrides);
|
|
343
554
|
}
|
|
344
555
|
//#endregion
|
|
556
|
+
//#region src/helpers/request-guard.helper.ts
|
|
557
|
+
const blockedRanges = new node_net.BlockList();
|
|
558
|
+
for (const [address, prefix] of [
|
|
559
|
+
["0.0.0.0", 8],
|
|
560
|
+
["10.0.0.0", 8],
|
|
561
|
+
["100.64.0.0", 10],
|
|
562
|
+
["127.0.0.0", 8],
|
|
563
|
+
["169.254.0.0", 16],
|
|
564
|
+
["172.16.0.0", 12],
|
|
565
|
+
["192.0.0.0", 24],
|
|
566
|
+
["192.168.0.0", 16],
|
|
567
|
+
["198.18.0.0", 15],
|
|
568
|
+
["224.0.0.0", 4],
|
|
569
|
+
["240.0.0.0", 4]
|
|
570
|
+
]) blockedRanges.addSubnet(address, prefix, "ipv4");
|
|
571
|
+
for (const [address, prefix] of [
|
|
572
|
+
["::", 128],
|
|
573
|
+
["::1", 128],
|
|
574
|
+
["64:ff9b::", 96],
|
|
575
|
+
["fc00::", 7],
|
|
576
|
+
["fe80::", 10],
|
|
577
|
+
["ff00::", 8]
|
|
578
|
+
]) blockedRanges.addSubnet(address, prefix, "ipv6");
|
|
579
|
+
const IPV4_MAPPED_IPV6 = /^::ffff:([\da-f]{1,4}):([\da-f]{1,4})$/i;
|
|
580
|
+
/** True for addresses that must not be reachable from a rendered document. */
|
|
581
|
+
function isPrivateAddress(address) {
|
|
582
|
+
const family = (0, node_net.isIP)(address);
|
|
583
|
+
if (family === 4) return blockedRanges.check(address, "ipv4");
|
|
584
|
+
if (family === 6) {
|
|
585
|
+
const mapped = IPV4_MAPPED_IPV6.exec(address);
|
|
586
|
+
if (mapped) {
|
|
587
|
+
const high = Number.parseInt(mapped[1], 16);
|
|
588
|
+
const low = Number.parseInt(mapped[2], 16);
|
|
589
|
+
return isPrivateAddress([
|
|
590
|
+
high >> 8,
|
|
591
|
+
high & 255,
|
|
592
|
+
low >> 8,
|
|
593
|
+
low & 255
|
|
594
|
+
].join("."));
|
|
595
|
+
}
|
|
596
|
+
return blockedRanges.check(address, "ipv6");
|
|
597
|
+
}
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
function hostMatches(hostname, pattern) {
|
|
601
|
+
const host = hostname.toLowerCase();
|
|
602
|
+
const rule = pattern.toLowerCase();
|
|
603
|
+
if (rule.startsWith("*.")) return host.endsWith(rule.slice(1));
|
|
604
|
+
return host === rule;
|
|
605
|
+
}
|
|
606
|
+
function isLocalhostName(hostname) {
|
|
607
|
+
return hostname === "localhost" || hostname.endsWith(".localhost");
|
|
608
|
+
}
|
|
609
|
+
async function resolvesToPrivateAddress(hostname) {
|
|
610
|
+
const host = hostname.replace(/^\[|\]$/g, "");
|
|
611
|
+
if ((0, node_net.isIP)(host)) return isPrivateAddress(host);
|
|
612
|
+
if (isLocalhostName(host)) return true;
|
|
613
|
+
try {
|
|
614
|
+
return (await (0, node_dns_promises.lookup)(host, {
|
|
615
|
+
all: true,
|
|
616
|
+
verbatim: true
|
|
617
|
+
})).some(({ address }) => isPrivateAddress(address));
|
|
618
|
+
} catch {
|
|
619
|
+
return true;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
async function isFileAllowed(url, roots) {
|
|
623
|
+
if (roots.length === 0 || url.hostname !== "" && url.hostname !== "localhost") return false;
|
|
624
|
+
let path;
|
|
625
|
+
try {
|
|
626
|
+
path = (0, node_url.fileURLToPath)(url);
|
|
627
|
+
} catch {
|
|
628
|
+
return false;
|
|
629
|
+
}
|
|
630
|
+
const real = async (candidate) => {
|
|
631
|
+
const missing = [];
|
|
632
|
+
let current = (0, node_path.resolve)(candidate);
|
|
633
|
+
for (;;) try {
|
|
634
|
+
return (0, node_path.join)(await node_fs.promises.realpath(current), ...missing);
|
|
635
|
+
} catch {
|
|
636
|
+
const parent = (0, node_path.dirname)(current);
|
|
637
|
+
if (parent === current) return (0, node_path.resolve)(candidate);
|
|
638
|
+
missing.unshift((0, node_path.basename)(current));
|
|
639
|
+
current = parent;
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
const target = await real(path);
|
|
643
|
+
for (const root of roots) {
|
|
644
|
+
const rel = (0, node_path.relative)(await real(root), target);
|
|
645
|
+
if (rel === "" || !rel.startsWith("..") && !(0, node_path.isAbsolute)(rel)) return true;
|
|
646
|
+
}
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
/** Decides whether the browser may fetch `rawUrl`. */
|
|
650
|
+
async function isRequestAllowed(rawUrl, options) {
|
|
651
|
+
let url;
|
|
652
|
+
try {
|
|
653
|
+
url = new URL(rawUrl);
|
|
654
|
+
} catch {
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
657
|
+
switch (url.protocol) {
|
|
658
|
+
case "about:":
|
|
659
|
+
case "data:":
|
|
660
|
+
case "blob:": return true;
|
|
661
|
+
case "file:": return isFileAllowed(url, options.allowedFileRoots ?? []);
|
|
662
|
+
case "http:":
|
|
663
|
+
case "https:":
|
|
664
|
+
if (options.allowedHosts) return options.allowedHosts.some((pattern) => hostMatches(url.hostname, pattern));
|
|
665
|
+
if (options.blockPrivateNetworks === false) return true;
|
|
666
|
+
return !await resolvesToPrivateAddress(url.hostname);
|
|
667
|
+
default: return false;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
/** Logs the origin and path only: query strings may carry secrets. */
|
|
671
|
+
function describe(rawUrl) {
|
|
672
|
+
try {
|
|
673
|
+
const url = new URL(rawUrl);
|
|
674
|
+
return `${url.origin === "null" ? `${url.protocol}//` : url.origin}${url.pathname}`;
|
|
675
|
+
} catch {
|
|
676
|
+
return "<invalid url>";
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Filters every request the page (and its frames) makes, redirects included,
|
|
681
|
+
* and closes the pop-ups a script could open to escape the filter.
|
|
682
|
+
*/
|
|
683
|
+
async function installRequestGuard(context, page, options) {
|
|
684
|
+
context.on("targetcreated", (target) => {
|
|
685
|
+
if (target.type() === puppeteer.TargetType.PAGE && target.opener()) target.page().then((popup) => popup?.close()).catch(() => void 0);
|
|
686
|
+
});
|
|
687
|
+
if (options.javascriptEnabled === false) await page.setJavaScriptEnabled(false);
|
|
688
|
+
await page.setRequestInterception(true);
|
|
689
|
+
page.on("request", (request) => {
|
|
690
|
+
(async () => {
|
|
691
|
+
if (request.isInterceptResolutionHandled()) return;
|
|
692
|
+
const url = request.url();
|
|
693
|
+
const allowed = await isRequestAllowed(url, options).catch(() => false);
|
|
694
|
+
if (request.isInterceptResolutionHandled()) return;
|
|
695
|
+
if (allowed) await request.continue();
|
|
696
|
+
else {
|
|
697
|
+
_nestjs_common.Logger.warn(`Blocked request to ${describe(url)}`, "NestJsPdf");
|
|
698
|
+
await request.abort("blockedbyclient");
|
|
699
|
+
}
|
|
700
|
+
})().catch(() => void 0);
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
//#endregion
|
|
345
704
|
//#region src/helpers/tokens.ts
|
|
346
705
|
const PDF_PARAMETERS = "PDF_PARAMETERS";
|
|
347
706
|
//#endregion
|
|
@@ -358,7 +717,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
358
717
|
}
|
|
359
718
|
//#endregion
|
|
360
719
|
//#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
|
|
361
|
-
function __decorate
|
|
720
|
+
function __decorate(decorators, target, key, desc) {
|
|
362
721
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
363
722
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
364
723
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
@@ -387,47 +746,47 @@ function isTargetClosedError(error) {
|
|
|
387
746
|
return error.name === "TargetCloseError" || error.message.includes("Target closed") || error.message.includes("Target.createTarget");
|
|
388
747
|
}
|
|
389
748
|
let BrowserService = class BrowserService {
|
|
390
|
-
cacheDir;
|
|
391
|
-
options;
|
|
392
|
-
|
|
393
|
-
browser;
|
|
749
|
+
#cacheDir;
|
|
750
|
+
#options;
|
|
751
|
+
#browserInstance = null;
|
|
752
|
+
#browser;
|
|
394
753
|
activeJobs = 0;
|
|
395
754
|
totalJobs = 0;
|
|
396
|
-
recycleRequested = false;
|
|
397
|
-
recycling = false;
|
|
398
|
-
shuttingDown = false;
|
|
755
|
+
#recycleRequested = false;
|
|
756
|
+
#recycling = false;
|
|
757
|
+
#shuttingDown = false;
|
|
399
758
|
/** Max time to wait for in-flight PDF jobs to finish before closing the browser on shutdown. */
|
|
400
759
|
shutdownDrainTimeoutMs = 15e3;
|
|
401
|
-
browserTag;
|
|
402
|
-
useLockedBrowser;
|
|
403
|
-
buildId;
|
|
760
|
+
#browserTag;
|
|
761
|
+
#useLockedBrowser;
|
|
762
|
+
#buildId;
|
|
404
763
|
constructor(pdfParams) {
|
|
405
|
-
this
|
|
406
|
-
this
|
|
407
|
-
this
|
|
408
|
-
this
|
|
409
|
-
this
|
|
410
|
-
this
|
|
764
|
+
this.#cacheDir = (0, node_path.resolve)(".cache/puppeteer-browser");
|
|
765
|
+
this.#options = pdfParams;
|
|
766
|
+
this.#loadBuildId();
|
|
767
|
+
this.#loadBrowser();
|
|
768
|
+
this.#loadBrowserTag();
|
|
769
|
+
this.#loadUseLockedBrowser();
|
|
411
770
|
}
|
|
412
771
|
async onModuleDestroy() {
|
|
413
|
-
this
|
|
414
|
-
await this
|
|
415
|
-
if (this
|
|
416
|
-
await this.
|
|
772
|
+
this.#shuttingDown = true;
|
|
773
|
+
await this.#waitForIdle(this.shutdownDrainTimeoutMs);
|
|
774
|
+
if (this.#browserInstance?.connected) try {
|
|
775
|
+
await this.#browserInstance.close();
|
|
417
776
|
} catch (error) {
|
|
418
777
|
_nestjs_common.Logger.warn(`Failed to close browser on module destroy: ${error instanceof Error ? error.message : String(error)}`);
|
|
419
778
|
}
|
|
420
|
-
if (this
|
|
779
|
+
if (this.#options?.cleanupBrowserCacheOnExit !== false) await this.#cleanupCacheBestEffort();
|
|
421
780
|
}
|
|
422
781
|
/** Wait until no PDF job is in flight, or until the timeout elapses. */
|
|
423
|
-
async waitForIdle(timeoutMs) {
|
|
782
|
+
async #waitForIdle(timeoutMs) {
|
|
424
783
|
const start = Date.now();
|
|
425
784
|
while (this.activeJobs > 0 && Date.now() - start < timeoutMs) await sleep(50);
|
|
426
785
|
if (this.activeJobs > 0) _nestjs_common.Logger.warn(`Shutdown: ${this.activeJobs} PDF job(s) still running after ${timeoutMs}ms, closing the browser anyway`);
|
|
427
786
|
}
|
|
428
787
|
async getBrowserInstance(args, headless, executablePathBin) {
|
|
429
|
-
if (!this
|
|
430
|
-
return this
|
|
788
|
+
if (!this.#browserInstance?.connected) this.#browserInstance = await this.#launchBrowser(args, headless, executablePathBin);
|
|
789
|
+
return this.#browserInstance;
|
|
431
790
|
}
|
|
432
791
|
async createContext(args, headless, executablePath) {
|
|
433
792
|
const browser = await this.getBrowserInstance(args, headless, executablePath);
|
|
@@ -436,41 +795,41 @@ let BrowserService = class BrowserService {
|
|
|
436
795
|
} catch (error) {
|
|
437
796
|
if (!isTargetClosedError(error)) throw error;
|
|
438
797
|
_nestjs_common.Logger.warn("Puppeteer browser closed while creating a context, retrying once");
|
|
439
|
-
this
|
|
798
|
+
this.#browserInstance = null;
|
|
440
799
|
return await (await this.getBrowserInstance(args, headless, executablePath)).createBrowserContext();
|
|
441
800
|
}
|
|
442
801
|
}
|
|
443
802
|
markJobStarted() {
|
|
444
|
-
if (this
|
|
803
|
+
if (this.#shuttingDown) throw new BrowserUnavailableException("nestjs-pdf is shutting down, refusing new PDF jobs");
|
|
445
804
|
this.activeJobs += 1;
|
|
446
805
|
this.totalJobs += 1;
|
|
447
|
-
if (this.totalJobs >= 200) this
|
|
806
|
+
if (this.totalJobs >= 200) this.#recycleRequested = true;
|
|
448
807
|
}
|
|
449
808
|
async markJobFinished() {
|
|
450
809
|
this.activeJobs = Math.max(0, this.activeJobs - 1);
|
|
451
810
|
await this.recycleBrowserIfNeeded();
|
|
452
811
|
}
|
|
453
812
|
async recycleBrowserIfNeeded() {
|
|
454
|
-
if (!this
|
|
455
|
-
if (this
|
|
813
|
+
if (!this.#recycleRequested) return;
|
|
814
|
+
if (this.#recycling) return;
|
|
456
815
|
if (this.activeJobs > 0) return;
|
|
457
|
-
if (!this
|
|
458
|
-
this
|
|
816
|
+
if (!this.#browserInstance) return;
|
|
817
|
+
this.#recycling = true;
|
|
459
818
|
try {
|
|
460
|
-
if (this.
|
|
461
|
-
this
|
|
819
|
+
if (this.#browserInstance.connected) await this.#browserInstance.close();
|
|
820
|
+
this.#browserInstance = null;
|
|
462
821
|
this.totalJobs = 0;
|
|
463
|
-
this
|
|
822
|
+
this.#recycleRequested = false;
|
|
464
823
|
_nestjs_common.Logger.log("Puppeteer browser recycled successfully");
|
|
465
824
|
} catch (error) {
|
|
466
825
|
_nestjs_common.Logger.warn(`Failed to recycle browser: ${error instanceof Error ? error.message : String(error)}`);
|
|
467
826
|
} finally {
|
|
468
|
-
this
|
|
827
|
+
this.#recycling = false;
|
|
469
828
|
}
|
|
470
829
|
}
|
|
471
|
-
async cleanupCacheBestEffort() {
|
|
830
|
+
async #cleanupCacheBestEffort() {
|
|
472
831
|
const logger = new _nestjs_common.Logger("NestJsPdf");
|
|
473
|
-
const dir = this
|
|
832
|
+
const dir = this.#cacheDir;
|
|
474
833
|
try {
|
|
475
834
|
if (!(0, node_fs.existsSync)(dir)) return;
|
|
476
835
|
logger.log(`Cleanup puppeteer cache: ${dir}`);
|
|
@@ -491,115 +850,124 @@ let BrowserService = class BrowserService {
|
|
|
491
850
|
}
|
|
492
851
|
}
|
|
493
852
|
async install(lock = false) {
|
|
494
|
-
|
|
495
|
-
|
|
853
|
+
try {
|
|
854
|
+
return await this.#doInstall(lock);
|
|
855
|
+
} catch (error) {
|
|
856
|
+
if (error instanceof NestjsPdfException) throw error;
|
|
857
|
+
throw new BrowserInstallationException(`Could not install browser: ${String(error)}`, { cause: error });
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
async #doInstall(lock) {
|
|
861
|
+
const browser = this.#browser;
|
|
862
|
+
const versionTag = this.#browserTag;
|
|
496
863
|
const browserPlatform = (0, _puppeteer_browsers.detectBrowserPlatform)() ?? _puppeteer_browsers.BrowserPlatform.LINUX;
|
|
497
864
|
let buildId;
|
|
498
|
-
if (this
|
|
499
|
-
else buildId = this
|
|
865
|
+
if (this.#buildId === void 0) buildId = await (0, _puppeteer_browsers.resolveBuildId)(browser, browserPlatform, versionTag);
|
|
866
|
+
else buildId = this.#buildId;
|
|
500
867
|
_nestjs_common.Logger.log(`Browser ${browser} ${versionTag} build id: ${buildId}`, "NestJsPdf");
|
|
501
868
|
if (await this.hasBrowserInstalled(browser, buildId)) {
|
|
502
869
|
_nestjs_common.Logger.log("Browser already installed", "NestJsPdf");
|
|
503
|
-
if (lock) this
|
|
870
|
+
if (lock) this.#writeLockFile(browser, buildId);
|
|
504
871
|
return;
|
|
505
872
|
} else {
|
|
506
873
|
_nestjs_common.Logger.log("Starting browser installation", "NestJsPdf");
|
|
507
874
|
const installOption = {
|
|
508
|
-
cacheDir: this
|
|
875
|
+
cacheDir: this.#cacheDir,
|
|
509
876
|
browser,
|
|
510
877
|
buildId,
|
|
511
|
-
baseUrl: this
|
|
878
|
+
baseUrl: this.#options?.browserInstallBaseUrl ?? void 0
|
|
512
879
|
};
|
|
513
880
|
if (await (0, _puppeteer_browsers.canDownload)(installOption)) {
|
|
514
881
|
_nestjs_common.Logger.log(`Installing ${installOption.browser} ${installOption.buildId}`, "NestJsPdf");
|
|
515
882
|
const installedBrowser = await (0, _puppeteer_browsers.install)(installOption);
|
|
516
883
|
if (await this.hasBrowserInstalled(browser, buildId)) {
|
|
517
884
|
_nestjs_common.Logger.log("Browser installed successfully", "NestJsPdf");
|
|
518
|
-
if (lock) this
|
|
885
|
+
if (lock) this.#writeLockFile(browser, buildId);
|
|
519
886
|
return installedBrowser;
|
|
520
887
|
} else _nestjs_common.Logger.error("Browser installation failed", "NestJsPdf");
|
|
521
888
|
} else _nestjs_common.Logger.error(`Error, can't install ${installOption.browser} ${installOption.buildId}`, "NestJsPdf");
|
|
522
889
|
}
|
|
523
890
|
return null;
|
|
524
891
|
}
|
|
525
|
-
loadBrowser() {
|
|
892
|
+
#loadBrowser() {
|
|
526
893
|
let browser;
|
|
527
|
-
if (this
|
|
528
|
-
else browser = this
|
|
529
|
-
this
|
|
894
|
+
if (this.#options?.browser === void 0) browser = _puppeteer_browsers.Browser.CHROMIUM;
|
|
895
|
+
else browser = this.#options.browser;
|
|
896
|
+
this.#browser = browser;
|
|
530
897
|
}
|
|
531
898
|
getBrowser() {
|
|
532
|
-
return this
|
|
899
|
+
return this.#browser;
|
|
533
900
|
}
|
|
534
|
-
loadBrowserTag() {
|
|
901
|
+
#loadBrowserTag() {
|
|
535
902
|
let versionTag;
|
|
536
|
-
if (this
|
|
537
|
-
if (this
|
|
903
|
+
if (this.#options?.browserTag === void 0) {
|
|
904
|
+
if (this.#browser === _puppeteer_browsers.Browser.CHROMIUM) versionTag = "latest";
|
|
538
905
|
else versionTag = "stable";
|
|
539
|
-
} else versionTag = this
|
|
540
|
-
this
|
|
906
|
+
} else versionTag = this.#options.browserTag;
|
|
907
|
+
this.#browserTag = versionTag;
|
|
541
908
|
}
|
|
542
|
-
loadBuildId() {
|
|
909
|
+
#loadBuildId() {
|
|
543
910
|
let buildId;
|
|
544
|
-
if (this
|
|
545
|
-
else buildId = this
|
|
546
|
-
this
|
|
911
|
+
if (this.#options?.buildId === void 0) buildId = void 0;
|
|
912
|
+
else buildId = this.#options.buildId;
|
|
913
|
+
this.#buildId = buildId;
|
|
547
914
|
}
|
|
548
915
|
setBrowserTag(browserTag) {
|
|
549
|
-
this
|
|
916
|
+
this.#browserTag = browserTag;
|
|
550
917
|
}
|
|
551
918
|
getBrowserTag() {
|
|
552
|
-
return this
|
|
919
|
+
return this.#browserTag;
|
|
553
920
|
}
|
|
554
921
|
getBuildId() {
|
|
555
|
-
return this
|
|
922
|
+
return this.#buildId;
|
|
556
923
|
}
|
|
557
|
-
loadUseLockedBrowser() {
|
|
924
|
+
#loadUseLockedBrowser() {
|
|
558
925
|
let useLockedBrowser;
|
|
559
|
-
if (this
|
|
560
|
-
else useLockedBrowser = this
|
|
561
|
-
this
|
|
926
|
+
if (this.#options?.useLockedBrowser === void 0) useLockedBrowser = false;
|
|
927
|
+
else useLockedBrowser = this.#options.useLockedBrowser;
|
|
928
|
+
this.#useLockedBrowser = useLockedBrowser;
|
|
562
929
|
}
|
|
563
930
|
async hasBrowserInstalled(browser, buildId) {
|
|
564
|
-
return (await (0, _puppeteer_browsers.getInstalledBrowsers)({ cacheDir: this
|
|
931
|
+
return (await (0, _puppeteer_browsers.getInstalledBrowsers)({ cacheDir: this.#cacheDir })).find((insBrowser) => {
|
|
565
932
|
return insBrowser.browser === browser && insBrowser.buildId === buildId;
|
|
566
933
|
}) !== void 0;
|
|
567
934
|
}
|
|
568
935
|
async getExecutablePath() {
|
|
569
|
-
const browser = this
|
|
570
|
-
const versionTag = this
|
|
936
|
+
const browser = this.#browser;
|
|
937
|
+
const versionTag = this.#browserTag;
|
|
571
938
|
const browserPlatform = (0, _puppeteer_browsers.detectBrowserPlatform)() ?? _puppeteer_browsers.BrowserPlatform.LINUX;
|
|
572
939
|
let buildId = null;
|
|
573
|
-
if (this
|
|
940
|
+
if (this.#useLockedBrowser) {
|
|
574
941
|
buildId = this.getLockedBuildId(browser);
|
|
575
942
|
_nestjs_common.Logger.log(`Using locked browser ${buildId}`, "NestJsPdf");
|
|
576
943
|
}
|
|
577
944
|
buildId ??= await (0, _puppeteer_browsers.resolveBuildId)(browser, browserPlatform, versionTag);
|
|
578
|
-
const installedBrowser = (await (0, _puppeteer_browsers.getInstalledBrowsers)({ cacheDir: this
|
|
945
|
+
const installedBrowser = (await (0, _puppeteer_browsers.getInstalledBrowsers)({ cacheDir: this.#cacheDir })).find((insBrowser) => {
|
|
579
946
|
return insBrowser.browser === browser && insBrowser.buildId === buildId;
|
|
580
947
|
});
|
|
581
948
|
if (installedBrowser === void 0) {
|
|
582
949
|
const newinstalledBrowser = await this.install();
|
|
583
|
-
if (newinstalledBrowser === null || newinstalledBrowser === void 0) throw new
|
|
950
|
+
if (newinstalledBrowser === null || newinstalledBrowser === void 0) throw new BrowserInstallationException("Could not install browser");
|
|
584
951
|
else return newinstalledBrowser.executablePath;
|
|
585
952
|
}
|
|
586
953
|
return installedBrowser.executablePath;
|
|
587
954
|
}
|
|
588
|
-
async launchBrowser(args, headless, executablePathBin) {
|
|
955
|
+
async #launchBrowser(args, headless, executablePathBin) {
|
|
589
956
|
const executablePath = executablePathBin ?? await this.getExecutablePath();
|
|
590
957
|
const browser = await (0, puppeteer.launch)({
|
|
591
958
|
executablePath,
|
|
592
959
|
headless,
|
|
593
|
-
args
|
|
960
|
+
args,
|
|
961
|
+
ignoreDefaultArgs: ["--disable-popup-blocking"]
|
|
594
962
|
});
|
|
595
963
|
browser.on("disconnected", () => {
|
|
596
964
|
_nestjs_common.Logger.warn("Puppeteer browser disconnected");
|
|
597
|
-
if (this
|
|
965
|
+
if (this.#browserInstance === browser) this.#browserInstance = null;
|
|
598
966
|
});
|
|
599
967
|
return browser;
|
|
600
968
|
}
|
|
601
|
-
writeLockFile(browser, buildId) {
|
|
602
|
-
const lockFile = (0, node_path.resolve)(this
|
|
969
|
+
#writeLockFile(browser, buildId) {
|
|
970
|
+
const lockFile = (0, node_path.resolve)(this.#cacheDir, `${browser}.lock`);
|
|
603
971
|
const data = JSON.stringify({
|
|
604
972
|
browser,
|
|
605
973
|
buildId,
|
|
@@ -609,7 +977,7 @@ let BrowserService = class BrowserService {
|
|
|
609
977
|
_nestjs_common.Logger.log(`Browser ${browser} locked to build ${buildId}`, "NestJsPdf");
|
|
610
978
|
}
|
|
611
979
|
getLockedBuildId(browser) {
|
|
612
|
-
const lockFile = (0, node_path.resolve)(this
|
|
980
|
+
const lockFile = (0, node_path.resolve)(this.#cacheDir, `${browser}.lock`);
|
|
613
981
|
if ((0, node_fs.existsSync)(lockFile)) {
|
|
614
982
|
const data = (0, node_fs.readFileSync)(lockFile);
|
|
615
983
|
return JSON.parse(data.toString()).buildId;
|
|
@@ -617,7 +985,7 @@ let BrowserService = class BrowserService {
|
|
|
617
985
|
return null;
|
|
618
986
|
}
|
|
619
987
|
};
|
|
620
|
-
BrowserService = __decorate
|
|
988
|
+
BrowserService = __decorate([
|
|
621
989
|
(0, _nestjs_common.Injectable)(),
|
|
622
990
|
__decorateParam(0, (0, _nestjs_common.Inject)("PDF_PARAMETERS")),
|
|
623
991
|
__decorateMetadata("design:paramtypes", [Object])
|
|
@@ -632,7 +1000,7 @@ let EjsService = class EjsService {
|
|
|
632
1000
|
...options
|
|
633
1001
|
});
|
|
634
1002
|
} catch (error) {
|
|
635
|
-
throw new
|
|
1003
|
+
throw new TemplateRenderException("EJS", `EJS rendering failed: ${String(error)}`, { cause: error });
|
|
636
1004
|
}
|
|
637
1005
|
}
|
|
638
1006
|
async renderFile(filePath, data = {}, options) {
|
|
@@ -642,19 +1010,19 @@ let EjsService = class EjsService {
|
|
|
642
1010
|
...options
|
|
643
1011
|
});
|
|
644
1012
|
} catch (error) {
|
|
645
|
-
throw new
|
|
1013
|
+
throw new TemplateRenderException("EJS", `EJS file rendering failed: ${String(error)}`, { cause: error });
|
|
646
1014
|
}
|
|
647
1015
|
}
|
|
648
1016
|
};
|
|
649
|
-
EjsService = __decorate
|
|
1017
|
+
EjsService = __decorate([(0, _nestjs_common.Injectable)()], EjsService);
|
|
650
1018
|
//#endregion
|
|
651
1019
|
//#region src/puppeteer/engines/eta/eta.service.ts
|
|
652
1020
|
let EtaService = class EtaService {
|
|
653
|
-
eta;
|
|
654
|
-
templateCache = /* @__PURE__ */ new Map();
|
|
655
|
-
maxCacheSize = 100;
|
|
1021
|
+
#eta;
|
|
1022
|
+
#templateCache = /* @__PURE__ */ new Map();
|
|
1023
|
+
#maxCacheSize = 100;
|
|
656
1024
|
constructor() {
|
|
657
|
-
this
|
|
1025
|
+
this.#eta = new eta.Eta({
|
|
658
1026
|
cache: true,
|
|
659
1027
|
autoEscape: true,
|
|
660
1028
|
useWith: true
|
|
@@ -675,9 +1043,9 @@ let EtaService = class EtaService {
|
|
|
675
1043
|
useWith: true,
|
|
676
1044
|
...options,
|
|
677
1045
|
varName: options.varName ?? "it"
|
|
678
|
-
}) : this
|
|
1046
|
+
}) : this.#eta).renderString(template, data);
|
|
679
1047
|
} catch (error) {
|
|
680
|
-
throw new
|
|
1048
|
+
throw new TemplateRenderException("Eta", `Eta rendering failed: ${String(error)}`, { cause: error });
|
|
681
1049
|
}
|
|
682
1050
|
}
|
|
683
1051
|
/**
|
|
@@ -691,53 +1059,54 @@ let EtaService = class EtaService {
|
|
|
691
1059
|
try {
|
|
692
1060
|
const resolvedPath = (0, node_path.resolve)(filePath);
|
|
693
1061
|
const useCache = options?.cache ?? true;
|
|
694
|
-
let template = useCache ? this
|
|
1062
|
+
let template = useCache ? this.#templateCache.get(resolvedPath) : void 0;
|
|
695
1063
|
if (!template) {
|
|
696
1064
|
template = (0, node_fs.readFileSync)(resolvedPath, "utf-8");
|
|
697
|
-
if (useCache && this
|
|
1065
|
+
if (useCache && this.#templateCache.size < this.#maxCacheSize) this.#templateCache.set(resolvedPath, template);
|
|
698
1066
|
}
|
|
699
1067
|
return this.render(template, data, options);
|
|
700
1068
|
} catch (error) {
|
|
701
|
-
throw new
|
|
1069
|
+
throw new TemplateRenderException("Eta", `Eta file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
|
|
702
1070
|
}
|
|
703
1071
|
}
|
|
704
1072
|
/**
|
|
705
1073
|
* Clear the template cache
|
|
706
1074
|
*/
|
|
707
1075
|
clearCache() {
|
|
708
|
-
this
|
|
1076
|
+
this.#templateCache.clear();
|
|
709
1077
|
}
|
|
710
1078
|
/**
|
|
711
1079
|
* Get the current cache size
|
|
712
1080
|
* @returns The number of cached templates
|
|
713
1081
|
*/
|
|
714
1082
|
getCacheSize() {
|
|
715
|
-
return this
|
|
1083
|
+
return this.#templateCache.size;
|
|
716
1084
|
}
|
|
717
1085
|
};
|
|
718
|
-
EtaService = __decorate
|
|
1086
|
+
EtaService = __decorate([(0, _nestjs_common.Injectable)(), __decorateMetadata("design:paramtypes", [])], EtaService);
|
|
719
1087
|
//#endregion
|
|
720
1088
|
//#region src/puppeteer/engines/handlebars/handlebars.service.ts
|
|
721
1089
|
let HandlebarsService = class HandlebarsService {
|
|
722
|
-
cachedOptions;
|
|
723
|
-
cachedEnv;
|
|
1090
|
+
#cachedOptions;
|
|
1091
|
+
#cachedEnv;
|
|
724
1092
|
render(template, parameters = {}, options = {}) {
|
|
725
1093
|
try {
|
|
726
|
-
return this
|
|
1094
|
+
return this.#getEnv(options).compile(template, options.compileOptions)(parameters, options.templateOptions);
|
|
727
1095
|
} catch (error) {
|
|
728
|
-
|
|
1096
|
+
if (error instanceof NestjsPdfException) throw error;
|
|
1097
|
+
throw new TemplateRenderException("Handlebars", `Handlebars rendering failed: ${String(error)}`, { cause: error });
|
|
729
1098
|
}
|
|
730
1099
|
}
|
|
731
1100
|
renderFile(file, parameters = {}, options = {}) {
|
|
732
|
-
if (options.templateDirectory === void 0) throw new
|
|
1101
|
+
if (options.templateDirectory === void 0) throw new TemplateConfigurationException("Handlebars file rendering failed: option `templateDirectory` is not set");
|
|
733
1102
|
const baseDir = (0, node_path.resolve)(process.cwd(), options.templateDirectory);
|
|
734
1103
|
const templatePath = (0, node_path.resolve)(baseDir, file);
|
|
735
|
-
if (templatePath !== baseDir && !templatePath.startsWith(baseDir + node_path.sep)) throw new
|
|
1104
|
+
if (templatePath !== baseDir && !templatePath.startsWith(baseDir + node_path.sep)) throw new TemplateConfigurationException(`Handlebars file rendering failed: ’${file}’ resolves outside \`templateDirectory\``);
|
|
736
1105
|
let template;
|
|
737
1106
|
try {
|
|
738
1107
|
template = (0, node_fs.readFileSync)(templatePath, "utf8");
|
|
739
1108
|
} catch (error) {
|
|
740
|
-
throw new
|
|
1109
|
+
throw new TemplateRenderException("Handlebars", `Handlebars file rendering failed: ${String(error)}`, { cause: error });
|
|
741
1110
|
}
|
|
742
1111
|
return this.render(template, parameters, options);
|
|
743
1112
|
}
|
|
@@ -746,19 +1115,19 @@ let HandlebarsService = class HandlebarsService {
|
|
|
746
1115
|
* nothing leaks into the global Handlebars. Memoised for the common case where
|
|
747
1116
|
* the same options object is reused across calls (e.g. the module `hbsOptions`).
|
|
748
1117
|
*/
|
|
749
|
-
getEnv(options) {
|
|
750
|
-
if (this
|
|
1118
|
+
#getEnv(options) {
|
|
1119
|
+
if (this.#cachedEnv && this.#cachedOptions === options) return this.#cachedEnv;
|
|
751
1120
|
const env = handlebars.default.create();
|
|
752
1121
|
for (const helper of options.helpers ?? []) env.registerHelper(helper.name, helper.fn);
|
|
753
|
-
this
|
|
754
|
-
this
|
|
755
|
-
this
|
|
1122
|
+
this.#registerPartials(env, options.partialDirectory);
|
|
1123
|
+
this.#cachedOptions = options;
|
|
1124
|
+
this.#cachedEnv = env;
|
|
756
1125
|
return env;
|
|
757
1126
|
}
|
|
758
|
-
registerPartials(env, partialDirectory) {
|
|
1127
|
+
#registerPartials(env, partialDirectory) {
|
|
759
1128
|
if (partialDirectory === void 0) return;
|
|
760
1129
|
const partialPath = (0, node_path.join)(process.cwd(), partialDirectory);
|
|
761
|
-
if (!(0, node_fs.existsSync)(partialPath)) throw new
|
|
1130
|
+
if (!(0, node_fs.existsSync)(partialPath)) throw new TemplateConfigurationException(`Handlebars partial directory does not exist: ${partialPath}`);
|
|
762
1131
|
for (const entry of (0, node_fs.readdirSync)(partialPath)) {
|
|
763
1132
|
const filePath = (0, node_path.join)(partialPath, entry);
|
|
764
1133
|
if (!(0, node_fs.statSync)(filePath).isFile()) continue;
|
|
@@ -766,25 +1135,34 @@ let HandlebarsService = class HandlebarsService {
|
|
|
766
1135
|
}
|
|
767
1136
|
}
|
|
768
1137
|
};
|
|
769
|
-
HandlebarsService = __decorate
|
|
1138
|
+
HandlebarsService = __decorate([(0, _nestjs_common.Injectable)()], HandlebarsService);
|
|
770
1139
|
//#endregion
|
|
771
1140
|
//#region src/puppeteer/engines/mjml/mjml.service.ts
|
|
772
1141
|
let MjmlService = class MjmlService {
|
|
773
1142
|
async render(template, options) {
|
|
774
|
-
|
|
775
|
-
|
|
1143
|
+
try {
|
|
1144
|
+
const { html } = await (0, mjml.default)(template, options);
|
|
1145
|
+
return html;
|
|
1146
|
+
} catch (error) {
|
|
1147
|
+
throw new TemplateRenderException("MJML", `MJML rendering failed: ${String(error)}`, { cause: error });
|
|
1148
|
+
}
|
|
776
1149
|
}
|
|
777
1150
|
async renderFile(filePath, options) {
|
|
778
|
-
|
|
1151
|
+
let template;
|
|
1152
|
+
try {
|
|
1153
|
+
template = (0, node_fs.readFileSync)(filePath, "utf-8");
|
|
1154
|
+
} catch (error) {
|
|
1155
|
+
throw new TemplateRenderException("MJML", `MJML file rendering failed: ${String(error)}`, { cause: error });
|
|
1156
|
+
}
|
|
779
1157
|
return await this.render(template, options);
|
|
780
1158
|
}
|
|
781
1159
|
};
|
|
782
|
-
MjmlService = __decorate
|
|
1160
|
+
MjmlService = __decorate([(0, _nestjs_common.Injectable)()], MjmlService);
|
|
783
1161
|
//#endregion
|
|
784
1162
|
//#region src/puppeteer/engines/mustache/mustache.service.ts
|
|
785
1163
|
let MustacheService = class MustacheService {
|
|
786
|
-
templateCache = /* @__PURE__ */ new Map();
|
|
787
|
-
maxCacheSize = 100;
|
|
1164
|
+
#templateCache = /* @__PURE__ */ new Map();
|
|
1165
|
+
#maxCacheSize = 100;
|
|
788
1166
|
/**
|
|
789
1167
|
* Render a Mustache template from a string
|
|
790
1168
|
* @param template The template string to render
|
|
@@ -800,7 +1178,7 @@ let MustacheService = class MustacheService {
|
|
|
800
1178
|
escape: options?.escape
|
|
801
1179
|
});
|
|
802
1180
|
} catch (error) {
|
|
803
|
-
throw new
|
|
1181
|
+
throw new TemplateRenderException("Mustache", `Mustache rendering failed: ${String(error)}`, { cause: error });
|
|
804
1182
|
}
|
|
805
1183
|
}
|
|
806
1184
|
/**
|
|
@@ -813,31 +1191,31 @@ let MustacheService = class MustacheService {
|
|
|
813
1191
|
renderFile(filePath, data = {}, options) {
|
|
814
1192
|
try {
|
|
815
1193
|
const resolvedPath = (0, node_path.resolve)(filePath);
|
|
816
|
-
let template = this
|
|
1194
|
+
let template = this.#templateCache.get(resolvedPath);
|
|
817
1195
|
if (!template) {
|
|
818
1196
|
template = (0, node_fs.readFileSync)(resolvedPath, "utf-8");
|
|
819
|
-
if (this
|
|
1197
|
+
if (this.#templateCache.size < this.#maxCacheSize) this.#templateCache.set(resolvedPath, template);
|
|
820
1198
|
}
|
|
821
1199
|
return this.render(template, data, options);
|
|
822
1200
|
} catch (error) {
|
|
823
|
-
throw new
|
|
1201
|
+
throw new TemplateRenderException("Mustache", `Mustache file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
|
|
824
1202
|
}
|
|
825
1203
|
}
|
|
826
1204
|
/**
|
|
827
1205
|
* Clear the template cache
|
|
828
1206
|
*/
|
|
829
1207
|
clearCache() {
|
|
830
|
-
this
|
|
1208
|
+
this.#templateCache.clear();
|
|
831
1209
|
}
|
|
832
1210
|
/**
|
|
833
1211
|
* Get the current cache size
|
|
834
1212
|
* @returns The number of cached templates
|
|
835
1213
|
*/
|
|
836
1214
|
getCacheSize() {
|
|
837
|
-
return this
|
|
1215
|
+
return this.#templateCache.size;
|
|
838
1216
|
}
|
|
839
1217
|
};
|
|
840
|
-
MustacheService = __decorate
|
|
1218
|
+
MustacheService = __decorate([(0, _nestjs_common.Injectable)()], MustacheService);
|
|
841
1219
|
//#endregion
|
|
842
1220
|
//#region src/puppeteer/engines/nunjucks/nunjucks.service.ts
|
|
843
1221
|
let NunjucksService = class NunjucksService {
|
|
@@ -862,7 +1240,7 @@ let NunjucksService = class NunjucksService {
|
|
|
862
1240
|
}
|
|
863
1241
|
return nunjucks.default.renderString(template, data);
|
|
864
1242
|
} catch (error) {
|
|
865
|
-
throw new
|
|
1243
|
+
throw new TemplateRenderException("Nunjucks", `Nunjucks rendering failed: ${String(error)}`, { cause: error });
|
|
866
1244
|
}
|
|
867
1245
|
}
|
|
868
1246
|
renderFile(filePath, data = {}, options) {
|
|
@@ -879,11 +1257,11 @@ let NunjucksService = class NunjucksService {
|
|
|
879
1257
|
}
|
|
880
1258
|
return nunjucks.default.render(filePath, data);
|
|
881
1259
|
} catch (error) {
|
|
882
|
-
throw new
|
|
1260
|
+
throw new TemplateRenderException("Nunjucks", `Nunjucks file rendering failed: ${String(error)}`, { cause: error });
|
|
883
1261
|
}
|
|
884
1262
|
}
|
|
885
1263
|
};
|
|
886
|
-
NunjucksService = __decorate
|
|
1264
|
+
NunjucksService = __decorate([(0, _nestjs_common.Injectable)(), __decorateMetadata("design:paramtypes", [])], NunjucksService);
|
|
887
1265
|
//#endregion
|
|
888
1266
|
//#region src/puppeteer/engines/pug/pug.service.ts
|
|
889
1267
|
let PugService = class PugService {
|
|
@@ -891,7 +1269,7 @@ let PugService = class PugService {
|
|
|
891
1269
|
try {
|
|
892
1270
|
return pug.default.compile(template, { ...options })(data);
|
|
893
1271
|
} catch (error) {
|
|
894
|
-
throw new
|
|
1272
|
+
throw new TemplateRenderException("Pug", `Pug rendering failed: ${String(error)}`, { cause: error });
|
|
895
1273
|
}
|
|
896
1274
|
}
|
|
897
1275
|
renderFile(filePath, data = {}, options) {
|
|
@@ -899,44 +1277,49 @@ let PugService = class PugService {
|
|
|
899
1277
|
const template = (0, node_fs.readFileSync)(filePath, "utf-8");
|
|
900
1278
|
return this.render(template, data, options);
|
|
901
1279
|
} catch (error) {
|
|
902
|
-
throw new
|
|
1280
|
+
throw new TemplateRenderException("Pug", `Pug file rendering failed: ${String(error)}`, { cause: error });
|
|
903
1281
|
}
|
|
904
1282
|
}
|
|
905
1283
|
};
|
|
906
|
-
PugService = __decorate
|
|
1284
|
+
PugService = __decorate([(0, _nestjs_common.Injectable)()], PugService);
|
|
907
1285
|
//#endregion
|
|
908
1286
|
//#region src/puppeteer/libs/requireService.utils.ts
|
|
909
1287
|
function requireService(service, name) {
|
|
910
|
-
if (!service) throw new
|
|
1288
|
+
if (!service) throw new EngineNotAvailableException(name);
|
|
911
1289
|
return service;
|
|
912
1290
|
}
|
|
913
1291
|
//#endregion
|
|
914
1292
|
//#region src/puppeteer/puppeteer.service.ts
|
|
915
1293
|
let PuppeteerService = class PuppeteerService {
|
|
916
|
-
browserService;
|
|
917
|
-
options;
|
|
918
|
-
hbsService;
|
|
919
|
-
mjmlService;
|
|
920
|
-
pugService;
|
|
921
|
-
ejsService;
|
|
922
|
-
nunjucksService;
|
|
923
|
-
etaService;
|
|
924
|
-
mustacheService;
|
|
1294
|
+
#browserService;
|
|
1295
|
+
#options;
|
|
1296
|
+
#hbsService;
|
|
1297
|
+
#mjmlService;
|
|
1298
|
+
#pugService;
|
|
1299
|
+
#ejsService;
|
|
1300
|
+
#nunjucksService;
|
|
1301
|
+
#etaService;
|
|
1302
|
+
#mustacheService;
|
|
925
1303
|
constructor(browserService, options, hbsService, mjmlService, pugService, ejsService, nunjucksService, etaService, mustacheService) {
|
|
926
|
-
this
|
|
927
|
-
this
|
|
928
|
-
this
|
|
929
|
-
this
|
|
930
|
-
this
|
|
931
|
-
this
|
|
932
|
-
this
|
|
933
|
-
this
|
|
934
|
-
this
|
|
935
|
-
}
|
|
936
|
-
limit = pLimit(3);
|
|
1304
|
+
this.#browserService = browserService;
|
|
1305
|
+
this.#options = options;
|
|
1306
|
+
this.#hbsService = hbsService;
|
|
1307
|
+
this.#mjmlService = mjmlService;
|
|
1308
|
+
this.#pugService = pugService;
|
|
1309
|
+
this.#ejsService = ejsService;
|
|
1310
|
+
this.#nunjucksService = nunjucksService;
|
|
1311
|
+
this.#etaService = etaService;
|
|
1312
|
+
this.#mustacheService = mustacheService;
|
|
1313
|
+
}
|
|
1314
|
+
#limit = pLimit(3);
|
|
937
1315
|
async generatePdfFromHtml(html, options) {
|
|
938
|
-
|
|
939
|
-
|
|
1316
|
+
const signal = options?.signal ?? this.#options.signal;
|
|
1317
|
+
signal?.throwIfAborted();
|
|
1318
|
+
let started = false;
|
|
1319
|
+
const job = this.#limit(async () => {
|
|
1320
|
+
signal?.throwIfAborted();
|
|
1321
|
+
started = true;
|
|
1322
|
+
const mergePuppeteerOptions = mergePuppeteerParameters(this.#options, options);
|
|
940
1323
|
if (mergePuppeteerOptions.chromiumRevision !== void 0) _nestjs_common.Logger.warn("Using `chromiumRevision` is no longer supported since the puppeteer update.");
|
|
941
1324
|
const headless = mergePuppeteerOptions.headless ?? true;
|
|
942
1325
|
const executablePath = mergePuppeteerOptions.executablePath || void 0;
|
|
@@ -957,7 +1340,6 @@ let PuppeteerService = class PuppeteerService {
|
|
|
957
1340
|
"--disable-ipc-flooding-protection",
|
|
958
1341
|
"--disable-notifications",
|
|
959
1342
|
"--disable-offer-store-unmasked-wallet-cards",
|
|
960
|
-
"--disable-popup-blocking",
|
|
961
1343
|
"--disable-print-preview",
|
|
962
1344
|
"--disable-prompt-on-repost",
|
|
963
1345
|
"--disable-renderer-backgrounding",
|
|
@@ -978,11 +1360,20 @@ let PuppeteerService = class PuppeteerService {
|
|
|
978
1360
|
"--no-zygote",
|
|
979
1361
|
"--disable-gpu"
|
|
980
1362
|
];
|
|
981
|
-
this
|
|
1363
|
+
this.#browserService.markJobStarted();
|
|
982
1364
|
let context = null;
|
|
1365
|
+
let closing;
|
|
1366
|
+
const onAbort = () => {
|
|
1367
|
+
if (!context) return;
|
|
1368
|
+
closing = context.close();
|
|
1369
|
+
closing.catch(() => void 0);
|
|
1370
|
+
};
|
|
1371
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
983
1372
|
try {
|
|
984
|
-
context = await this
|
|
1373
|
+
context = await this.#browserService.createContext(args, headless, executablePath);
|
|
1374
|
+
signal?.throwIfAborted();
|
|
985
1375
|
const page = await context.newPage();
|
|
1376
|
+
if (mergePuppeteerOptions.security) await installRequestGuard(context, page, mergePuppeteerOptions.security);
|
|
986
1377
|
const pdfOptions = mergePuppeteerOptions.pdfOptions ?? { format: "A4" };
|
|
987
1378
|
await page.setContent(html, { waitUntil: "domcontentloaded" });
|
|
988
1379
|
await page.emulateMediaType("screen");
|
|
@@ -992,78 +1383,97 @@ let PuppeteerService = class PuppeteerService {
|
|
|
992
1383
|
});
|
|
993
1384
|
/* v8 ignore next */
|
|
994
1385
|
await page.evaluate(() => document.fonts.ready);
|
|
995
|
-
|
|
1386
|
+
const pdf = await page.pdf(pdfOptions);
|
|
1387
|
+
signal?.throwIfAborted();
|
|
1388
|
+
return mergePuppeteerOptions.watermark ? await addWatermark(pdf, mergePuppeteerOptions.watermark) : pdf;
|
|
996
1389
|
} catch (e) {
|
|
1390
|
+
if (signal?.aborted) throw signal.reason;
|
|
997
1391
|
_nestjs_common.Logger.error(e);
|
|
998
|
-
throw e;
|
|
1392
|
+
if (e instanceof NestjsPdfException) throw e;
|
|
1393
|
+
throw new PdfGenerationException(`PDF generation failed: ${String(e)}`, { cause: e });
|
|
999
1394
|
} finally {
|
|
1395
|
+
signal?.removeEventListener("abort", onAbort);
|
|
1000
1396
|
if (context) try {
|
|
1001
|
-
|
|
1397
|
+
if (closing) await closing;
|
|
1398
|
+
else await context.close();
|
|
1002
1399
|
} catch (error) {
|
|
1003
1400
|
_nestjs_common.Logger.error(error);
|
|
1004
1401
|
}
|
|
1005
|
-
await this
|
|
1402
|
+
await this.#browserService.markJobFinished();
|
|
1006
1403
|
}
|
|
1007
1404
|
});
|
|
1405
|
+
if (!signal) return job;
|
|
1406
|
+
let onQueuedAbort;
|
|
1407
|
+
const abortedWhileQueued = new Promise((_, reject) => {
|
|
1408
|
+
onQueuedAbort = () => {
|
|
1409
|
+
if (!started) reject(signal.reason);
|
|
1410
|
+
};
|
|
1411
|
+
signal.addEventListener("abort", onQueuedAbort, { once: true });
|
|
1412
|
+
});
|
|
1413
|
+
try {
|
|
1414
|
+
return await Promise.race([job, abortedWhileQueued]);
|
|
1415
|
+
} finally {
|
|
1416
|
+
signal.removeEventListener("abort", onQueuedAbort);
|
|
1417
|
+
}
|
|
1008
1418
|
}
|
|
1009
1419
|
async generatePdfFromTemplateHbsString(template, parameters = {}, options) {
|
|
1010
|
-
const html = requireService(this
|
|
1420
|
+
const html = requireService(this.#hbsService, "Handlebars").render(template, parameters, options?.hbsOptions ?? this.#options.hbsOptions);
|
|
1011
1421
|
return this.generatePdfFromHtml(html, options);
|
|
1012
1422
|
}
|
|
1013
1423
|
async generatePdfFromTemplateHbsFile(file, parameters = {}, options) {
|
|
1014
|
-
const html = requireService(this
|
|
1424
|
+
const html = requireService(this.#hbsService, "Handlebars").renderFile(file, parameters, options?.hbsOptions ?? this.#options.hbsOptions);
|
|
1015
1425
|
return this.generatePdfFromHtml(html, options);
|
|
1016
1426
|
}
|
|
1017
1427
|
async generatePdfFromMjmlString(template, options) {
|
|
1018
|
-
const html = await requireService(this
|
|
1428
|
+
const html = await requireService(this.#mjmlService, "MJML").render(template, options?.mjmlOptions ?? this.#options.mjmlOptions);
|
|
1019
1429
|
return this.generatePdfFromHtml(html, options);
|
|
1020
1430
|
}
|
|
1021
1431
|
async generatePdfFromMjmlFile(file, options) {
|
|
1022
|
-
const html = await requireService(this
|
|
1432
|
+
const html = await requireService(this.#mjmlService, "MJML").renderFile(file, options?.mjmlOptions ?? this.#options.mjmlOptions);
|
|
1023
1433
|
return this.generatePdfFromHtml(html, options);
|
|
1024
1434
|
}
|
|
1025
1435
|
async generatePdfFromPugString(template, data = {}, options) {
|
|
1026
|
-
const html = requireService(this
|
|
1436
|
+
const html = requireService(this.#pugService, "Pug").render(template, data, options?.pugOptions ?? this.#options.pugOptions);
|
|
1027
1437
|
return this.generatePdfFromHtml(html, options);
|
|
1028
1438
|
}
|
|
1029
1439
|
async generatePdfFromPugFile(file, data = {}, options) {
|
|
1030
|
-
const html = requireService(this
|
|
1440
|
+
const html = requireService(this.#pugService, "Pug").renderFile(file, data, options?.pugOptions ?? this.#options.pugOptions);
|
|
1031
1441
|
return this.generatePdfFromHtml(html, options);
|
|
1032
1442
|
}
|
|
1033
1443
|
async generatePdfFromEjsString(template, data = {}, options) {
|
|
1034
|
-
const html = await requireService(this
|
|
1444
|
+
const html = await requireService(this.#ejsService, "EJS").render(template, data, options?.ejsOptions ?? this.#options.ejsOptions);
|
|
1035
1445
|
return this.generatePdfFromHtml(html, options);
|
|
1036
1446
|
}
|
|
1037
1447
|
async generatePdfFromEjsFile(file, data = {}, options) {
|
|
1038
|
-
const html = await requireService(this
|
|
1448
|
+
const html = await requireService(this.#ejsService, "EJS").renderFile(file, data, options?.ejsOptions ?? this.#options.ejsOptions);
|
|
1039
1449
|
return this.generatePdfFromHtml(html, options);
|
|
1040
1450
|
}
|
|
1041
1451
|
async generatePdfFromNunjucksString(template, data = {}, options) {
|
|
1042
|
-
const html = requireService(this
|
|
1452
|
+
const html = requireService(this.#nunjucksService, "Nunjucks").render(template, data, options?.nunjucksOptions ?? this.#options.nunjucksOptions);
|
|
1043
1453
|
return this.generatePdfFromHtml(html, options);
|
|
1044
1454
|
}
|
|
1045
1455
|
async generatePdfFromNunjucksFile(file, data = {}, options) {
|
|
1046
|
-
const html = requireService(this
|
|
1456
|
+
const html = requireService(this.#nunjucksService, "Nunjucks").renderFile(file, data, options?.nunjucksOptions ?? this.#options.nunjucksOptions);
|
|
1047
1457
|
return this.generatePdfFromHtml(html, options);
|
|
1048
1458
|
}
|
|
1049
1459
|
async generatePdfFromEtaString(template, data = {}, options) {
|
|
1050
|
-
const html = requireService(this
|
|
1460
|
+
const html = requireService(this.#etaService, "Eta").render(template, data, options?.etaOptions ?? this.#options.etaOptions);
|
|
1051
1461
|
return this.generatePdfFromHtml(html, options);
|
|
1052
1462
|
}
|
|
1053
1463
|
async generatePdfFromEtaFile(file, data = {}, options) {
|
|
1054
|
-
const html = requireService(this
|
|
1464
|
+
const html = requireService(this.#etaService, "Eta").renderFile(file, data, options?.etaOptions ?? this.#options.etaOptions);
|
|
1055
1465
|
return this.generatePdfFromHtml(html, options);
|
|
1056
1466
|
}
|
|
1057
1467
|
async generatePdfFromMustacheString(template, data = {}, options) {
|
|
1058
|
-
const html = requireService(this
|
|
1468
|
+
const html = requireService(this.#mustacheService, "Mustache").render(template, data, options?.mustacheOptions ?? this.#options.mustacheOptions);
|
|
1059
1469
|
return this.generatePdfFromHtml(html, options);
|
|
1060
1470
|
}
|
|
1061
1471
|
async generatePdfFromMustacheFile(file, data = {}, options) {
|
|
1062
|
-
const html = requireService(this
|
|
1472
|
+
const html = requireService(this.#mustacheService, "Mustache").renderFile(file, data, options?.mustacheOptions ?? this.#options.mustacheOptions);
|
|
1063
1473
|
return this.generatePdfFromHtml(html, options);
|
|
1064
1474
|
}
|
|
1065
1475
|
};
|
|
1066
|
-
PuppeteerService = __decorate
|
|
1476
|
+
PuppeteerService = __decorate([
|
|
1067
1477
|
(0, _nestjs_common.Injectable)(),
|
|
1068
1478
|
__decorateParam(1, (0, _nestjs_common.Inject)(PDF_PARAMETERS)),
|
|
1069
1479
|
__decorateParam(2, (0, _nestjs_common.Optional)()),
|
|
@@ -1088,9 +1498,9 @@ PuppeteerService = __decorate$3([
|
|
|
1088
1498
|
//#endregion
|
|
1089
1499
|
//#region src/nestjs-pdf.service.ts
|
|
1090
1500
|
let NestjsPdfService = class NestjsPdfService {
|
|
1091
|
-
puppeteerService;
|
|
1501
|
+
#puppeteerService;
|
|
1092
1502
|
constructor(puppeteerService) {
|
|
1093
|
-
this
|
|
1503
|
+
this.#puppeteerService = puppeteerService;
|
|
1094
1504
|
}
|
|
1095
1505
|
/**
|
|
1096
1506
|
* @param html HTML string to convert to PDF
|
|
@@ -1099,7 +1509,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1099
1509
|
* @description This method uses the Puppeteer service to generate a PDF from an HTML string. Generation options can be customized by passing a `PuppeteerParameters` object as the second argument. This allows you to control various aspects of PDF rendering, such as page size, margins, background display, etc. If no options are provided, the default parameters defined in the Puppeteer service will be used.
|
|
1100
1510
|
*/
|
|
1101
1511
|
generatePdfFromHtml(html, options) {
|
|
1102
|
-
return this
|
|
1512
|
+
return this.#puppeteerService.generatePdfFromHtml(html, options);
|
|
1103
1513
|
}
|
|
1104
1514
|
/**
|
|
1105
1515
|
* @param template Handlebars template string
|
|
@@ -1109,7 +1519,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1109
1519
|
* @description This method generates a PDF from a Handlebars template provided as a string. The parameters to inject into the template are passed in the `parameters` object, which is used to render the template before converting it to PDF. PDF generation options can also be customized by passing a `PuppeteerParameters` object as the third argument. This allows you to control various aspects of PDF rendering, such as page size, margins, background display, etc. If no options are provided, the default parameters defined in the Puppeteer service will be used.
|
|
1110
1520
|
*/
|
|
1111
1521
|
generatePdfFromTemplateHbsString(template, parameters = {}, options) {
|
|
1112
|
-
return this
|
|
1522
|
+
return this.#puppeteerService.generatePdfFromTemplateHbsString(template, parameters, options);
|
|
1113
1523
|
}
|
|
1114
1524
|
/**
|
|
1115
1525
|
* @param file Path to the Handlebars template file
|
|
@@ -1119,7 +1529,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1119
1529
|
* @description This method generates a PDF from a Handlebars template located at the specified file path. The file path is passed as a string in the `file` parameter. The parameters to inject into the template are passed in the `parameters` object, which is used to render the template before converting it to PDF. PDF generation options can also be customized by passing a `PuppeteerParameters` object as the third argument. This allows you to control various aspects of PDF rendering, such as page size, margins, background display, etc. If no options are provided, the default parameters defined in the Puppeteer service will be used.
|
|
1120
1530
|
*/
|
|
1121
1531
|
generatePdfFromTemplateHbsFile(file, parameters = {}, options) {
|
|
1122
|
-
return this
|
|
1532
|
+
return this.#puppeteerService.generatePdfFromTemplateHbsFile(file, parameters, options);
|
|
1123
1533
|
}
|
|
1124
1534
|
/**
|
|
1125
1535
|
* @param template MJML template string
|
|
@@ -1128,7 +1538,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1128
1538
|
* @description This method generates a PDF from an MJML template provided as a string. MJML (MJML Markup Language) is a markup language designed to reduce the pain of coding a responsive email. The template is first rendered to HTML using the MJML renderer, then converted to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the second argument.
|
|
1129
1539
|
*/
|
|
1130
1540
|
generatePdfFromMjmlString(template, options) {
|
|
1131
|
-
return this
|
|
1541
|
+
return this.#puppeteerService.generatePdfFromMjmlString(template, options);
|
|
1132
1542
|
}
|
|
1133
1543
|
/**
|
|
1134
1544
|
* @param file Path to the MJML template file
|
|
@@ -1137,7 +1547,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1137
1547
|
* @description This method generates a PDF from an MJML template located at the specified file path. The file path is passed as a string in the `file` parameter. The template is first rendered to HTML using the MJML renderer, then converted to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the second argument.
|
|
1138
1548
|
*/
|
|
1139
1549
|
generatePdfFromMjmlFile(file, options) {
|
|
1140
|
-
return this
|
|
1550
|
+
return this.#puppeteerService.generatePdfFromMjmlFile(file, options);
|
|
1141
1551
|
}
|
|
1142
1552
|
/**
|
|
1143
1553
|
* @param template EJS template string
|
|
@@ -1147,7 +1557,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1147
1557
|
* @description This method generates a PDF from an EJS (Embedded JavaScript) template provided as a string. EJS is a templating language with a simple, straightforward syntax. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
1148
1558
|
*/
|
|
1149
1559
|
generatePdfFromEjsString(template, data = {}, options) {
|
|
1150
|
-
return this
|
|
1560
|
+
return this.#puppeteerService.generatePdfFromEjsString(template, data, options);
|
|
1151
1561
|
}
|
|
1152
1562
|
/**
|
|
1153
1563
|
* @param file Path to the EJS template file
|
|
@@ -1157,7 +1567,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1157
1567
|
* @description This method generates a PDF from an EJS template located at the specified file path. The file path is passed as a string in the `file` parameter. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
1158
1568
|
*/
|
|
1159
1569
|
generatePdfFromEjsFile(file, data = {}, options) {
|
|
1160
|
-
return this
|
|
1570
|
+
return this.#puppeteerService.generatePdfFromEjsFile(file, data, options);
|
|
1161
1571
|
}
|
|
1162
1572
|
/**
|
|
1163
1573
|
* @param template Pug template string
|
|
@@ -1167,7 +1577,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1167
1577
|
* @description This method generates a PDF from a Pug template provided as a string. Pug is a clean, whitespace-sensitive syntax for writing HTML. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
1168
1578
|
*/
|
|
1169
1579
|
generatePdfFromPugString(template, data = {}, options) {
|
|
1170
|
-
return this
|
|
1580
|
+
return this.#puppeteerService.generatePdfFromPugString(template, data, options);
|
|
1171
1581
|
}
|
|
1172
1582
|
/**
|
|
1173
1583
|
* @param file Path to the Pug template file
|
|
@@ -1177,7 +1587,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1177
1587
|
* @description This method generates a PDF from a Pug template located at the specified file path. The file path is passed as a string in the `file` parameter. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
1178
1588
|
*/
|
|
1179
1589
|
generatePdfFromPugFile(file, data = {}, options) {
|
|
1180
|
-
return this
|
|
1590
|
+
return this.#puppeteerService.generatePdfFromPugFile(file, data, options);
|
|
1181
1591
|
}
|
|
1182
1592
|
/**
|
|
1183
1593
|
* @param template Nunjucks template string
|
|
@@ -1187,7 +1597,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1187
1597
|
* @description This method generates a PDF from a Nunjucks template provided as a string. Nunjucks is a powerful templating language with support for inheritance, macros, and filters. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
1188
1598
|
*/
|
|
1189
1599
|
generatePdfFromNunjucksString(template, data = {}, options) {
|
|
1190
|
-
return this
|
|
1600
|
+
return this.#puppeteerService.generatePdfFromNunjucksString(template, data, options);
|
|
1191
1601
|
}
|
|
1192
1602
|
/**
|
|
1193
1603
|
* @param file Path to the Nunjucks template file
|
|
@@ -1197,7 +1607,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1197
1607
|
* @description This method generates a PDF from a Nunjucks template located at the specified file path. The file path is passed as a string in the `file` parameter. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
1198
1608
|
*/
|
|
1199
1609
|
generatePdfFromNunjucksFile(file, data = {}, options) {
|
|
1200
|
-
return this
|
|
1610
|
+
return this.#puppeteerService.generatePdfFromNunjucksFile(file, data, options);
|
|
1201
1611
|
}
|
|
1202
1612
|
/**
|
|
1203
1613
|
* @param template Eta template string
|
|
@@ -1207,7 +1617,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1207
1617
|
* @description This method generates a PDF from an Eta template provided as a string. Eta is a fast and lightweight embedded templating language with a syntax similar to EJS but with better performance. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
1208
1618
|
*/
|
|
1209
1619
|
generatePdfFromEtaString(template, data = {}, options) {
|
|
1210
|
-
return this
|
|
1620
|
+
return this.#puppeteerService.generatePdfFromEtaString(template, data, options);
|
|
1211
1621
|
}
|
|
1212
1622
|
/**
|
|
1213
1623
|
* @param file Path to the Eta template file
|
|
@@ -1217,7 +1627,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1217
1627
|
* @description This method generates a PDF from an Eta template located at the specified file path. The file path is passed as a string in the `file` parameter. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
1218
1628
|
*/
|
|
1219
1629
|
generatePdfFromEtaFile(file, data = {}, options) {
|
|
1220
|
-
return this
|
|
1630
|
+
return this.#puppeteerService.generatePdfFromEtaFile(file, data, options);
|
|
1221
1631
|
}
|
|
1222
1632
|
/**
|
|
1223
1633
|
* @param template Mustache template string
|
|
@@ -1227,7 +1637,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1227
1637
|
* @description This method generates a PDF from a Mustache template provided as a string. Mustache is a logic-less template language that emphasizes readable and simple templates. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
1228
1638
|
*/
|
|
1229
1639
|
generatePdfFromMustacheString(template, data = {}, options) {
|
|
1230
|
-
return this
|
|
1640
|
+
return this.#puppeteerService.generatePdfFromMustacheString(template, data, options);
|
|
1231
1641
|
}
|
|
1232
1642
|
/**
|
|
1233
1643
|
* @param file Path to the Mustache template file
|
|
@@ -1237,7 +1647,7 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1237
1647
|
* @description This method generates a PDF from a Mustache template located at the specified file path. The file path is passed as a string in the `file` parameter. The data to inject into the template is passed in the `data` object, which is used to render the template before converting it to PDF. PDF generation options can be customized by passing a `PuppeteerParameters` object as the third argument.
|
|
1238
1648
|
*/
|
|
1239
1649
|
generatePdfFromMustacheFile(file, data = {}, options) {
|
|
1240
|
-
return this
|
|
1650
|
+
return this.#puppeteerService.generatePdfFromMustacheFile(file, data, options);
|
|
1241
1651
|
}
|
|
1242
1652
|
/**
|
|
1243
1653
|
* @param pdf The PDF bytes to modify
|
|
@@ -1264,1307 +1674,57 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1264
1674
|
async addSignatureFieldSignatureDebtorRaw(pdf, fieldName = "SignatureDebtor", anchorText = "__SIG_DEBTOR_ANCHOR__") {
|
|
1265
1675
|
return await addSignatureFieldUsingAnchor(pdf, fieldName, anchorText);
|
|
1266
1676
|
}
|
|
1267
|
-
};
|
|
1268
|
-
NestjsPdfService = __decorate$3([(0, _nestjs_common.Injectable)(), __decorateMetadata("design:paramtypes", [typeof PuppeteerService === "undefined" ? Object : PuppeteerService])], NestjsPdfService);
|
|
1269
|
-
//#endregion
|
|
1270
|
-
//#region node_modules/.pnpm/@nestjs+config@12.0.0_@nestjs+common@12.0.1_reflect-metadata@0.2.2_rxjs@7.8.2_supports-color@8.1.1__rxjs@7.8.2/node_modules/@nestjs/config/dist/config.constants.js
|
|
1271
|
-
var import_main = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1272
|
-
function _resolveEscapeSequences(value) {
|
|
1273
|
-
return value.replace(/\\\$/g, "$");
|
|
1274
|
-
}
|
|
1275
|
-
function expandValue(value, processEnv, runningParsed) {
|
|
1276
|
-
const env = {
|
|
1277
|
-
...runningParsed,
|
|
1278
|
-
...processEnv
|
|
1279
|
-
};
|
|
1280
|
-
const regex = /(?<!\\)\${([^{}]+)}|(?<!\\)\$([A-Za-z_][A-Za-z0-9_]*)/g;
|
|
1281
|
-
let result = value;
|
|
1282
|
-
let match;
|
|
1283
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1284
|
-
while ((match = regex.exec(result)) !== null) {
|
|
1285
|
-
seen.add(result);
|
|
1286
|
-
const [template, bracedExpression, unbracedExpression] = match;
|
|
1287
|
-
const expression = bracedExpression || unbracedExpression;
|
|
1288
|
-
const opMatch = expression.match(/(:\+|\+|:-|-)/);
|
|
1289
|
-
const splitter = opMatch ? opMatch[0] : null;
|
|
1290
|
-
const r = expression.split(splitter);
|
|
1291
|
-
let defaultValue;
|
|
1292
|
-
let value;
|
|
1293
|
-
const key = r.shift();
|
|
1294
|
-
if ([":+", "+"].includes(splitter)) {
|
|
1295
|
-
defaultValue = env[key] ? r.join(splitter) : "";
|
|
1296
|
-
value = null;
|
|
1297
|
-
} else {
|
|
1298
|
-
defaultValue = r.join(splitter);
|
|
1299
|
-
value = env[key];
|
|
1300
|
-
}
|
|
1301
|
-
if (value) {
|
|
1302
|
-
if (seen.has(value)) result = result.replace(template, defaultValue);
|
|
1303
|
-
else result = result.replace(template, value);
|
|
1304
|
-
} else result = result.replace(template, defaultValue);
|
|
1305
|
-
if (result === runningParsed[key]) break;
|
|
1306
|
-
regex.lastIndex = 0;
|
|
1307
|
-
}
|
|
1308
|
-
return result;
|
|
1309
|
-
}
|
|
1310
|
-
function expand(options) {
|
|
1311
|
-
const runningParsed = {};
|
|
1312
|
-
let processEnv = process.env;
|
|
1313
|
-
if (options && options.processEnv != null) processEnv = options.processEnv;
|
|
1314
|
-
for (const key in options.parsed) {
|
|
1315
|
-
let value = options.parsed[key];
|
|
1316
|
-
if (processEnv[key] && processEnv[key] !== value) value = processEnv[key];
|
|
1317
|
-
else value = expandValue(value, processEnv, runningParsed);
|
|
1318
|
-
options.parsed[key] = _resolveEscapeSequences(value);
|
|
1319
|
-
runningParsed[key] = _resolveEscapeSequences(value);
|
|
1320
|
-
}
|
|
1321
|
-
for (const processKey in options.parsed) processEnv[processKey] = options.parsed[processKey];
|
|
1322
|
-
return options;
|
|
1323
|
-
}
|
|
1324
|
-
module.exports.expand = expand;
|
|
1325
|
-
})))();
|
|
1326
|
-
/**
|
|
1327
|
-
* Injection tokens
|
|
1328
|
-
*/
|
|
1329
|
-
const CONFIGURATION_SERVICE_TOKEN = Symbol("CONFIG_SERVICE");
|
|
1330
|
-
const CONFIGURATION_TOKEN = "CONFIGURATION_TOKEN";
|
|
1331
|
-
const CONFIGURATION_LOADER = "CONFIGURATION_LOADER";
|
|
1332
|
-
const VALIDATED_ENV_LOADER = "VALIDATED_ENV_LOADER";
|
|
1333
|
-
const PARTIAL_CONFIGURATION_KEY = "PARTIAL_CONFIGURATION_KEY";
|
|
1334
|
-
const VALIDATED_ENV_PROPNAME = "_PROCESS_ENV_VALIDATED";
|
|
1335
|
-
//#endregion
|
|
1336
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs
|
|
1337
|
-
/**
|
|
1338
|
-
* Checks if a property key is unsafe to access or copy directly.
|
|
1339
|
-
*
|
|
1340
|
-
* This function is used in functions like `get`, `unset`, and `merge` to prevent
|
|
1341
|
-
* prototype pollution attacks by identifying `__proto__`, which modifies the object's
|
|
1342
|
-
* prototype chain. `constructor` and `prototype` stay accessible here because lodash
|
|
1343
|
-
* keeps reads of them unrestricted; write paths use `isUnsafeToWriteProperty` instead,
|
|
1344
|
-
* which also blocks those keys.
|
|
1345
|
-
*
|
|
1346
|
-
* @param key - The property key to check
|
|
1347
|
-
* @returns `true` if the property is unsafe to access directly, `false` otherwise
|
|
1348
|
-
* @internal
|
|
1349
|
-
*/
|
|
1350
|
-
function isUnsafeProperty(key) {
|
|
1351
|
-
return key === "__proto__";
|
|
1352
|
-
}
|
|
1353
|
-
//#endregion
|
|
1354
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/_internal/isDeepKey.mjs
|
|
1355
|
-
/** Matches any deep property path. Examples: `a.b`, `a[0]`, `a["b"]` */
|
|
1356
|
-
const regexIsDeepProp$1 = /\.|(\[(?:[^[\]]*|(["'])(?:(?!\2)[^\\]|\\.)*?\2)\])/;
|
|
1357
|
-
/**
|
|
1358
|
-
* Checks if a given key is a deep key.
|
|
1359
|
-
*
|
|
1360
|
-
* A deep key is a string that contains a dot (.) or square brackets with a property accessor.
|
|
1361
|
-
*
|
|
1362
|
-
* @param {PropertyKey} key - The key to check.
|
|
1363
|
-
* @returns {boolean} - Returns true if the key is a deep key, otherwise false.
|
|
1364
|
-
*
|
|
1365
|
-
* Examples:
|
|
1366
|
-
*
|
|
1367
|
-
* isDeepKey('a.b') // true
|
|
1368
|
-
* isDeepKey('a[b]') // true
|
|
1369
|
-
* isDeepKey('a') // false
|
|
1370
|
-
* isDeepKey(123) // false
|
|
1371
|
-
* isDeepKey('a.b.c') // true
|
|
1372
|
-
* isDeepKey('a[b][c]') // true
|
|
1373
|
-
* isDeepKey('a.') // false
|
|
1374
|
-
* isDeepKey('.a') // false
|
|
1375
|
-
* isDeepKey('a[b') // false
|
|
1376
|
-
* isDeepKey('a]b]') // false
|
|
1377
|
-
* isDeepKey('a][b') // false
|
|
1378
|
-
* isDeepKey('') // false
|
|
1379
|
-
* isDeepKey('a[0]') // true
|
|
1380
|
-
*
|
|
1381
|
-
*/
|
|
1382
|
-
function isDeepKey(key) {
|
|
1383
|
-
switch (typeof key) {
|
|
1384
|
-
case "number":
|
|
1385
|
-
case "symbol": return false;
|
|
1386
|
-
case "string":
|
|
1387
|
-
if (key === "" || key.startsWith(".") || key.endsWith(".")) return false;
|
|
1388
|
-
return regexIsDeepProp$1.test(key);
|
|
1389
|
-
default: return false;
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
//#endregion
|
|
1393
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/_internal/toKey.mjs
|
|
1394
|
-
/**
|
|
1395
|
-
* Converts `value` to a string key if it's not a string or symbol.
|
|
1396
|
-
*
|
|
1397
|
-
* @private
|
|
1398
|
-
* @param {unknown} value The value to inspect.
|
|
1399
|
-
* @returns {string|symbol} Returns the key.
|
|
1400
|
-
*/
|
|
1401
|
-
function toKey(value) {
|
|
1402
|
-
if (typeof value === "string" || typeof value === "symbol") return value;
|
|
1403
|
-
if (Object.is(value?.valueOf?.(), -0)) return "-0";
|
|
1404
|
-
return String(value);
|
|
1405
|
-
}
|
|
1406
|
-
//#endregion
|
|
1407
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/util/toString.mjs
|
|
1408
|
-
/**
|
|
1409
|
-
* Converts `value` to a string.
|
|
1410
|
-
*
|
|
1411
|
-
* An empty string is returned for `null` and `undefined` values.
|
|
1412
|
-
* The sign of `-0` is preserved.
|
|
1413
|
-
*
|
|
1414
|
-
* @param value - The value to convert.
|
|
1415
|
-
* @returns Returns the converted string.
|
|
1416
|
-
*
|
|
1417
|
-
* @example
|
|
1418
|
-
* toString(null) // returns ''
|
|
1419
|
-
* toString(undefined) // returns ''
|
|
1420
|
-
* toString(-0) // returns '-0'
|
|
1421
|
-
* toString([1, 2, -0]) // returns '1,2,-0'
|
|
1422
|
-
* toString([Symbol('a'), Symbol('b')]) // returns 'Symbol(a),Symbol(b)'
|
|
1423
|
-
*/
|
|
1424
|
-
function toString(value) {
|
|
1425
|
-
if (value == null) return "";
|
|
1426
|
-
return baseToString(value);
|
|
1427
|
-
}
|
|
1428
|
-
function baseToString(value) {
|
|
1429
|
-
if (typeof value === "string") return value;
|
|
1430
|
-
if (Array.isArray(value)) return value.map(baseToString).join(",");
|
|
1431
|
-
const result = String(value);
|
|
1432
|
-
if (result === "0" && Object.is(Number(value), -0)) return "-0";
|
|
1433
|
-
return result;
|
|
1434
|
-
}
|
|
1435
|
-
//#endregion
|
|
1436
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/util/toPath.mjs
|
|
1437
|
-
/**
|
|
1438
|
-
* Converts a deep key string into an array of path segments.
|
|
1439
|
-
*
|
|
1440
|
-
* This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.
|
|
1441
|
-
*
|
|
1442
|
-
* @param deepKey - The deep key string to convert.
|
|
1443
|
-
* @returns An array of strings, each representing a segment of the path.
|
|
1444
|
-
*
|
|
1445
|
-
* Examples:
|
|
1446
|
-
*
|
|
1447
|
-
* toPath('a.b.c') // Returns ['a', 'b', 'c']
|
|
1448
|
-
* toPath('a[b][c]') // Returns ['a', 'b', 'c']
|
|
1449
|
-
* toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']
|
|
1450
|
-
* toPath('a["b.c"].d') // Returns ['a', 'b.c', 'd']
|
|
1451
|
-
* toPath('') // Returns []
|
|
1452
|
-
* toPath('.a[b].c.d[e]["f.g"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']
|
|
1453
|
-
*/
|
|
1454
|
-
function toPath(deepKey) {
|
|
1455
|
-
if (Array.isArray(deepKey)) return deepKey.map(toKey);
|
|
1456
|
-
if (typeof deepKey === "symbol") return [deepKey];
|
|
1457
|
-
deepKey = toString(deepKey);
|
|
1458
|
-
const result = [];
|
|
1459
|
-
const length = deepKey.length;
|
|
1460
|
-
if (length === 0) return result;
|
|
1461
|
-
let index = 0;
|
|
1462
|
-
let key = "";
|
|
1463
|
-
let quoteChar = "";
|
|
1464
|
-
let bracket = false;
|
|
1465
|
-
let bracketHadQuote = false;
|
|
1466
|
-
const bracketNumberRegex = /^-?\d+(?:\.\d+)?$/;
|
|
1467
|
-
if (deepKey.charCodeAt(0) === 46) result.push("");
|
|
1468
|
-
while (index < length) {
|
|
1469
|
-
const char = deepKey[index];
|
|
1470
|
-
if (quoteChar) if (char === "\\" && index + 1 < length) {
|
|
1471
|
-
index++;
|
|
1472
|
-
key += deepKey[index];
|
|
1473
|
-
} else if (char === quoteChar) quoteChar = "";
|
|
1474
|
-
else key += char;
|
|
1475
|
-
else if (bracket) if (char === "\"" || char === "'") {
|
|
1476
|
-
quoteChar = char;
|
|
1477
|
-
bracketHadQuote = true;
|
|
1478
|
-
} else if (char === "]") {
|
|
1479
|
-
bracket = false;
|
|
1480
|
-
if (!bracketHadQuote && key.includes(".") && !bracketNumberRegex.test(key)) {
|
|
1481
|
-
const segments = key.split(".");
|
|
1482
|
-
for (let i = 0; i < segments.length; i++) if (segments[i] !== "") result.push(segments[i]);
|
|
1483
|
-
} else result.push(key);
|
|
1484
|
-
key = "";
|
|
1485
|
-
} else key += char;
|
|
1486
|
-
else if (char === "[") {
|
|
1487
|
-
bracket = true;
|
|
1488
|
-
bracketHadQuote = false;
|
|
1489
|
-
if (key) {
|
|
1490
|
-
result.push(key);
|
|
1491
|
-
key = "";
|
|
1492
|
-
}
|
|
1493
|
-
} else if (char === ".") {
|
|
1494
|
-
if (key) {
|
|
1495
|
-
result.push(key);
|
|
1496
|
-
key = "";
|
|
1497
|
-
}
|
|
1498
|
-
const next = deepKey[index + 1];
|
|
1499
|
-
if (next === void 0 || next === ".") result.push("");
|
|
1500
|
-
} else key += char;
|
|
1501
|
-
index++;
|
|
1502
|
-
}
|
|
1503
|
-
if (key) result.push(key);
|
|
1504
|
-
return result;
|
|
1505
|
-
}
|
|
1506
|
-
//#endregion
|
|
1507
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/object/get.mjs
|
|
1508
|
-
/**
|
|
1509
|
-
* Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead.
|
|
1510
|
-
*
|
|
1511
|
-
* @param object - The object to query.
|
|
1512
|
-
* @param path - The path of the property to get.
|
|
1513
|
-
* @param [defaultValue] - The value returned if the resolved value is undefined.
|
|
1514
|
-
* @returns Returns the resolved value.
|
|
1515
|
-
*
|
|
1516
|
-
* @example
|
|
1517
|
-
* const object = { a: { b: { c: 1 } } };
|
|
1518
|
-
* get(object, 'a.b.c');
|
|
1519
|
-
* // => 1
|
|
1520
|
-
*
|
|
1521
|
-
* get(object, ['a', 'b', 'c']);
|
|
1522
|
-
* // => 1
|
|
1523
|
-
*
|
|
1524
|
-
* get(object, 'a.b.d', 'default');
|
|
1525
|
-
* // => 'default'
|
|
1526
|
-
*/
|
|
1527
|
-
function get(object, path, defaultValue) {
|
|
1528
|
-
if (object == null) return defaultValue;
|
|
1529
|
-
switch (typeof path) {
|
|
1530
|
-
case "string": {
|
|
1531
|
-
if (isUnsafeProperty(path)) return defaultValue;
|
|
1532
|
-
const result = object[path];
|
|
1533
|
-
if (result === void 0) if (isDeepKey(path) && !Object.hasOwn(object, path)) return get(object, toPath(path), defaultValue);
|
|
1534
|
-
else return defaultValue;
|
|
1535
|
-
return result;
|
|
1536
|
-
}
|
|
1537
|
-
case "number":
|
|
1538
|
-
case "symbol": {
|
|
1539
|
-
if (typeof path === "number") path = toKey(path);
|
|
1540
|
-
const result = object[path];
|
|
1541
|
-
if (result === void 0) return defaultValue;
|
|
1542
|
-
return result;
|
|
1543
|
-
}
|
|
1544
|
-
default: {
|
|
1545
|
-
if (Array.isArray(path)) return getWithPath(object, path, defaultValue);
|
|
1546
|
-
if (Object.is(path?.valueOf(), -0)) path = "-0";
|
|
1547
|
-
else path = String(path);
|
|
1548
|
-
if (isUnsafeProperty(path)) return defaultValue;
|
|
1549
|
-
const result = object[path];
|
|
1550
|
-
if (result === void 0) return defaultValue;
|
|
1551
|
-
return result;
|
|
1552
|
-
}
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
function getWithPath(object, path, defaultValue) {
|
|
1556
|
-
if (path.length === 0) return defaultValue;
|
|
1557
|
-
let current = object;
|
|
1558
|
-
for (let index = 0; index < path.length; index++) {
|
|
1559
|
-
if (current == null) return defaultValue;
|
|
1560
|
-
if (isUnsafeProperty(path[index])) return defaultValue;
|
|
1561
|
-
current = current[path[index]];
|
|
1562
|
-
}
|
|
1563
|
-
if (current === void 0) return defaultValue;
|
|
1564
|
-
return current;
|
|
1565
|
-
}
|
|
1566
|
-
//#endregion
|
|
1567
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/_internal/isIndex.mjs
|
|
1568
|
-
const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
|
|
1569
|
-
function isIndex(value, length = Number.MAX_SAFE_INTEGER) {
|
|
1570
|
-
switch (typeof value) {
|
|
1571
|
-
case "number": return Number.isInteger(value) && value >= 0 && value < length;
|
|
1572
|
-
case "symbol": return false;
|
|
1573
|
-
case "string": return IS_UNSIGNED_INTEGER.test(value);
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
//#endregion
|
|
1577
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/_internal/getTag.mjs
|
|
1578
|
-
/**
|
|
1579
|
-
* Gets the `toStringTag` of `value`.
|
|
1580
|
-
*
|
|
1581
|
-
* @private
|
|
1582
|
-
* @param {T} value The value to query.
|
|
1583
|
-
* @returns {string} Returns the `Object.prototype.toString.call` result.
|
|
1584
|
-
*/
|
|
1585
|
-
function getTag(value) {
|
|
1586
|
-
if (value == null) return value === void 0 ? "[object Undefined]" : "[object Null]";
|
|
1587
|
-
return Object.prototype.toString.call(value);
|
|
1588
|
-
}
|
|
1589
|
-
//#endregion
|
|
1590
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/predicate/isArguments.mjs
|
|
1591
|
-
/**
|
|
1592
|
-
* Checks if the given value is an arguments object.
|
|
1593
|
-
*
|
|
1594
|
-
* This function tests whether the provided value is an arguments object or not.
|
|
1595
|
-
* It returns `true` if the value is an arguments object, and `false` otherwise.
|
|
1596
|
-
*
|
|
1597
|
-
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an arguments object.
|
|
1598
|
-
*
|
|
1599
|
-
* @param value - The value to test if it is an arguments object.
|
|
1600
|
-
* @returns `true` if the value is an arguments, `false` otherwise.
|
|
1601
|
-
*
|
|
1602
|
-
* @example
|
|
1603
|
-
* const args = (function() { return arguments; })();
|
|
1604
|
-
* const strictArgs = (function() { 'use strict'; return arguments; })();
|
|
1605
|
-
* const value = [1, 2, 3];
|
|
1606
|
-
*
|
|
1607
|
-
* console.log(isArguments(args)); // true
|
|
1608
|
-
* console.log(isArguments(strictArgs)); // true
|
|
1609
|
-
* console.log(isArguments(value)); // false
|
|
1610
|
-
*/
|
|
1611
|
-
function isArguments(value) {
|
|
1612
|
-
return value !== null && typeof value === "object" && getTag(value) === "[object Arguments]";
|
|
1613
|
-
}
|
|
1614
|
-
//#endregion
|
|
1615
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/object/has.mjs
|
|
1616
|
-
/**
|
|
1617
|
-
* Checks if a given path exists within an object.
|
|
1618
|
-
*
|
|
1619
|
-
* You can provide the path as a single property key, an array of property keys,
|
|
1620
|
-
* or a string representing a deep path.
|
|
1621
|
-
*
|
|
1622
|
-
* If the path is an index and the object is an array or an arguments object, the function will verify
|
|
1623
|
-
* if the index is valid and within the bounds of the array or arguments object, even if the array or
|
|
1624
|
-
* arguments object is sparse (i.e., not all indexes are defined).
|
|
1625
|
-
*
|
|
1626
|
-
* @param object - The object to query.
|
|
1627
|
-
* @param path - The path to check. This can be a single property key,
|
|
1628
|
-
* an array of property keys, or a string representing a deep path.
|
|
1629
|
-
* @returns Returns `true` if the path exists in the object, `false` otherwise.
|
|
1630
|
-
*
|
|
1631
|
-
* @example
|
|
1632
|
-
*
|
|
1633
|
-
* const obj = { a: { b: { c: 3 } } };
|
|
1634
|
-
*
|
|
1635
|
-
* has(obj, 'a'); // true
|
|
1636
|
-
* has(obj, ['a', 'b']); // true
|
|
1637
|
-
* has(obj, ['a', 'b', 'c']); // true
|
|
1638
|
-
* has(obj, 'a.b.c'); // true
|
|
1639
|
-
* has(obj, 'a.b.d'); // false
|
|
1640
|
-
* has(obj, ['a', 'b', 'c', 'd']); // false
|
|
1641
|
-
* has([], 0); // false
|
|
1642
|
-
* has([1, 2, 3], 2); // true
|
|
1643
|
-
* has([1, 2, 3], 5); // false
|
|
1644
|
-
*/
|
|
1645
|
-
function has(object, path) {
|
|
1646
|
-
let resolvedPath;
|
|
1647
|
-
if (Array.isArray(path)) resolvedPath = path;
|
|
1648
|
-
else if (typeof path === "string" && isDeepKey(path) && !(path in Object(object))) resolvedPath = toPath(path);
|
|
1649
|
-
else resolvedPath = [path];
|
|
1650
|
-
if (resolvedPath.length === 0) return false;
|
|
1651
|
-
let current = object;
|
|
1652
|
-
for (let i = 0; i < resolvedPath.length; i++) {
|
|
1653
|
-
const key = resolvedPath[i];
|
|
1654
|
-
if (current == null || !Object.hasOwn(current, key)) {
|
|
1655
|
-
if (!((Array.isArray(current) || isArguments(current)) && isIndex(key) && key < current.length)) return false;
|
|
1656
|
-
}
|
|
1657
|
-
current = current[key];
|
|
1658
|
-
}
|
|
1659
|
-
return true;
|
|
1660
|
-
}
|
|
1661
|
-
//#endregion
|
|
1662
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/predicate/isObject.mjs
|
|
1663
|
-
/**
|
|
1664
|
-
* Checks if the given value is an object. An object is a value that is
|
|
1665
|
-
* not a primitive type (string, number, boolean, symbol, null, or undefined).
|
|
1666
|
-
*
|
|
1667
|
-
* This function tests whether the provided value is an object or not.
|
|
1668
|
-
* It returns `true` if the value is an object, and `false` otherwise.
|
|
1669
|
-
*
|
|
1670
|
-
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to an object value.
|
|
1671
|
-
*
|
|
1672
|
-
* @param value - The value to check if it is an object.
|
|
1673
|
-
* @returns `true` if the value is an object, `false` otherwise.
|
|
1674
|
-
*
|
|
1675
|
-
* @example
|
|
1676
|
-
* const value1 = {};
|
|
1677
|
-
* const value2 = [1, 2, 3];
|
|
1678
|
-
* const value3 = () => {};
|
|
1679
|
-
* const value4 = null;
|
|
1680
|
-
*
|
|
1681
|
-
* console.log(isObject(value1)); // true
|
|
1682
|
-
* console.log(isObject(value2)); // true
|
|
1683
|
-
* console.log(isObject(value3)); // true
|
|
1684
|
-
* console.log(isObject(value4)); // false
|
|
1685
|
-
*/
|
|
1686
|
-
function isObject$1(value) {
|
|
1687
|
-
return value !== null && (typeof value === "object" || typeof value === "function");
|
|
1688
|
-
}
|
|
1689
|
-
//#endregion
|
|
1690
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/predicate/isSymbol.mjs
|
|
1691
|
-
/**
|
|
1692
|
-
* Check whether a value is a symbol.
|
|
1693
|
-
*
|
|
1694
|
-
* This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `symbol`.
|
|
1695
|
-
*
|
|
1696
|
-
* @param value The value to check.
|
|
1697
|
-
* @returns Returns `true` if `value` is a symbol, else `false`.
|
|
1698
|
-
* @example
|
|
1699
|
-
* isSymbol(Symbol.iterator);
|
|
1700
|
-
* // => true
|
|
1701
|
-
*
|
|
1702
|
-
* isSymbol('abc');
|
|
1703
|
-
* // => false
|
|
1704
|
-
*/
|
|
1705
|
-
function isSymbol(value) {
|
|
1706
|
-
return typeof value === "symbol" || value instanceof Symbol;
|
|
1707
|
-
}
|
|
1708
|
-
//#endregion
|
|
1709
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/_internal/isKey.mjs
|
|
1710
|
-
/** Matches any deep property path. (e.g. `a.b[0].c`)*/
|
|
1711
|
-
const regexIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
|
|
1712
|
-
/** Matches any word character (alphanumeric & underscore).*/
|
|
1713
|
-
const regexIsPlainProp = /^\w*$/;
|
|
1714
|
-
/**
|
|
1715
|
-
* Checks if `value` is a property name and not a property path. (It's ok that the `value` is not in the keys of the `object`)
|
|
1716
|
-
* @param {unknown} value The value to check.
|
|
1717
|
-
* @param {unknown} object The object to query.
|
|
1718
|
-
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
|
1719
|
-
*
|
|
1720
|
-
* @example
|
|
1721
|
-
* isKey('a', { a: 1 });
|
|
1722
|
-
* // => true
|
|
1723
|
-
*
|
|
1724
|
-
* isKey('a.b', { a: { b: 2 } });
|
|
1725
|
-
* // => false
|
|
1726
|
-
*/
|
|
1727
|
-
function isKey(value, object) {
|
|
1728
|
-
if (Array.isArray(value)) return false;
|
|
1729
|
-
if (typeof value === "number" || typeof value === "boolean" || value == null || isSymbol(value)) return true;
|
|
1730
|
-
return typeof value === "string" && (regexIsPlainProp.test(value) || !regexIsDeepProp.test(value)) || object != null && Object.hasOwn(object, value);
|
|
1731
|
-
}
|
|
1732
|
-
//#endregion
|
|
1733
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/util/eq.mjs
|
|
1734
|
-
/**
|
|
1735
|
-
* Performs a `SameValueZero` comparison between two values to determine if they are equivalent.
|
|
1736
|
-
*
|
|
1737
|
-
* @param value The value to compare.
|
|
1738
|
-
* @param other The other value to compare.
|
|
1739
|
-
* @returns Returns `true` if the values are equivalent, else `false`.
|
|
1740
|
-
*
|
|
1741
|
-
* @example
|
|
1742
|
-
* eq(1, 1); // true
|
|
1743
|
-
* eq(0, -0); // true
|
|
1744
|
-
* eq(NaN, NaN); // true
|
|
1745
|
-
* eq('a', Object('a')); // false
|
|
1746
|
-
*/
|
|
1747
|
-
function eq(value, other) {
|
|
1748
|
-
return value === other || Number.isNaN(value) && Number.isNaN(other);
|
|
1749
|
-
}
|
|
1750
|
-
//#endregion
|
|
1751
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/_internal/assignValue.mjs
|
|
1752
|
-
const assignValue = (object, key, value) => {
|
|
1753
|
-
const objValue = object[key];
|
|
1754
|
-
if (!(Object.hasOwn(object, key) && eq(objValue, value)) || value === void 0 && !(key in object)) object[key] = value;
|
|
1755
|
-
};
|
|
1756
|
-
//#endregion
|
|
1757
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/_internal/isUnsafeToWriteProperty.mjs
|
|
1758
|
-
/**
|
|
1759
|
-
* Checks if a property key is unsafe to write to.
|
|
1760
|
-
*
|
|
1761
|
-
* Writing through `__proto__`, `constructor`, or `prototype` can reach
|
|
1762
|
-
* `Object.prototype` and pollute every object, so write paths like `set`,
|
|
1763
|
-
* `update`, and `zipObjectDeep` abort when a path segment matches one of
|
|
1764
|
-
* these keys, matching lodash's behavior.
|
|
1765
|
-
*
|
|
1766
|
-
* Read paths like `get` and `unset` use `isUnsafeProperty` instead, which
|
|
1767
|
-
* only blocks `__proto__`; lodash keeps reads of `constructor` and
|
|
1768
|
-
* `prototype` unrestricted.
|
|
1769
|
-
*
|
|
1770
|
-
* @param key - The property key to check
|
|
1771
|
-
* @returns `true` if the property is unsafe to write to, `false` otherwise
|
|
1772
|
-
* @internal
|
|
1773
|
-
*/
|
|
1774
|
-
function isUnsafeToWriteProperty(key) {
|
|
1775
|
-
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
1776
|
-
}
|
|
1777
|
-
//#endregion
|
|
1778
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/object/updateWith.mjs
|
|
1779
|
-
/**
|
|
1780
|
-
* Updates the value at the specified path of the given object using an updater function and a customizer.
|
|
1781
|
-
* If any part of the path does not exist, it will be created.
|
|
1782
|
-
*
|
|
1783
|
-
* @template T - The type of the object.
|
|
1784
|
-
* @template R - The type of the return value.
|
|
1785
|
-
* @param obj - The object to modify.
|
|
1786
|
-
* @param path - The path of the property to update.
|
|
1787
|
-
* @param updater - The function to produce the updated value.
|
|
1788
|
-
* @param customizer - The function to customize the update process.
|
|
1789
|
-
* @returns The modified object.
|
|
1790
|
-
*
|
|
1791
|
-
* @example
|
|
1792
|
-
* const object = { 'a': [{ 'b': { 'c': 3 } }] };
|
|
1793
|
-
* updateWith(object, 'a[0].b.c', (n) => n * n);
|
|
1794
|
-
* // => { 'a': [{ 'b': { 'c': 9 } }] }
|
|
1795
|
-
*/
|
|
1796
|
-
function updateWith(obj, path, updater, customizer) {
|
|
1797
|
-
if (obj == null && !isObject$1(obj)) return obj;
|
|
1798
|
-
let resolvedPath;
|
|
1799
|
-
if (isKey(path, obj)) resolvedPath = [path];
|
|
1800
|
-
else if (Array.isArray(path)) resolvedPath = path;
|
|
1801
|
-
else resolvedPath = toPath(path);
|
|
1802
|
-
const updateValue = updater(get(obj, resolvedPath));
|
|
1803
|
-
let current = obj;
|
|
1804
|
-
for (let i = 0; i < resolvedPath.length && current != null; i++) {
|
|
1805
|
-
const key = toKey(resolvedPath[i]);
|
|
1806
|
-
if (isUnsafeToWriteProperty(key)) return obj;
|
|
1807
|
-
let newValue;
|
|
1808
|
-
if (i === resolvedPath.length - 1) newValue = updateValue;
|
|
1809
|
-
else {
|
|
1810
|
-
const objValue = current[key];
|
|
1811
|
-
const customizerResult = customizer?.(objValue, key, obj);
|
|
1812
|
-
newValue = customizerResult !== void 0 ? customizerResult : isObject$1(objValue) ? objValue : isIndex(resolvedPath[i + 1]) ? [] : {};
|
|
1813
|
-
}
|
|
1814
|
-
assignValue(current, key, newValue);
|
|
1815
|
-
current = current[key];
|
|
1816
|
-
}
|
|
1817
|
-
return obj;
|
|
1818
|
-
}
|
|
1819
|
-
//#endregion
|
|
1820
|
-
//#region node_modules/.pnpm/es-toolkit@1.51.0/node_modules/es-toolkit/dist/compat/object/set.mjs
|
|
1821
|
-
/**
|
|
1822
|
-
* Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.
|
|
1823
|
-
*
|
|
1824
|
-
* @template T - The type of the object.
|
|
1825
|
-
* @param obj - The object to modify.
|
|
1826
|
-
* @param path - The path of the property to set.
|
|
1827
|
-
* @param value - The value to set.
|
|
1828
|
-
* @returns The modified object.
|
|
1829
|
-
*
|
|
1830
|
-
* @example
|
|
1831
|
-
* // Set a value in a nested object
|
|
1832
|
-
* const obj = { a: { b: { c: 3 } } };
|
|
1833
|
-
* set(obj, 'a.b.c', 4);
|
|
1834
|
-
* console.log(obj.a.b.c); // 4
|
|
1835
|
-
*
|
|
1836
|
-
* @example
|
|
1837
|
-
* // Set a value in an array
|
|
1838
|
-
* const arr = [1, 2, 3];
|
|
1839
|
-
* set(arr, 1, 4);
|
|
1840
|
-
* console.log(arr[1]); // 4
|
|
1841
|
-
*
|
|
1842
|
-
* @example
|
|
1843
|
-
* // Create non-existent path and set value
|
|
1844
|
-
* const obj = {};
|
|
1845
|
-
* set(obj, 'a.b.c', 4);
|
|
1846
|
-
* console.log(obj); // { a: { b: { c: 4 } } }
|
|
1847
|
-
*/
|
|
1848
|
-
function set(obj, path, value) {
|
|
1849
|
-
return updateWith(obj, path, () => value, () => void 0);
|
|
1850
|
-
}
|
|
1851
|
-
//#endregion
|
|
1852
|
-
//#region node_modules/.pnpm/@nestjs+config@12.0.0_@nestjs+common@12.0.1_reflect-metadata@0.2.2_rxjs@7.8.2_supports-color@8.1.1__rxjs@7.8.2/node_modules/@nestjs/config/dist/utils/get-config-token.util.js
|
|
1853
|
-
/**
|
|
1854
|
-
* @publicApi
|
|
1855
|
-
*/
|
|
1856
|
-
function getConfigToken(token) {
|
|
1857
|
-
return `CONFIGURATION(${token.toString()})`;
|
|
1858
|
-
}
|
|
1859
|
-
//#endregion
|
|
1860
|
-
//#region node_modules/.pnpm/@nestjs+config@12.0.0_@nestjs+common@12.0.1_reflect-metadata@0.2.2_rxjs@7.8.2_supports-color@8.1.1__rxjs@7.8.2/node_modules/@nestjs/config/dist/utils/get-default-parser.util.js
|
|
1861
|
-
var import_main$1 = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1862
|
-
const fs$2 = require("fs");
|
|
1863
|
-
const path$1 = require("path");
|
|
1864
|
-
const os = require("os");
|
|
1865
|
-
const crypto$1 = require("crypto");
|
|
1866
|
-
const TIPS = [
|
|
1867
|
-
"◈ encrypted .env [www.dotenvx.com]",
|
|
1868
|
-
"◈ secrets for agents [www.dotenvx.com]",
|
|
1869
|
-
"⌁ auth for agents [www.vestauth.com]",
|
|
1870
|
-
"⌘ custom filepath { path: '/custom/path/.env' }",
|
|
1871
|
-
"⌘ enable debugging { debug: true }",
|
|
1872
|
-
"⌘ override existing { override: true }",
|
|
1873
|
-
"⌘ suppress logs { quiet: true }",
|
|
1874
|
-
"⌘ multiple files { path: ['.env.local', '.env'] }"
|
|
1875
|
-
];
|
|
1876
|
-
function _getRandomTip() {
|
|
1877
|
-
return TIPS[Math.floor(Math.random() * TIPS.length)];
|
|
1878
|
-
}
|
|
1879
|
-
function parseBoolean(value) {
|
|
1880
|
-
if (typeof value === "string") return ![
|
|
1881
|
-
"false",
|
|
1882
|
-
"0",
|
|
1883
|
-
"no",
|
|
1884
|
-
"off",
|
|
1885
|
-
""
|
|
1886
|
-
].includes(value.toLowerCase());
|
|
1887
|
-
return Boolean(value);
|
|
1888
|
-
}
|
|
1889
|
-
function supportsAnsi() {
|
|
1890
|
-
return process.stdout.isTTY;
|
|
1891
|
-
}
|
|
1892
|
-
function dim(text) {
|
|
1893
|
-
return supportsAnsi() ? `\x1b[2m${text}\x1b[0m` : text;
|
|
1894
|
-
}
|
|
1895
|
-
const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;
|
|
1896
|
-
function parse(src) {
|
|
1897
|
-
const obj = {};
|
|
1898
|
-
let lines = src.toString();
|
|
1899
|
-
lines = lines.replace(/\r\n?/gm, "\n");
|
|
1900
|
-
let match;
|
|
1901
|
-
while ((match = LINE.exec(lines)) != null) {
|
|
1902
|
-
const key = match[1];
|
|
1903
|
-
let value = match[2] || "";
|
|
1904
|
-
value = value.trim();
|
|
1905
|
-
const maybeQuote = value[0];
|
|
1906
|
-
value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2");
|
|
1907
|
-
if (maybeQuote === "\"") {
|
|
1908
|
-
value = value.replace(/\\n/g, "\n");
|
|
1909
|
-
value = value.replace(/\\r/g, "\r");
|
|
1910
|
-
}
|
|
1911
|
-
obj[key] = value;
|
|
1912
|
-
}
|
|
1913
|
-
return obj;
|
|
1914
|
-
}
|
|
1915
|
-
function _parseVault(options) {
|
|
1916
|
-
options = options || {};
|
|
1917
|
-
const vaultPath = _vaultPath(options);
|
|
1918
|
-
options.path = vaultPath;
|
|
1919
|
-
const result = DotenvModule.configDotenv(options);
|
|
1920
|
-
if (!result.parsed) {
|
|
1921
|
-
const err = /* @__PURE__ */ new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
|
1922
|
-
err.code = "MISSING_DATA";
|
|
1923
|
-
throw err;
|
|
1924
|
-
}
|
|
1925
|
-
const keys = _dotenvKey(options).split(",");
|
|
1926
|
-
const length = keys.length;
|
|
1927
|
-
let decrypted;
|
|
1928
|
-
for (let i = 0; i < length; i++) try {
|
|
1929
|
-
const attrs = _instructions(result, keys[i].trim());
|
|
1930
|
-
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
|
1931
|
-
break;
|
|
1932
|
-
} catch (error) {
|
|
1933
|
-
if (i + 1 >= length) throw error;
|
|
1934
|
-
}
|
|
1935
|
-
return DotenvModule.parse(decrypted);
|
|
1936
|
-
}
|
|
1937
|
-
function _warn(message) {
|
|
1938
|
-
console.error(`⚠ ${message}`);
|
|
1939
|
-
}
|
|
1940
|
-
function _debug(message) {
|
|
1941
|
-
console.log(`┆ ${message}`);
|
|
1942
|
-
}
|
|
1943
|
-
function _log(message) {
|
|
1944
|
-
console.log(`◇ ${message}`);
|
|
1945
|
-
}
|
|
1946
|
-
function _dotenvKey(options) {
|
|
1947
|
-
if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) return options.DOTENV_KEY;
|
|
1948
|
-
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) return process.env.DOTENV_KEY;
|
|
1949
|
-
return "";
|
|
1950
|
-
}
|
|
1951
|
-
function _instructions(result, dotenvKey) {
|
|
1952
|
-
let uri;
|
|
1953
|
-
try {
|
|
1954
|
-
uri = new URL(dotenvKey);
|
|
1955
|
-
} catch (error) {
|
|
1956
|
-
if (error.code === "ERR_INVALID_URL") {
|
|
1957
|
-
const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
|
|
1958
|
-
err.code = "INVALID_DOTENV_KEY";
|
|
1959
|
-
throw err;
|
|
1960
|
-
}
|
|
1961
|
-
throw error;
|
|
1962
|
-
}
|
|
1963
|
-
const key = uri.password;
|
|
1964
|
-
if (!key) {
|
|
1965
|
-
const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: Missing key part");
|
|
1966
|
-
err.code = "INVALID_DOTENV_KEY";
|
|
1967
|
-
throw err;
|
|
1968
|
-
}
|
|
1969
|
-
const environment = uri.searchParams.get("environment");
|
|
1970
|
-
if (!environment) {
|
|
1971
|
-
const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: Missing environment part");
|
|
1972
|
-
err.code = "INVALID_DOTENV_KEY";
|
|
1973
|
-
throw err;
|
|
1974
|
-
}
|
|
1975
|
-
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
|
1976
|
-
const ciphertext = result.parsed[environmentKey];
|
|
1977
|
-
if (!ciphertext) {
|
|
1978
|
-
const err = /* @__PURE__ */ new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
|
1979
|
-
err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
|
|
1980
|
-
throw err;
|
|
1981
|
-
}
|
|
1982
|
-
return {
|
|
1983
|
-
ciphertext,
|
|
1984
|
-
key
|
|
1985
|
-
};
|
|
1986
|
-
}
|
|
1987
|
-
function _vaultPath(options) {
|
|
1988
|
-
let possibleVaultPath = null;
|
|
1989
|
-
if (options && options.path && options.path.length > 0) {
|
|
1990
|
-
if (Array.isArray(options.path)) {
|
|
1991
|
-
for (const filepath of options.path) if (fs$2.existsSync(filepath)) possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
|
|
1992
|
-
} else possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
|
|
1993
|
-
} else possibleVaultPath = path$1.resolve(process.cwd(), ".env.vault");
|
|
1994
|
-
if (fs$2.existsSync(possibleVaultPath)) return possibleVaultPath;
|
|
1995
|
-
return null;
|
|
1996
|
-
}
|
|
1997
|
-
function _resolveHome(envPath) {
|
|
1998
|
-
return envPath[0] === "~" ? path$1.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
1999
|
-
}
|
|
2000
|
-
function _configVault(options) {
|
|
2001
|
-
const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
|
|
2002
|
-
const quiet = parseBoolean(process.env.DOTENV_CONFIG_QUIET || options && options.quiet);
|
|
2003
|
-
if (debug || !quiet) _log("loading env from encrypted .env.vault");
|
|
2004
|
-
const parsed = DotenvModule._parseVault(options);
|
|
2005
|
-
let processEnv = process.env;
|
|
2006
|
-
if (options && options.processEnv != null) processEnv = options.processEnv;
|
|
2007
|
-
DotenvModule.populate(processEnv, parsed, options);
|
|
2008
|
-
return { parsed };
|
|
2009
|
-
}
|
|
2010
|
-
function configDotenv(options) {
|
|
2011
|
-
const dotenvPath = path$1.resolve(process.cwd(), ".env");
|
|
2012
|
-
let encoding = "utf8";
|
|
2013
|
-
let processEnv = process.env;
|
|
2014
|
-
if (options && options.processEnv != null) processEnv = options.processEnv;
|
|
2015
|
-
let debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || options && options.debug);
|
|
2016
|
-
let quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || options && options.quiet);
|
|
2017
|
-
if (options && options.encoding) encoding = options.encoding;
|
|
2018
|
-
else if (debug) _debug("no encoding is specified (UTF-8 is used by default)");
|
|
2019
|
-
let optionPaths = [dotenvPath];
|
|
2020
|
-
if (options && options.path) {
|
|
2021
|
-
if (!Array.isArray(options.path)) optionPaths = [_resolveHome(options.path)];
|
|
2022
|
-
else {
|
|
2023
|
-
optionPaths = [];
|
|
2024
|
-
for (const filepath of options.path) optionPaths.push(_resolveHome(filepath));
|
|
2025
|
-
}
|
|
2026
|
-
}
|
|
2027
|
-
let lastError;
|
|
2028
|
-
const parsedAll = {};
|
|
2029
|
-
for (const path$2 of optionPaths) try {
|
|
2030
|
-
const parsed = DotenvModule.parse(fs$2.readFileSync(path$2, { encoding }));
|
|
2031
|
-
DotenvModule.populate(parsedAll, parsed, options);
|
|
2032
|
-
} catch (e) {
|
|
2033
|
-
if (debug) _debug(`failed to load ${path$2} ${e.message}`);
|
|
2034
|
-
lastError = e;
|
|
2035
|
-
}
|
|
2036
|
-
const populated = DotenvModule.populate(processEnv, parsedAll, options);
|
|
2037
|
-
debug = parseBoolean(processEnv.DOTENV_CONFIG_DEBUG || debug);
|
|
2038
|
-
quiet = parseBoolean(processEnv.DOTENV_CONFIG_QUIET || quiet);
|
|
2039
|
-
if (debug || !quiet) {
|
|
2040
|
-
const keysCount = Object.keys(populated).length;
|
|
2041
|
-
const shortPaths = [];
|
|
2042
|
-
for (const filePath of optionPaths) try {
|
|
2043
|
-
const relative = path$1.relative(process.cwd(), filePath);
|
|
2044
|
-
shortPaths.push(relative);
|
|
2045
|
-
} catch (e) {
|
|
2046
|
-
if (debug) _debug(`failed to load ${filePath} ${e.message}`);
|
|
2047
|
-
lastError = e;
|
|
2048
|
-
}
|
|
2049
|
-
_log(`injected env (${keysCount}) from ${shortPaths.join(",")} ${dim(`// tip: ${_getRandomTip()}`)}`);
|
|
2050
|
-
}
|
|
2051
|
-
if (lastError) return {
|
|
2052
|
-
parsed: parsedAll,
|
|
2053
|
-
error: lastError
|
|
2054
|
-
};
|
|
2055
|
-
else return { parsed: parsedAll };
|
|
2056
|
-
}
|
|
2057
|
-
function config(options) {
|
|
2058
|
-
if (_dotenvKey(options).length === 0) return DotenvModule.configDotenv(options);
|
|
2059
|
-
const vaultPath = _vaultPath(options);
|
|
2060
|
-
if (!vaultPath) {
|
|
2061
|
-
_warn(`you set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}`);
|
|
2062
|
-
return DotenvModule.configDotenv(options);
|
|
2063
|
-
}
|
|
2064
|
-
return DotenvModule._configVault(options);
|
|
2065
|
-
}
|
|
2066
|
-
function decrypt(encrypted, keyStr) {
|
|
2067
|
-
const key = Buffer.from(keyStr.slice(-64), "hex");
|
|
2068
|
-
let ciphertext = Buffer.from(encrypted, "base64");
|
|
2069
|
-
const nonce = ciphertext.subarray(0, 12);
|
|
2070
|
-
const authTag = ciphertext.subarray(-16);
|
|
2071
|
-
ciphertext = ciphertext.subarray(12, -16);
|
|
2072
|
-
try {
|
|
2073
|
-
const aesgcm = crypto$1.createDecipheriv("aes-256-gcm", key, nonce);
|
|
2074
|
-
aesgcm.setAuthTag(authTag);
|
|
2075
|
-
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
2076
|
-
} catch (error) {
|
|
2077
|
-
const isRange = error instanceof RangeError;
|
|
2078
|
-
const invalidKeyLength = error.message === "Invalid key length";
|
|
2079
|
-
const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
|
|
2080
|
-
if (isRange || invalidKeyLength) {
|
|
2081
|
-
const err = /* @__PURE__ */ new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
|
|
2082
|
-
err.code = "INVALID_DOTENV_KEY";
|
|
2083
|
-
throw err;
|
|
2084
|
-
} else if (decryptionFailed) {
|
|
2085
|
-
const err = /* @__PURE__ */ new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
|
|
2086
|
-
err.code = "DECRYPTION_FAILED";
|
|
2087
|
-
throw err;
|
|
2088
|
-
} else throw error;
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
function populate(processEnv, parsed, options = {}) {
|
|
2092
|
-
const debug = Boolean(options && options.debug);
|
|
2093
|
-
const override = Boolean(options && options.override);
|
|
2094
|
-
const populated = {};
|
|
2095
|
-
if (typeof parsed !== "object") {
|
|
2096
|
-
const err = /* @__PURE__ */ new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
|
2097
|
-
err.code = "OBJECT_REQUIRED";
|
|
2098
|
-
throw err;
|
|
2099
|
-
}
|
|
2100
|
-
for (const key of Object.keys(parsed)) if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
2101
|
-
if (override === true) {
|
|
2102
|
-
processEnv[key] = parsed[key];
|
|
2103
|
-
populated[key] = parsed[key];
|
|
2104
|
-
}
|
|
2105
|
-
if (debug) {
|
|
2106
|
-
if (override === true) _debug(`"${key}" is already defined and WAS overwritten`);
|
|
2107
|
-
else _debug(`"${key}" is already defined and was NOT overwritten`);
|
|
2108
|
-
}
|
|
2109
|
-
} else {
|
|
2110
|
-
processEnv[key] = parsed[key];
|
|
2111
|
-
populated[key] = parsed[key];
|
|
2112
|
-
}
|
|
2113
|
-
return populated;
|
|
2114
|
-
}
|
|
2115
|
-
const DotenvModule = {
|
|
2116
|
-
configDotenv,
|
|
2117
|
-
_configVault,
|
|
2118
|
-
_parseVault,
|
|
2119
|
-
config,
|
|
2120
|
-
decrypt,
|
|
2121
|
-
parse,
|
|
2122
|
-
populate
|
|
2123
|
-
};
|
|
2124
|
-
module.exports.configDotenv = DotenvModule.configDotenv;
|
|
2125
|
-
module.exports._configVault = DotenvModule._configVault;
|
|
2126
|
-
module.exports._parseVault = DotenvModule._parseVault;
|
|
2127
|
-
module.exports.config = DotenvModule.config;
|
|
2128
|
-
module.exports.decrypt = DotenvModule.decrypt;
|
|
2129
|
-
module.exports.parse = DotenvModule.parse;
|
|
2130
|
-
module.exports.populate = DotenvModule.populate;
|
|
2131
|
-
module.exports = DotenvModule;
|
|
2132
|
-
})))(), 1);
|
|
2133
|
-
const getDefaultParser = () => import_main$1.parse;
|
|
2134
|
-
//#endregion
|
|
2135
|
-
//#region node_modules/.pnpm/@nestjs+config@12.0.0_@nestjs+common@12.0.1_reflect-metadata@0.2.2_rxjs@7.8.2_supports-color@8.1.1__rxjs@7.8.2/node_modules/@nestjs/config/dist/config.service.js
|
|
2136
|
-
var __decorate$2 = function(decorators, target, key, desc) {
|
|
2137
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2138
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2139
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2140
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2141
|
-
};
|
|
2142
|
-
var __metadata = function(k, v) {
|
|
2143
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
2144
|
-
};
|
|
2145
|
-
var __param = function(paramIndex, decorator) {
|
|
2146
|
-
return function(target, key) {
|
|
2147
|
-
decorator(target, key, paramIndex);
|
|
2148
|
-
};
|
|
2149
|
-
};
|
|
2150
|
-
/**
|
|
2151
|
-
* @publicApi
|
|
2152
|
-
*/
|
|
2153
|
-
let ConfigService = class ConfigService {
|
|
2154
|
-
set isCacheEnabled(value) {
|
|
2155
|
-
this._isCacheEnabled = value;
|
|
2156
|
-
}
|
|
2157
|
-
get isCacheEnabled() {
|
|
2158
|
-
return this._isCacheEnabled;
|
|
2159
|
-
}
|
|
2160
|
-
set skipProcessEnv(value) {
|
|
2161
|
-
this._skipProcessEnv = value;
|
|
2162
|
-
}
|
|
2163
|
-
get skipProcessEnv() {
|
|
2164
|
-
return this._skipProcessEnv;
|
|
2165
|
-
}
|
|
2166
|
-
constructor(internalConfig = {}) {
|
|
2167
|
-
this.internalConfig = internalConfig;
|
|
2168
|
-
this.cache = {};
|
|
2169
|
-
this._changes$ = new rxjs.Subject();
|
|
2170
|
-
this._skipProcessEnv = false;
|
|
2171
|
-
this._isCacheEnabled = false;
|
|
2172
|
-
this.envFilePaths = [];
|
|
2173
|
-
this.parser = getDefaultParser();
|
|
2174
|
-
}
|
|
2175
|
-
/**
|
|
2176
|
-
* Returns a stream of configuration changes.
|
|
2177
|
-
* Each event contains the attribute path, the old value and the new value.
|
|
2178
|
-
*/
|
|
2179
|
-
get changes$() {
|
|
2180
|
-
return this._changes$.asObservable();
|
|
2181
|
-
}
|
|
2182
1677
|
/**
|
|
2183
|
-
*
|
|
2184
|
-
*
|
|
2185
|
-
*
|
|
2186
|
-
* @
|
|
2187
|
-
*
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
}
|
|
2199
|
-
return defaultValue;
|
|
2200
|
-
}
|
|
2201
|
-
/**
|
|
2202
|
-
* Get a configuration value (either custom configuration or process environment variable)
|
|
2203
|
-
* based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
|
|
2204
|
-
* It returns a default value if the key does not exist.
|
|
2205
|
-
* If the default value is undefined an exception will be thrown.
|
|
2206
|
-
* @param propertyPath
|
|
2207
|
-
* @param defaultValueOrOptions
|
|
2208
|
-
*/
|
|
2209
|
-
getOrThrow(propertyPath, defaultValueOrOptions, options) {
|
|
2210
|
-
const value = this.get(propertyPath, defaultValueOrOptions, options);
|
|
2211
|
-
if ((0, _nestjs_common_utils_shared_utils_js.isUndefined)(value)) throw new TypeError(`Configuration key "${propertyPath.toString()}" does not exist`);
|
|
2212
|
-
return value;
|
|
2213
|
-
}
|
|
2214
|
-
/**
|
|
2215
|
-
* Sets a configuration value based on property path.
|
|
2216
|
-
* @param propertyPath
|
|
2217
|
-
* @param value
|
|
2218
|
-
*/
|
|
2219
|
-
set(propertyPath, value) {
|
|
2220
|
-
const oldValue = this.get(propertyPath);
|
|
2221
|
-
set(this.internalConfig, propertyPath, value);
|
|
2222
|
-
if (typeof propertyPath === "string") {
|
|
2223
|
-
process.env[propertyPath] = String(value);
|
|
2224
|
-
this.updateInterpolatedEnv(propertyPath, String(value));
|
|
2225
|
-
}
|
|
2226
|
-
if (this.isCacheEnabled) this.setInCacheIfDefined(propertyPath, value);
|
|
2227
|
-
this._changes$.next({
|
|
2228
|
-
path: propertyPath,
|
|
2229
|
-
oldValue,
|
|
2230
|
-
newValue: value
|
|
2231
|
-
});
|
|
2232
|
-
}
|
|
2233
|
-
/**
|
|
2234
|
-
* Sets env file paths from `config.module.ts` to parse.
|
|
2235
|
-
* @param paths
|
|
2236
|
-
*/
|
|
2237
|
-
setEnvFilePaths(paths) {
|
|
2238
|
-
this.envFilePaths = paths;
|
|
2239
|
-
}
|
|
2240
|
-
/**
|
|
2241
|
-
* Sets parser from `config.module.ts`.
|
|
2242
|
-
* @param parser
|
|
2243
|
-
*/
|
|
2244
|
-
setParser(parser) {
|
|
2245
|
-
this.parser = parser;
|
|
2246
|
-
}
|
|
2247
|
-
getFromCache(propertyPath, defaultValue) {
|
|
2248
|
-
const cachedValue = get(this.cache, propertyPath);
|
|
2249
|
-
return (0, _nestjs_common_utils_shared_utils_js.isUndefined)(cachedValue) ? defaultValue : cachedValue;
|
|
2250
|
-
}
|
|
2251
|
-
getFromValidatedEnv(propertyPath) {
|
|
2252
|
-
return get(this.internalConfig[VALIDATED_ENV_PROPNAME], propertyPath);
|
|
2253
|
-
}
|
|
2254
|
-
getFromProcessEnv(propertyPath, defaultValue) {
|
|
2255
|
-
if (this.isCacheEnabled && has(this.cache, propertyPath)) {
|
|
2256
|
-
const cachedValue = this.getFromCache(propertyPath, defaultValue);
|
|
2257
|
-
return !(0, _nestjs_common_utils_shared_utils_js.isUndefined)(cachedValue) ? cachedValue : defaultValue;
|
|
2258
|
-
}
|
|
2259
|
-
const processValue = get(process.env, propertyPath);
|
|
2260
|
-
this.setInCacheIfDefined(propertyPath, processValue);
|
|
2261
|
-
return processValue;
|
|
2262
|
-
}
|
|
2263
|
-
getFromInternalConfig(propertyPath) {
|
|
2264
|
-
return get(this.internalConfig, propertyPath);
|
|
2265
|
-
}
|
|
2266
|
-
setInCacheIfDefined(propertyPath, value) {
|
|
2267
|
-
if (typeof value === "undefined") return;
|
|
2268
|
-
set(this.cache, propertyPath, value);
|
|
2269
|
-
}
|
|
2270
|
-
isGetOptionsObject(options) {
|
|
2271
|
-
return options && options?.infer && Object.keys(options).length === 1;
|
|
2272
|
-
}
|
|
2273
|
-
updateInterpolatedEnv(propertyPath, value) {
|
|
2274
|
-
let config = {};
|
|
2275
|
-
for (const envFilePath of this.envFilePaths) if (fs.default.existsSync(envFilePath)) config = Object.assign(this.parser(fs.default.readFileSync(envFilePath)), config);
|
|
2276
|
-
const regex = new RegExp(`\\$\\{?${propertyPath}\\}?`, "g");
|
|
2277
|
-
for (const [k, v] of Object.entries(config)) if (regex.test(v)) process.env[k] = v.replace(regex, value);
|
|
2278
|
-
}
|
|
2279
|
-
};
|
|
2280
|
-
ConfigService = __decorate$2([
|
|
2281
|
-
(0, _nestjs_common.Injectable)(),
|
|
2282
|
-
__param(0, (0, _nestjs_common.Optional)()),
|
|
2283
|
-
__param(0, (0, _nestjs_common.Inject)(CONFIGURATION_TOKEN)),
|
|
2284
|
-
__metadata("design:paramtypes", [Object])
|
|
2285
|
-
], ConfigService);
|
|
2286
|
-
//#endregion
|
|
2287
|
-
//#region node_modules/.pnpm/@nestjs+config@12.0.0_@nestjs+common@12.0.1_reflect-metadata@0.2.2_rxjs@7.8.2_supports-color@8.1.1__rxjs@7.8.2/node_modules/@nestjs/config/dist/config-host.module.js
|
|
2288
|
-
var __decorate$1 = function(decorators, target, key, desc) {
|
|
2289
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2290
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2291
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2292
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2293
|
-
};
|
|
2294
|
-
/**
|
|
2295
|
-
* @publicApi
|
|
2296
|
-
*/
|
|
2297
|
-
let ConfigHostModule = class ConfigHostModule {};
|
|
2298
|
-
ConfigHostModule = __decorate$1([(0, _nestjs_common.Global)(), (0, _nestjs_common.Module)({
|
|
2299
|
-
providers: [{
|
|
2300
|
-
provide: CONFIGURATION_TOKEN,
|
|
2301
|
-
useFactory: () => ({})
|
|
2302
|
-
}, {
|
|
2303
|
-
provide: CONFIGURATION_SERVICE_TOKEN,
|
|
2304
|
-
useClass: ConfigService
|
|
2305
|
-
}],
|
|
2306
|
-
exports: [CONFIGURATION_TOKEN, CONFIGURATION_SERVICE_TOKEN]
|
|
2307
|
-
})], ConfigHostModule);
|
|
2308
|
-
//#endregion
|
|
2309
|
-
//#region node_modules/.pnpm/@nestjs+config@12.0.0_@nestjs+common@12.0.1_reflect-metadata@0.2.2_rxjs@7.8.2_supports-color@8.1.1__rxjs@7.8.2/node_modules/@nestjs/config/dist/utils/create-config-factory.util.js
|
|
2310
|
-
/**
|
|
2311
|
-
* @publicApi
|
|
2312
|
-
*/
|
|
2313
|
-
function createConfigProvider(factory) {
|
|
2314
|
-
return {
|
|
2315
|
-
provide: factory.KEY || getConfigToken((0, crypto.randomUUID)()),
|
|
2316
|
-
useFactory: factory,
|
|
2317
|
-
inject: []
|
|
2318
|
-
};
|
|
2319
|
-
}
|
|
2320
|
-
//#endregion
|
|
2321
|
-
//#region node_modules/.pnpm/@nestjs+config@12.0.0_@nestjs+common@12.0.1_reflect-metadata@0.2.2_rxjs@7.8.2_supports-color@8.1.1__rxjs@7.8.2/node_modules/@nestjs/config/dist/utils/get-registration-token.util.js
|
|
2322
|
-
/**
|
|
2323
|
-
* @publicApi
|
|
2324
|
-
*/
|
|
2325
|
-
function getRegistrationToken(config) {
|
|
2326
|
-
return config[PARTIAL_CONFIGURATION_KEY];
|
|
2327
|
-
}
|
|
2328
|
-
//#endregion
|
|
2329
|
-
//#region node_modules/.pnpm/@nestjs+config@12.0.0_@nestjs+common@12.0.1_reflect-metadata@0.2.2_rxjs@7.8.2_supports-color@8.1.1__rxjs@7.8.2/node_modules/@nestjs/config/dist/utils/merge-configs.util.js
|
|
2330
|
-
/**
|
|
2331
|
-
* @publicApi
|
|
2332
|
-
*/
|
|
2333
|
-
function mergeConfigObject(host, partial, token) {
|
|
2334
|
-
if (token) {
|
|
2335
|
-
set(host, token, partial);
|
|
2336
|
-
return partial;
|
|
2337
|
-
}
|
|
2338
|
-
Object.assign(host, partial);
|
|
2339
|
-
}
|
|
2340
|
-
//#endregion
|
|
2341
|
-
//#region node_modules/.pnpm/@nestjs+config@12.0.0_@nestjs+common@12.0.1_reflect-metadata@0.2.2_rxjs@7.8.2_supports-color@8.1.1__rxjs@7.8.2/node_modules/@nestjs/config/dist/utils/validate-with-schema.util.js
|
|
2342
|
-
/**
|
|
2343
|
-
* Joi defaults to `allowUnknown: false` and `abortEarly: true`, which would
|
|
2344
|
-
* reject the unrelated variables that are always present in `process.env` and
|
|
2345
|
-
* report only the first failure. Previous versions of this package overrode
|
|
2346
|
-
* both, so they remain the defaults for Joi schemas unless the user opts out.
|
|
2347
|
-
*/
|
|
2348
|
-
const JOI_DEFAULT_LIBRARY_OPTIONS = {
|
|
2349
|
-
abortEarly: false,
|
|
2350
|
-
allowUnknown: true
|
|
2351
|
-
};
|
|
2352
|
-
/**
|
|
2353
|
-
* Validates config using a Standard Schema (e.g. Zod, Arktype).
|
|
2354
|
-
* @see https://standardschema.dev/
|
|
2355
|
-
*/
|
|
2356
|
-
async function validateWithStandardSchema(schema, config, options) {
|
|
2357
|
-
const result = await schema["~standard"].validate(config, getLibraryOptions(schema, options));
|
|
2358
|
-
if (result.issues) return {
|
|
2359
|
-
error: new Error(formatIssues(result.issues)),
|
|
2360
|
-
value: config
|
|
2361
|
-
};
|
|
2362
|
-
return { value: result.value };
|
|
2363
|
-
}
|
|
2364
|
-
function getLibraryOptions(schema, options) {
|
|
2365
|
-
if (schema["~standard"].vendor !== "joi") return options;
|
|
2366
|
-
return {
|
|
2367
|
-
...options,
|
|
2368
|
-
libraryOptions: {
|
|
2369
|
-
...JOI_DEFAULT_LIBRARY_OPTIONS,
|
|
2370
|
-
...options?.libraryOptions
|
|
2371
|
-
}
|
|
2372
|
-
};
|
|
2373
|
-
}
|
|
2374
|
-
function formatIssues(issues) {
|
|
2375
|
-
return issues.map((issue) => {
|
|
2376
|
-
const path = formatIssuePath(issue.path);
|
|
2377
|
-
return path ? `${path}: ${issue.message}` : issue.message;
|
|
2378
|
-
}).join("\n");
|
|
2379
|
-
}
|
|
2380
|
-
function formatIssuePath(path) {
|
|
2381
|
-
return (path ?? []).map((segment) => typeof segment === "object" && segment !== null ? String(segment.key) : String(segment)).join(".");
|
|
2382
|
-
}
|
|
2383
|
-
//#endregion
|
|
2384
|
-
//#region node_modules/.pnpm/@nestjs+config@12.0.0_@nestjs+common@12.0.1_reflect-metadata@0.2.2_rxjs@7.8.2_supports-color@8.1.1__rxjs@7.8.2/node_modules/@nestjs/config/dist/config.module.js
|
|
2385
|
-
var __decorate = function(decorators, target, key, desc) {
|
|
2386
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2387
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
2388
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
2389
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
2390
|
-
};
|
|
2391
|
-
var ConfigModule_1;
|
|
2392
|
-
/**
|
|
2393
|
-
* @publicApi
|
|
2394
|
-
*/
|
|
2395
|
-
let ConfigModule = ConfigModule_1 = class ConfigModule {
|
|
2396
|
-
/**
|
|
2397
|
-
* This promise resolves when parser completes loading environment variables.
|
|
2398
|
-
* When "ignoreEnvFile" is set to true, then it will resolve immediately after the
|
|
2399
|
-
* "ConfigModule#forRoot" method is called.
|
|
1678
|
+
* @param pdf The PDF bytes to modify
|
|
1679
|
+
* @param options Watermark options (`text` or `image` is required)
|
|
1680
|
+
* @returns Modified PDF with the watermark stamped on the selected pages
|
|
1681
|
+
* @description Stamps a text or image watermark on an existing PDF. By default the mark is centered, rotated by 45° at 15% opacity on every page. Use `position: 'tile'` to repeat it across the page and `pages` to target specific pages (1-based). To watermark a PDF while generating it, pass the same options as `watermark` in the `PuppeteerParameters`.
|
|
1682
|
+
*
|
|
1683
|
+
* ```typescript
|
|
1684
|
+
* const watermarked = await pdfService.addWatermark(pdf, {
|
|
1685
|
+
* text: 'CONFIDENTIAL',
|
|
1686
|
+
* color: '#ff0000',
|
|
1687
|
+
* opacity: 0.2,
|
|
1688
|
+
* });
|
|
1689
|
+
* ```
|
|
1690
|
+
*
|
|
1691
|
+
* Text uses the PDF standard fonts, which only support WinAnsi characters; use an `image` for anything else.
|
|
1692
|
+
* @throws WatermarkException when the options are invalid or the PDF cannot be processed
|
|
2400
1693
|
*/
|
|
2401
|
-
|
|
2402
|
-
return
|
|
2403
|
-
}
|
|
2404
|
-
/**
|
|
2405
|
-
* Loads environment variables based on the "ignoreEnvFile" flag and "envFilePath" value.
|
|
2406
|
-
* Additionally, registers custom configurations globally.
|
|
2407
|
-
* @param options
|
|
2408
|
-
*/
|
|
2409
|
-
static async forRoot(options = {}) {
|
|
2410
|
-
const envFilePaths = Array.isArray(options.envFilePath) ? options.envFilePath : [options.envFilePath || (0, path.resolve)(process.cwd(), ".env")];
|
|
2411
|
-
const parser = options.parser ?? getDefaultParser();
|
|
2412
|
-
let validatedEnvConfig = void 0;
|
|
2413
|
-
let config = options.ignoreEnvFile ? {} : this.loadEnvFile(envFilePaths, parser, options);
|
|
2414
|
-
if (!options.ignoreEnvVars && options.validatePredefined !== false) config = options.override ? {
|
|
2415
|
-
...process.env,
|
|
2416
|
-
...config
|
|
2417
|
-
} : {
|
|
2418
|
-
...config,
|
|
2419
|
-
...process.env
|
|
2420
|
-
};
|
|
2421
|
-
if (options.validate) {
|
|
2422
|
-
const validatedConfig = options.validate(config);
|
|
2423
|
-
validatedEnvConfig = validatedConfig;
|
|
2424
|
-
this.assignVariablesToProcess(validatedConfig, options.override);
|
|
2425
|
-
} else if (options.validationSchema) {
|
|
2426
|
-
const { error, value: validatedConfig } = await validateWithStandardSchema(options.validationSchema, config, options.validationOptions);
|
|
2427
|
-
if (error) throw new Error(`Config validation error: ${error.message}`);
|
|
2428
|
-
validatedEnvConfig = {
|
|
2429
|
-
...config,
|
|
2430
|
-
...validatedConfig
|
|
2431
|
-
};
|
|
2432
|
-
this.assignVariablesToProcess(validatedEnvConfig, options.override);
|
|
2433
|
-
} else this.assignVariablesToProcess(config, options.override);
|
|
2434
|
-
const isConfigToLoad = options.load && options.load.length;
|
|
2435
|
-
const providers = (await Promise.all(options.load || [])).map((factory) => createConfigProvider(factory)).filter((item) => item);
|
|
2436
|
-
const configProviderTokens = providers.map((item) => item.provide);
|
|
2437
|
-
const configServiceProvider = {
|
|
2438
|
-
provide: ConfigService,
|
|
2439
|
-
useFactory: (configService) => {
|
|
2440
|
-
const untypedConfigService = configService;
|
|
2441
|
-
if (options.cache) untypedConfigService.isCacheEnabled = true;
|
|
2442
|
-
if (options.skipProcessEnv) untypedConfigService.skipProcessEnv = true;
|
|
2443
|
-
configService.setEnvFilePaths(envFilePaths);
|
|
2444
|
-
configService.setParser(parser);
|
|
2445
|
-
return configService;
|
|
2446
|
-
},
|
|
2447
|
-
inject: [CONFIGURATION_SERVICE_TOKEN, ...configProviderTokens]
|
|
2448
|
-
};
|
|
2449
|
-
providers.push(configServiceProvider);
|
|
2450
|
-
if (validatedEnvConfig) {
|
|
2451
|
-
const validatedEnvConfigLoader = {
|
|
2452
|
-
provide: VALIDATED_ENV_LOADER,
|
|
2453
|
-
useFactory: (host) => {
|
|
2454
|
-
host[VALIDATED_ENV_PROPNAME] = validatedEnvConfig;
|
|
2455
|
-
},
|
|
2456
|
-
inject: [CONFIGURATION_TOKEN]
|
|
2457
|
-
};
|
|
2458
|
-
providers.push(validatedEnvConfigLoader);
|
|
2459
|
-
}
|
|
2460
|
-
this.environmentVariablesLoadedSignal();
|
|
2461
|
-
return {
|
|
2462
|
-
module: ConfigModule_1,
|
|
2463
|
-
global: options.isGlobal,
|
|
2464
|
-
providers: isConfigToLoad ? [...providers, {
|
|
2465
|
-
provide: CONFIGURATION_LOADER,
|
|
2466
|
-
useFactory: (host, ...configurations) => {
|
|
2467
|
-
configurations.forEach((item, index) => this.mergePartial(host, item, providers[index]));
|
|
2468
|
-
},
|
|
2469
|
-
inject: [CONFIGURATION_TOKEN, ...configProviderTokens]
|
|
2470
|
-
}] : providers,
|
|
2471
|
-
exports: [ConfigService, ...configProviderTokens]
|
|
2472
|
-
};
|
|
2473
|
-
}
|
|
2474
|
-
/**
|
|
2475
|
-
* Registers configuration object (partial registration).
|
|
2476
|
-
* @param config
|
|
2477
|
-
*/
|
|
2478
|
-
static forFeature(config) {
|
|
2479
|
-
const configProvider = createConfigProvider(config);
|
|
2480
|
-
const serviceProvider = {
|
|
2481
|
-
provide: ConfigService,
|
|
2482
|
-
useFactory: (configService) => configService,
|
|
2483
|
-
inject: [CONFIGURATION_SERVICE_TOKEN, configProvider.provide]
|
|
2484
|
-
};
|
|
2485
|
-
return {
|
|
2486
|
-
module: ConfigModule_1,
|
|
2487
|
-
providers: [
|
|
2488
|
-
configProvider,
|
|
2489
|
-
serviceProvider,
|
|
2490
|
-
{
|
|
2491
|
-
provide: CONFIGURATION_LOADER,
|
|
2492
|
-
useFactory: (host, partialConfig) => {
|
|
2493
|
-
this.mergePartial(host, partialConfig, configProvider);
|
|
2494
|
-
},
|
|
2495
|
-
inject: [CONFIGURATION_TOKEN, configProvider.provide]
|
|
2496
|
-
}
|
|
2497
|
-
],
|
|
2498
|
-
exports: [ConfigService, configProvider.provide]
|
|
2499
|
-
};
|
|
2500
|
-
}
|
|
2501
|
-
static loadEnvFile(envFilePaths, parser, options) {
|
|
2502
|
-
let config = {};
|
|
2503
|
-
for (const envFilePath of envFilePaths) if (fs.existsSync(envFilePath)) {
|
|
2504
|
-
config = Object.assign(parser(fs.readFileSync(envFilePath)), config);
|
|
2505
|
-
if (options.expandVariables) {
|
|
2506
|
-
const expandOptions = typeof options.expandVariables === "object" ? options.expandVariables : {};
|
|
2507
|
-
config = (0, import_main.expand)({
|
|
2508
|
-
...expandOptions,
|
|
2509
|
-
parsed: config
|
|
2510
|
-
}).parsed || config;
|
|
2511
|
-
}
|
|
2512
|
-
}
|
|
2513
|
-
return config;
|
|
2514
|
-
}
|
|
2515
|
-
static assignVariablesToProcess(config, override) {
|
|
2516
|
-
if (!(0, _nestjs_common_utils_shared_utils_js.isObject)(config)) return;
|
|
2517
|
-
(override ? Object.keys(config) : Object.keys(config).filter((key) => !(key in process.env))).forEach((key) => {
|
|
2518
|
-
const value = config[key];
|
|
2519
|
-
if (typeof value === "string") process.env[key] = value;
|
|
2520
|
-
else if (typeof value === "boolean" || typeof value === "number") process.env[key] = `${value}`;
|
|
2521
|
-
});
|
|
2522
|
-
}
|
|
2523
|
-
static mergePartial(host, item, provider) {
|
|
2524
|
-
const factoryRef = provider.useFactory;
|
|
2525
|
-
mergeConfigObject(host, item, getRegistrationToken(factoryRef));
|
|
1694
|
+
async addWatermark(pdf, options) {
|
|
1695
|
+
return await addWatermark(pdf, options);
|
|
2526
1696
|
}
|
|
2527
1697
|
};
|
|
2528
|
-
|
|
2529
|
-
ConfigModule = ConfigModule_1 = __decorate([(0, _nestjs_common.Module)({
|
|
2530
|
-
imports: [ConfigHostModule],
|
|
2531
|
-
providers: [{
|
|
2532
|
-
provide: ConfigService,
|
|
2533
|
-
useExisting: CONFIGURATION_SERVICE_TOKEN
|
|
2534
|
-
}],
|
|
2535
|
-
exports: [ConfigHostModule, ConfigService]
|
|
2536
|
-
})], ConfigModule);
|
|
1698
|
+
NestjsPdfService = __decorate([(0, _nestjs_common.Injectable)(), __decorateMetadata("design:paramtypes", [typeof PuppeteerService === "undefined" ? Object : PuppeteerService])], NestjsPdfService);
|
|
2537
1699
|
//#endregion
|
|
2538
1700
|
//#region src/puppeteer/puppeteer.module.ts
|
|
2539
1701
|
var _PuppeteerModule;
|
|
2540
1702
|
let PuppeteerModule = _PuppeteerModule = class PuppeteerModule {
|
|
2541
|
-
browserService;
|
|
2542
|
-
pdfParams;
|
|
1703
|
+
#browserService;
|
|
1704
|
+
#pdfParams;
|
|
2543
1705
|
constructor(browserService, pdfParams) {
|
|
2544
|
-
this
|
|
2545
|
-
this
|
|
1706
|
+
this.#browserService = browserService;
|
|
1707
|
+
this.#pdfParams = pdfParams;
|
|
2546
1708
|
}
|
|
2547
1709
|
async onModuleInit() {
|
|
2548
|
-
if (!this
|
|
1710
|
+
if (!this.#pdfParams.executablePath) await this.#browserService.install(this.#pdfParams.useLockedBrowser ?? false);
|
|
2549
1711
|
}
|
|
2550
1712
|
static forRoot(pdfParameters) {
|
|
2551
|
-
const providers = [
|
|
2552
|
-
{
|
|
2553
|
-
provide: PDF_PARAMETERS,
|
|
2554
|
-
useValue: pdfParameters
|
|
2555
|
-
},
|
|
2556
|
-
HandlebarsService,
|
|
2557
|
-
MjmlService,
|
|
2558
|
-
PugService,
|
|
2559
|
-
EjsService,
|
|
2560
|
-
NunjucksService,
|
|
2561
|
-
EtaService,
|
|
2562
|
-
MustacheService
|
|
2563
|
-
];
|
|
2564
1713
|
return {
|
|
2565
1714
|
module: _PuppeteerModule,
|
|
2566
|
-
|
|
2567
|
-
|
|
1715
|
+
providers: [
|
|
1716
|
+
{
|
|
1717
|
+
provide: PDF_PARAMETERS,
|
|
1718
|
+
useValue: pdfParameters
|
|
1719
|
+
},
|
|
1720
|
+
HandlebarsService,
|
|
1721
|
+
MjmlService,
|
|
1722
|
+
PugService,
|
|
1723
|
+
EjsService,
|
|
1724
|
+
NunjucksService,
|
|
1725
|
+
EtaService,
|
|
1726
|
+
MustacheService
|
|
1727
|
+
],
|
|
2568
1728
|
exports: [
|
|
2569
1729
|
PuppeteerService,
|
|
2570
1730
|
MjmlService,
|
|
@@ -2584,7 +1744,7 @@ let PuppeteerModule = _PuppeteerModule = class PuppeteerModule {
|
|
|
2584
1744
|
};
|
|
2585
1745
|
return {
|
|
2586
1746
|
module: _PuppeteerModule,
|
|
2587
|
-
imports:
|
|
1747
|
+
imports: options.imports ?? [],
|
|
2588
1748
|
providers: [
|
|
2589
1749
|
pdfParamsProvider,
|
|
2590
1750
|
PuppeteerService,
|
|
@@ -2609,7 +1769,7 @@ let PuppeteerModule = _PuppeteerModule = class PuppeteerModule {
|
|
|
2609
1769
|
};
|
|
2610
1770
|
}
|
|
2611
1771
|
};
|
|
2612
|
-
PuppeteerModule = _PuppeteerModule = __decorate
|
|
1772
|
+
PuppeteerModule = _PuppeteerModule = __decorate([
|
|
2613
1773
|
(0, _nestjs_common.Module)({
|
|
2614
1774
|
providers: [
|
|
2615
1775
|
PuppeteerService,
|
|
@@ -2655,14 +1815,17 @@ let NestjsPdfModule = _NestjsPdfModule = class NestjsPdfModule {
|
|
|
2655
1815
|
};
|
|
2656
1816
|
}
|
|
2657
1817
|
};
|
|
2658
|
-
NestjsPdfModule = _NestjsPdfModule = __decorate
|
|
1818
|
+
NestjsPdfModule = _NestjsPdfModule = __decorate([(0, _nestjs_common.Module)({})], NestjsPdfModule);
|
|
2659
1819
|
//#endregion
|
|
1820
|
+
exports.BrowserInstallationException = BrowserInstallationException;
|
|
1821
|
+
exports.BrowserUnavailableException = BrowserUnavailableException;
|
|
2660
1822
|
Object.defineProperty(exports, "EjsService", {
|
|
2661
1823
|
enumerable: true,
|
|
2662
1824
|
get: function() {
|
|
2663
1825
|
return EjsService;
|
|
2664
1826
|
}
|
|
2665
1827
|
});
|
|
1828
|
+
exports.EngineNotAvailableException = EngineNotAvailableException;
|
|
2666
1829
|
Object.defineProperty(exports, "EtaService", {
|
|
2667
1830
|
enumerable: true,
|
|
2668
1831
|
get: function() {
|
|
@@ -2687,6 +1850,8 @@ Object.defineProperty(exports, "MustacheService", {
|
|
|
2687
1850
|
return MustacheService;
|
|
2688
1851
|
}
|
|
2689
1852
|
});
|
|
1853
|
+
exports.NestjsPdfErrorCode = NestjsPdfErrorCode;
|
|
1854
|
+
exports.NestjsPdfException = NestjsPdfException;
|
|
2690
1855
|
Object.defineProperty(exports, "NestjsPdfModule", {
|
|
2691
1856
|
enumerable: true,
|
|
2692
1857
|
get: function() {
|
|
@@ -2705,6 +1870,7 @@ Object.defineProperty(exports, "NunjucksService", {
|
|
|
2705
1870
|
return NunjucksService;
|
|
2706
1871
|
}
|
|
2707
1872
|
});
|
|
1873
|
+
exports.PdfGenerationException = PdfGenerationException;
|
|
2708
1874
|
Object.defineProperty(exports, "PugService", {
|
|
2709
1875
|
enumerable: true,
|
|
2710
1876
|
get: function() {
|
|
@@ -2723,4 +1889,9 @@ Object.defineProperty(exports, "PuppeteerService", {
|
|
|
2723
1889
|
return PuppeteerService;
|
|
2724
1890
|
}
|
|
2725
1891
|
});
|
|
1892
|
+
exports.SignatureDependencyException = SignatureDependencyException;
|
|
1893
|
+
exports.SignaturePlacementException = SignaturePlacementException;
|
|
1894
|
+
exports.TemplateConfigurationException = TemplateConfigurationException;
|
|
1895
|
+
exports.TemplateRenderException = TemplateRenderException;
|
|
1896
|
+
exports.WatermarkException = WatermarkException;
|
|
2726
1897
|
exports.getRelativePathToValue = getRelativePathToValue;
|