@shad0wz7/nestjs-pdf 3.2.0 → 4.0.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 +34 -26
- package/dist/index.cjs +213 -76
- package/dist/index.d.cts +183 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +183 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +203 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +83 -43
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
2
3
|
import { Inject, Injectable, Logger, Module, Optional } from "@nestjs/common";
|
|
3
4
|
import { PDFArray, PDFDict, PDFDocument, PDFName, PDFNumber, PDFString, StandardFonts, degrees, rgb } from "pdf-lib";
|
|
@@ -8,13 +9,6 @@ import { BlockList, isIP } from "node:net";
|
|
|
8
9
|
import { fileURLToPath } from "node:url";
|
|
9
10
|
import { TargetType, launch } from "puppeteer";
|
|
10
11
|
import { Browser as Browser$1, BrowserPlatform, canDownload, detectBrowserPlatform, getInstalledBrowsers, install, resolveBuildId } from "@puppeteer/browsers";
|
|
11
|
-
import ejs from "ejs";
|
|
12
|
-
import { Eta } from "eta";
|
|
13
|
-
import Handlebars from "handlebars";
|
|
14
|
-
import mjml from "mjml";
|
|
15
|
-
import mustache from "mustache";
|
|
16
|
-
import nunjucks from "nunjucks";
|
|
17
|
-
import pug from "pug";
|
|
18
12
|
//#region src/exceptions/nestjs-pdf.exception.ts
|
|
19
13
|
let NestjsPdfErrorCode = /* @__PURE__ */ function(NestjsPdfErrorCode) {
|
|
20
14
|
NestjsPdfErrorCode["ENGINE_NOT_AVAILABLE"] = "ENGINE_NOT_AVAILABLE";
|
|
@@ -48,8 +42,8 @@ var BrowserUnavailableException = class extends NestjsPdfException {
|
|
|
48
42
|
//#region src/exceptions/engine-not-available.exception.ts
|
|
49
43
|
var EngineNotAvailableException = class extends NestjsPdfException {
|
|
50
44
|
code = "ENGINE_NOT_AVAILABLE";
|
|
51
|
-
constructor(engineName) {
|
|
52
|
-
super(`${engineName} service is not available. If the problem persists, open an issue in the repo
|
|
45
|
+
constructor(engineName, packageName, options) {
|
|
46
|
+
super(packageName ? `${engineName} engine is not available: the '${packageName}' package is not installed. Run \`npm install ${packageName}\` to use it.` : `${engineName} service is not available. If the problem persists, open an issue in the repo.`, options);
|
|
53
47
|
}
|
|
54
48
|
};
|
|
55
49
|
//#endregion
|
|
@@ -449,7 +443,7 @@ var Queue = class {
|
|
|
449
443
|
}
|
|
450
444
|
};
|
|
451
445
|
//#endregion
|
|
452
|
-
//#region node_modules/.pnpm/p-limit@7.3.
|
|
446
|
+
//#region node_modules/.pnpm/p-limit@7.3.3/node_modules/p-limit/index.js
|
|
453
447
|
function pLimit(concurrency) {
|
|
454
448
|
let rejectOnClear = false;
|
|
455
449
|
if (typeof concurrency === "object") ({concurrency, rejectOnClear = false} = concurrency);
|
|
@@ -508,7 +502,17 @@ function pLimit(concurrency) {
|
|
|
508
502
|
}
|
|
509
503
|
},
|
|
510
504
|
map: { async value(iterable, function_) {
|
|
511
|
-
const promises =
|
|
505
|
+
const promises = [];
|
|
506
|
+
try {
|
|
507
|
+
Array.from(iterable, (value, index) => {
|
|
508
|
+
const promise = generator(function_, value, index);
|
|
509
|
+
promises.push(promise);
|
|
510
|
+
return promise;
|
|
511
|
+
});
|
|
512
|
+
} catch (error) {
|
|
513
|
+
for (const promise of promises) promise.catch(() => {});
|
|
514
|
+
throw error;
|
|
515
|
+
}
|
|
512
516
|
return Promise.all(promises);
|
|
513
517
|
} }
|
|
514
518
|
});
|
|
@@ -675,19 +679,19 @@ async function installRequestGuard(context, page, options) {
|
|
|
675
679
|
//#region src/helpers/tokens.ts
|
|
676
680
|
const PDF_PARAMETERS = "PDF_PARAMETERS";
|
|
677
681
|
//#endregion
|
|
678
|
-
//#region \0@oxc-project+runtime@0.
|
|
682
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateMetadata.js
|
|
679
683
|
function __decorateMetadata(k, v) {
|
|
680
684
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
681
685
|
}
|
|
682
686
|
//#endregion
|
|
683
|
-
//#region \0@oxc-project+runtime@0.
|
|
687
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
|
|
684
688
|
function __decorateParam(paramIndex, decorator) {
|
|
685
689
|
return function(target, key) {
|
|
686
690
|
decorator(target, key, paramIndex);
|
|
687
691
|
};
|
|
688
692
|
}
|
|
689
693
|
//#endregion
|
|
690
|
-
//#region \0@oxc-project+runtime@0.
|
|
694
|
+
//#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
|
|
691
695
|
function __decorate(decorators, target, key, desc) {
|
|
692
696
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
693
697
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -962,11 +966,34 @@ BrowserService = __decorate([
|
|
|
962
966
|
__decorateMetadata("design:paramtypes", [Object])
|
|
963
967
|
], BrowserService);
|
|
964
968
|
//#endregion
|
|
969
|
+
//#region src/puppeteer/libs/loadEngine.utils.ts
|
|
970
|
+
const requireEngine = createRequire(import.meta.url);
|
|
971
|
+
/**
|
|
972
|
+
* Load an optional template engine on first use, so the library can be imported
|
|
973
|
+
* without every engine installed. `require` (not `import()`) is used on purpose:
|
|
974
|
+
* most engines expose a synchronous render API.
|
|
975
|
+
*/
|
|
976
|
+
function loadEngine(packageName, engineName) {
|
|
977
|
+
let mod;
|
|
978
|
+
try {
|
|
979
|
+
mod = requireEngine(packageName);
|
|
980
|
+
} catch (error) {
|
|
981
|
+
if (error.code === "MODULE_NOT_FOUND") throw new EngineNotAvailableException(engineName, packageName, { cause: error });
|
|
982
|
+
throw error;
|
|
983
|
+
}
|
|
984
|
+
return mod.__esModule && "default" in mod ? mod.default : mod;
|
|
985
|
+
}
|
|
986
|
+
//#endregion
|
|
965
987
|
//#region src/puppeteer/engines/ejs/ejs.service.ts
|
|
966
988
|
let EjsService = class EjsService {
|
|
989
|
+
#ejs;
|
|
990
|
+
get #engine() {
|
|
991
|
+
return this.#ejs ??= loadEngine("ejs", "EJS");
|
|
992
|
+
}
|
|
967
993
|
async render(template, data = {}, options) {
|
|
994
|
+
const engine = this.#engine;
|
|
968
995
|
try {
|
|
969
|
-
return await
|
|
996
|
+
return await engine.render(template, data, {
|
|
970
997
|
async: true,
|
|
971
998
|
...options
|
|
972
999
|
});
|
|
@@ -975,8 +1002,9 @@ let EjsService = class EjsService {
|
|
|
975
1002
|
}
|
|
976
1003
|
}
|
|
977
1004
|
async renderFile(filePath, data = {}, options) {
|
|
1005
|
+
const engine = this.#engine;
|
|
978
1006
|
try {
|
|
979
|
-
return await
|
|
1007
|
+
return await engine.renderFile(filePath, data, {
|
|
980
1008
|
async: true,
|
|
981
1009
|
...options
|
|
982
1010
|
});
|
|
@@ -989,15 +1017,12 @@ EjsService = __decorate([Injectable()], EjsService);
|
|
|
989
1017
|
//#endregion
|
|
990
1018
|
//#region src/puppeteer/engines/eta/eta.service.ts
|
|
991
1019
|
let EtaService = class EtaService {
|
|
1020
|
+
#etaModule;
|
|
992
1021
|
#eta;
|
|
993
1022
|
#templateCache = /* @__PURE__ */ new Map();
|
|
994
1023
|
#maxCacheSize = 100;
|
|
995
|
-
|
|
996
|
-
this.#
|
|
997
|
-
cache: true,
|
|
998
|
-
autoEscape: true,
|
|
999
|
-
useWith: true
|
|
1000
|
-
});
|
|
1024
|
+
get #engine() {
|
|
1025
|
+
return this.#etaModule ??= loadEngine("eta", "Eta");
|
|
1001
1026
|
}
|
|
1002
1027
|
/**
|
|
1003
1028
|
* Render an Eta template from a string
|
|
@@ -1007,6 +1032,7 @@ let EtaService = class EtaService {
|
|
|
1007
1032
|
* @returns The rendered HTML string
|
|
1008
1033
|
*/
|
|
1009
1034
|
render(template, data = {}, options) {
|
|
1035
|
+
const { Eta } = this.#engine;
|
|
1010
1036
|
try {
|
|
1011
1037
|
return (options && Object.keys(options).length > 0 ? new Eta({
|
|
1012
1038
|
cache: true,
|
|
@@ -1014,7 +1040,11 @@ let EtaService = class EtaService {
|
|
|
1014
1040
|
useWith: true,
|
|
1015
1041
|
...options,
|
|
1016
1042
|
varName: options.varName ?? "it"
|
|
1017
|
-
}) : this.#eta
|
|
1043
|
+
}) : this.#eta ??= new Eta({
|
|
1044
|
+
cache: true,
|
|
1045
|
+
autoEscape: true,
|
|
1046
|
+
useWith: true
|
|
1047
|
+
})).renderString(template, data);
|
|
1018
1048
|
} catch (error) {
|
|
1019
1049
|
throw new TemplateRenderException("Eta", `Eta rendering failed: ${String(error)}`, { cause: error });
|
|
1020
1050
|
}
|
|
@@ -1037,6 +1067,7 @@ let EtaService = class EtaService {
|
|
|
1037
1067
|
}
|
|
1038
1068
|
return this.render(template, data, options);
|
|
1039
1069
|
} catch (error) {
|
|
1070
|
+
if (error instanceof EngineNotAvailableException) throw error;
|
|
1040
1071
|
throw new TemplateRenderException("Eta", `Eta file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
|
|
1041
1072
|
}
|
|
1042
1073
|
}
|
|
@@ -1054,12 +1085,16 @@ let EtaService = class EtaService {
|
|
|
1054
1085
|
return this.#templateCache.size;
|
|
1055
1086
|
}
|
|
1056
1087
|
};
|
|
1057
|
-
EtaService = __decorate([Injectable()
|
|
1088
|
+
EtaService = __decorate([Injectable()], EtaService);
|
|
1058
1089
|
//#endregion
|
|
1059
1090
|
//#region src/puppeteer/engines/handlebars/handlebars.service.ts
|
|
1060
1091
|
let HandlebarsService = class HandlebarsService {
|
|
1092
|
+
#handlebars;
|
|
1061
1093
|
#cachedOptions;
|
|
1062
1094
|
#cachedEnv;
|
|
1095
|
+
get #engine() {
|
|
1096
|
+
return this.#handlebars ??= loadEngine("handlebars", "Handlebars");
|
|
1097
|
+
}
|
|
1063
1098
|
render(template, parameters = {}, options = {}) {
|
|
1064
1099
|
try {
|
|
1065
1100
|
return this.#getEnv(options).compile(template, options.compileOptions)(parameters, options.templateOptions);
|
|
@@ -1088,7 +1123,7 @@ let HandlebarsService = class HandlebarsService {
|
|
|
1088
1123
|
*/
|
|
1089
1124
|
#getEnv(options) {
|
|
1090
1125
|
if (this.#cachedEnv && this.#cachedOptions === options) return this.#cachedEnv;
|
|
1091
|
-
const env =
|
|
1126
|
+
const env = this.#engine.create();
|
|
1092
1127
|
for (const helper of options.helpers ?? []) env.registerHelper(helper.name, helper.fn);
|
|
1093
1128
|
this.#registerPartials(env, options.partialDirectory);
|
|
1094
1129
|
this.#cachedOptions = options;
|
|
@@ -1108,11 +1143,78 @@ let HandlebarsService = class HandlebarsService {
|
|
|
1108
1143
|
};
|
|
1109
1144
|
HandlebarsService = __decorate([Injectable()], HandlebarsService);
|
|
1110
1145
|
//#endregion
|
|
1146
|
+
//#region src/puppeteer/engines/liquid/liquid.service.ts
|
|
1147
|
+
let LiquidService = class LiquidService {
|
|
1148
|
+
#liquidModule;
|
|
1149
|
+
#liquid;
|
|
1150
|
+
#templateCache = /* @__PURE__ */ new Map();
|
|
1151
|
+
#maxCacheSize = 100;
|
|
1152
|
+
get #engine() {
|
|
1153
|
+
return this.#liquidModule ??= loadEngine("liquidjs", "Liquid");
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Render a Liquid template from a string
|
|
1157
|
+
* @param template The template string to render
|
|
1158
|
+
* @param data The data object to use for rendering
|
|
1159
|
+
* @param options Optional Liquid engine options
|
|
1160
|
+
* @returns The rendered HTML string
|
|
1161
|
+
*/
|
|
1162
|
+
render(template, data = {}, options) {
|
|
1163
|
+
const { Liquid } = this.#engine;
|
|
1164
|
+
try {
|
|
1165
|
+
return (options && Object.keys(options).length > 0 ? new Liquid(options) : this.#liquid ??= new Liquid()).parseAndRenderSync(template, data);
|
|
1166
|
+
} catch (error) {
|
|
1167
|
+
throw new TemplateRenderException("Liquid", `Liquid rendering failed: ${String(error)}`, { cause: error });
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Render a Liquid template from a file
|
|
1172
|
+
* @param filePath The path to the template file
|
|
1173
|
+
* @param data The data object to use for rendering
|
|
1174
|
+
* @param options Optional Liquid engine options
|
|
1175
|
+
* @returns The rendered HTML string
|
|
1176
|
+
*/
|
|
1177
|
+
renderFile(filePath, data = {}, options) {
|
|
1178
|
+
try {
|
|
1179
|
+
const resolvedPath = resolve(filePath);
|
|
1180
|
+
const useCache = options?.cache !== false;
|
|
1181
|
+
let template = useCache ? this.#templateCache.get(resolvedPath) : void 0;
|
|
1182
|
+
if (!template) {
|
|
1183
|
+
template = readFileSync(resolvedPath, "utf-8");
|
|
1184
|
+
if (useCache && this.#templateCache.size < this.#maxCacheSize) this.#templateCache.set(resolvedPath, template);
|
|
1185
|
+
}
|
|
1186
|
+
return this.render(template, data, options);
|
|
1187
|
+
} catch (error) {
|
|
1188
|
+
if (error instanceof EngineNotAvailableException) throw error;
|
|
1189
|
+
throw new TemplateRenderException("Liquid", `Liquid file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
/**
|
|
1193
|
+
* Clear the template cache
|
|
1194
|
+
*/
|
|
1195
|
+
clearCache() {
|
|
1196
|
+
this.#templateCache.clear();
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* Get the current cache size
|
|
1200
|
+
* @returns The number of cached templates
|
|
1201
|
+
*/
|
|
1202
|
+
getCacheSize() {
|
|
1203
|
+
return this.#templateCache.size;
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
LiquidService = __decorate([Injectable()], LiquidService);
|
|
1207
|
+
//#endregion
|
|
1111
1208
|
//#region src/puppeteer/engines/mjml/mjml.service.ts
|
|
1112
1209
|
let MjmlService = class MjmlService {
|
|
1210
|
+
#mjml;
|
|
1211
|
+
get #engine() {
|
|
1212
|
+
return this.#mjml ??= loadEngine("mjml", "MJML");
|
|
1213
|
+
}
|
|
1113
1214
|
async render(template, options) {
|
|
1215
|
+
const engine = this.#engine;
|
|
1114
1216
|
try {
|
|
1115
|
-
const { html } = await
|
|
1217
|
+
const { html } = await engine(template, options);
|
|
1116
1218
|
return html;
|
|
1117
1219
|
} catch (error) {
|
|
1118
1220
|
throw new TemplateRenderException("MJML", `MJML rendering failed: ${String(error)}`, { cause: error });
|
|
@@ -1132,8 +1234,12 @@ MjmlService = __decorate([Injectable()], MjmlService);
|
|
|
1132
1234
|
//#endregion
|
|
1133
1235
|
//#region src/puppeteer/engines/mustache/mustache.service.ts
|
|
1134
1236
|
let MustacheService = class MustacheService {
|
|
1237
|
+
#mustache;
|
|
1135
1238
|
#templateCache = /* @__PURE__ */ new Map();
|
|
1136
1239
|
#maxCacheSize = 100;
|
|
1240
|
+
get #engine() {
|
|
1241
|
+
return this.#mustache ??= loadEngine("mustache", "Mustache");
|
|
1242
|
+
}
|
|
1137
1243
|
/**
|
|
1138
1244
|
* Render a Mustache template from a string
|
|
1139
1245
|
* @param template The template string to render
|
|
@@ -1142,9 +1248,10 @@ let MustacheService = class MustacheService {
|
|
|
1142
1248
|
* @returns The rendered HTML string
|
|
1143
1249
|
*/
|
|
1144
1250
|
render(template, data = {}, options) {
|
|
1251
|
+
const engine = this.#engine;
|
|
1145
1252
|
try {
|
|
1146
1253
|
const tags = options?.tags ?? ["{{", "}}"];
|
|
1147
|
-
return
|
|
1254
|
+
return engine.render(template, data, void 0, {
|
|
1148
1255
|
tags,
|
|
1149
1256
|
escape: options?.escape
|
|
1150
1257
|
});
|
|
@@ -1169,6 +1276,7 @@ let MustacheService = class MustacheService {
|
|
|
1169
1276
|
}
|
|
1170
1277
|
return this.render(template, data, options);
|
|
1171
1278
|
} catch (error) {
|
|
1279
|
+
if (error instanceof EngineNotAvailableException) throw error;
|
|
1172
1280
|
throw new TemplateRenderException("Mustache", `Mustache file rendering failed for ${filePath}: ${String(error)}`, { cause: error });
|
|
1173
1281
|
}
|
|
1174
1282
|
}
|
|
@@ -1190,14 +1298,20 @@ MustacheService = __decorate([Injectable()], MustacheService);
|
|
|
1190
1298
|
//#endregion
|
|
1191
1299
|
//#region src/puppeteer/engines/nunjucks/nunjucks.service.ts
|
|
1192
1300
|
let NunjucksService = class NunjucksService {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1301
|
+
#nunjucks;
|
|
1302
|
+
get #engine() {
|
|
1303
|
+
if (!this.#nunjucks) {
|
|
1304
|
+
this.#nunjucks = loadEngine("nunjucks", "Nunjucks");
|
|
1305
|
+
this.#nunjucks.configure({
|
|
1306
|
+
noCache: true,
|
|
1307
|
+
trimBlocks: true,
|
|
1308
|
+
lstripBlocks: true
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
return this.#nunjucks;
|
|
1199
1312
|
}
|
|
1200
1313
|
render(template, data = {}, options) {
|
|
1314
|
+
const nunjucks = this.#engine;
|
|
1201
1315
|
try {
|
|
1202
1316
|
if (options) {
|
|
1203
1317
|
const configOptions = {
|
|
@@ -1215,6 +1329,7 @@ let NunjucksService = class NunjucksService {
|
|
|
1215
1329
|
}
|
|
1216
1330
|
}
|
|
1217
1331
|
renderFile(filePath, data = {}, options) {
|
|
1332
|
+
const nunjucks = this.#engine;
|
|
1218
1333
|
try {
|
|
1219
1334
|
if (options) {
|
|
1220
1335
|
const configOptions = {
|
|
@@ -1232,13 +1347,18 @@ let NunjucksService = class NunjucksService {
|
|
|
1232
1347
|
}
|
|
1233
1348
|
}
|
|
1234
1349
|
};
|
|
1235
|
-
NunjucksService = __decorate([Injectable()
|
|
1350
|
+
NunjucksService = __decorate([Injectable()], NunjucksService);
|
|
1236
1351
|
//#endregion
|
|
1237
1352
|
//#region src/puppeteer/engines/pug/pug.service.ts
|
|
1238
1353
|
let PugService = class PugService {
|
|
1354
|
+
#pug;
|
|
1355
|
+
get #engine() {
|
|
1356
|
+
return this.#pug ??= loadEngine("pug", "Pug");
|
|
1357
|
+
}
|
|
1239
1358
|
render(template, data = {}, options) {
|
|
1359
|
+
const engine = this.#engine;
|
|
1240
1360
|
try {
|
|
1241
|
-
return
|
|
1361
|
+
return engine.compile(template, { ...options })(data);
|
|
1242
1362
|
} catch (error) {
|
|
1243
1363
|
throw new TemplateRenderException("Pug", `Pug rendering failed: ${String(error)}`, { cause: error });
|
|
1244
1364
|
}
|
|
@@ -1248,6 +1368,7 @@ let PugService = class PugService {
|
|
|
1248
1368
|
const template = readFileSync(filePath, "utf-8");
|
|
1249
1369
|
return this.render(template, data, options);
|
|
1250
1370
|
} catch (error) {
|
|
1371
|
+
if (error instanceof EngineNotAvailableException) throw error;
|
|
1251
1372
|
throw new TemplateRenderException("Pug", `Pug file rendering failed: ${String(error)}`, { cause: error });
|
|
1252
1373
|
}
|
|
1253
1374
|
}
|
|
@@ -1271,7 +1392,8 @@ let PuppeteerService = class PuppeteerService {
|
|
|
1271
1392
|
#nunjucksService;
|
|
1272
1393
|
#etaService;
|
|
1273
1394
|
#mustacheService;
|
|
1274
|
-
|
|
1395
|
+
#liquidService;
|
|
1396
|
+
constructor(browserService, options, hbsService, mjmlService, pugService, ejsService, nunjucksService, etaService, mustacheService, liquidService) {
|
|
1275
1397
|
this.#browserService = browserService;
|
|
1276
1398
|
this.#options = options;
|
|
1277
1399
|
this.#hbsService = hbsService;
|
|
@@ -1281,6 +1403,7 @@ let PuppeteerService = class PuppeteerService {
|
|
|
1281
1403
|
this.#nunjucksService = nunjucksService;
|
|
1282
1404
|
this.#etaService = etaService;
|
|
1283
1405
|
this.#mustacheService = mustacheService;
|
|
1406
|
+
this.#liquidService = liquidService;
|
|
1284
1407
|
}
|
|
1285
1408
|
#limit = pLimit(3);
|
|
1286
1409
|
async generatePdfFromHtml(html, options) {
|
|
@@ -1443,6 +1566,14 @@ let PuppeteerService = class PuppeteerService {
|
|
|
1443
1566
|
const html = requireService(this.#mustacheService, "Mustache").renderFile(file, data, options?.mustacheOptions ?? this.#options.mustacheOptions);
|
|
1444
1567
|
return this.generatePdfFromHtml(html, options);
|
|
1445
1568
|
}
|
|
1569
|
+
async generatePdfFromLiquidString(template, data = {}, options) {
|
|
1570
|
+
const html = requireService(this.#liquidService, "Liquid").render(template, data, options?.liquidOptions ?? this.#options.liquidOptions);
|
|
1571
|
+
return this.generatePdfFromHtml(html, options);
|
|
1572
|
+
}
|
|
1573
|
+
async generatePdfFromLiquidFile(file, data = {}, options) {
|
|
1574
|
+
const html = requireService(this.#liquidService, "Liquid").renderFile(file, data, options?.liquidOptions ?? this.#options.liquidOptions);
|
|
1575
|
+
return this.generatePdfFromHtml(html, options);
|
|
1576
|
+
}
|
|
1446
1577
|
};
|
|
1447
1578
|
PuppeteerService = __decorate([
|
|
1448
1579
|
Injectable(),
|
|
@@ -1454,6 +1585,7 @@ PuppeteerService = __decorate([
|
|
|
1454
1585
|
__decorateParam(6, Optional()),
|
|
1455
1586
|
__decorateParam(7, Optional()),
|
|
1456
1587
|
__decorateParam(8, Optional()),
|
|
1588
|
+
__decorateParam(9, Optional()),
|
|
1457
1589
|
__decorateMetadata("design:paramtypes", [
|
|
1458
1590
|
typeof BrowserService === "undefined" ? Object : BrowserService,
|
|
1459
1591
|
Object,
|
|
@@ -1463,7 +1595,8 @@ PuppeteerService = __decorate([
|
|
|
1463
1595
|
typeof EjsService === "undefined" ? Object : EjsService,
|
|
1464
1596
|
typeof NunjucksService === "undefined" ? Object : NunjucksService,
|
|
1465
1597
|
typeof EtaService === "undefined" ? Object : EtaService,
|
|
1466
|
-
typeof MustacheService === "undefined" ? Object : MustacheService
|
|
1598
|
+
typeof MustacheService === "undefined" ? Object : MustacheService,
|
|
1599
|
+
typeof LiquidService === "undefined" ? Object : LiquidService
|
|
1467
1600
|
])
|
|
1468
1601
|
], PuppeteerService);
|
|
1469
1602
|
//#endregion
|
|
@@ -1621,6 +1754,26 @@ let NestjsPdfService = class NestjsPdfService {
|
|
|
1621
1754
|
return this.#puppeteerService.generatePdfFromMustacheFile(file, data, options);
|
|
1622
1755
|
}
|
|
1623
1756
|
/**
|
|
1757
|
+
* @param template Liquid template string
|
|
1758
|
+
* @param data Data to inject into the template
|
|
1759
|
+
* @param options PDF generation options (optional)
|
|
1760
|
+
* @returns PDF generated from the provided Liquid template with data applied
|
|
1761
|
+
* @description This method generates a PDF from a Liquid template provided as a string. Liquid is a safe, Shopify-compatible template language with filters, tags, partials and layouts. 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.
|
|
1762
|
+
*/
|
|
1763
|
+
generatePdfFromLiquidString(template, data = {}, options) {
|
|
1764
|
+
return this.#puppeteerService.generatePdfFromLiquidString(template, data, options);
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* @param file Path to the Liquid template file
|
|
1768
|
+
* @param data Data to inject into the template
|
|
1769
|
+
* @param options PDF generation options (optional)
|
|
1770
|
+
* @returns PDF generated from the Liquid template at the provided file path with data applied
|
|
1771
|
+
* @description This method generates a PDF from a Liquid 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.
|
|
1772
|
+
*/
|
|
1773
|
+
generatePdfFromLiquidFile(file, data = {}, options) {
|
|
1774
|
+
return this.#puppeteerService.generatePdfFromLiquidFile(file, data, options);
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1624
1777
|
* @param pdf The PDF bytes to modify
|
|
1625
1778
|
* @param fieldName The name of the signature field to add (default: 'SignatureDebtor')
|
|
1626
1779
|
* @param anchorText The text anchor to locate the signature field position (default: '__SIG_DEBTOR_ANCHOR__')
|
|
@@ -1694,7 +1847,8 @@ let PuppeteerModule = _PuppeteerModule = class PuppeteerModule {
|
|
|
1694
1847
|
EjsService,
|
|
1695
1848
|
NunjucksService,
|
|
1696
1849
|
EtaService,
|
|
1697
|
-
MustacheService
|
|
1850
|
+
MustacheService,
|
|
1851
|
+
LiquidService
|
|
1698
1852
|
],
|
|
1699
1853
|
exports: [
|
|
1700
1854
|
PuppeteerService,
|
|
@@ -1703,7 +1857,8 @@ let PuppeteerModule = _PuppeteerModule = class PuppeteerModule {
|
|
|
1703
1857
|
EjsService,
|
|
1704
1858
|
NunjucksService,
|
|
1705
1859
|
EtaService,
|
|
1706
|
-
MustacheService
|
|
1860
|
+
MustacheService,
|
|
1861
|
+
LiquidService
|
|
1707
1862
|
]
|
|
1708
1863
|
};
|
|
1709
1864
|
}
|
|
@@ -1726,7 +1881,8 @@ let PuppeteerModule = _PuppeteerModule = class PuppeteerModule {
|
|
|
1726
1881
|
EjsService,
|
|
1727
1882
|
NunjucksService,
|
|
1728
1883
|
EtaService,
|
|
1729
|
-
MustacheService
|
|
1884
|
+
MustacheService,
|
|
1885
|
+
LiquidService
|
|
1730
1886
|
],
|
|
1731
1887
|
exports: [
|
|
1732
1888
|
PuppeteerService,
|
|
@@ -1735,7 +1891,8 @@ let PuppeteerModule = _PuppeteerModule = class PuppeteerModule {
|
|
|
1735
1891
|
EjsService,
|
|
1736
1892
|
NunjucksService,
|
|
1737
1893
|
EtaService,
|
|
1738
|
-
MustacheService
|
|
1894
|
+
MustacheService,
|
|
1895
|
+
LiquidService
|
|
1739
1896
|
]
|
|
1740
1897
|
};
|
|
1741
1898
|
}
|
|
@@ -1750,7 +1907,8 @@ PuppeteerModule = _PuppeteerModule = __decorate([
|
|
|
1750
1907
|
EjsService,
|
|
1751
1908
|
NunjucksService,
|
|
1752
1909
|
EtaService,
|
|
1753
|
-
MustacheService
|
|
1910
|
+
MustacheService,
|
|
1911
|
+
LiquidService
|
|
1754
1912
|
],
|
|
1755
1913
|
exports: [
|
|
1756
1914
|
PuppeteerService,
|
|
@@ -1759,7 +1917,8 @@ PuppeteerModule = _PuppeteerModule = __decorate([
|
|
|
1759
1917
|
EjsService,
|
|
1760
1918
|
NunjucksService,
|
|
1761
1919
|
EtaService,
|
|
1762
|
-
MustacheService
|
|
1920
|
+
MustacheService,
|
|
1921
|
+
LiquidService
|
|
1763
1922
|
]
|
|
1764
1923
|
}),
|
|
1765
1924
|
__decorateParam(1, Inject(PDF_PARAMETERS)),
|
|
@@ -1788,6 +1947,6 @@ let NestjsPdfModule = _NestjsPdfModule = class NestjsPdfModule {
|
|
|
1788
1947
|
};
|
|
1789
1948
|
NestjsPdfModule = _NestjsPdfModule = __decorate([Module({})], NestjsPdfModule);
|
|
1790
1949
|
//#endregion
|
|
1791
|
-
export { BrowserInstallationException, BrowserUnavailableException, EjsService, EngineNotAvailableException, EtaService, HandlebarsService, MjmlService, MustacheService, NestjsPdfErrorCode, NestjsPdfException, NestjsPdfModule, NestjsPdfService, NunjucksService, PdfGenerationException, PugService, PuppeteerModule, PuppeteerService, SignatureDependencyException, SignaturePlacementException, TemplateConfigurationException, TemplateRenderException, WatermarkException, getRelativePathToValue };
|
|
1950
|
+
export { BrowserInstallationException, BrowserUnavailableException, EjsService, EngineNotAvailableException, EtaService, HandlebarsService, LiquidService, MjmlService, MustacheService, NestjsPdfErrorCode, NestjsPdfException, NestjsPdfModule, NestjsPdfService, NunjucksService, PdfGenerationException, PugService, PuppeteerModule, PuppeteerService, SignatureDependencyException, SignaturePlacementException, TemplateConfigurationException, TemplateRenderException, WatermarkException, getRelativePathToValue };
|
|
1792
1951
|
|
|
1793
1952
|
//# sourceMappingURL=index.mjs.map
|