@custom-js/n8n-nodes-pdf-toolkit 1.30.0 → 1.32.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.
|
@@ -4,9 +4,9 @@ exports.InvoiceGenerator = void 0;
|
|
|
4
4
|
class InvoiceGenerator {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.description = {
|
|
7
|
-
displayName: 'Invoice Generator',
|
|
7
|
+
displayName: 'Invoice Generator (CustomJS)',
|
|
8
8
|
name: 'invoiceGenerator',
|
|
9
|
-
icon:
|
|
9
|
+
icon: "file:customJs.svg",
|
|
10
10
|
group: ['transform'],
|
|
11
11
|
version: 1,
|
|
12
12
|
description: 'Create PDF invoices from data and templates',
|
|
@@ -176,8 +176,11 @@ class InvoiceGenerator {
|
|
|
176
176
|
const templateString = await fetch(tpl).then(r => r.text());
|
|
177
177
|
const renderedHtml = await nunjucks.renderString(
|
|
178
178
|
templateString,
|
|
179
|
-
{ invoiceData: JSON.stringify(input).replace(
|
|
179
|
+
{ invoiceData: JSON.stringify(input).replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\").replace(/\\n/g, '\\\\n')
|
|
180
|
+
|
|
181
|
+
}
|
|
180
182
|
);
|
|
183
|
+
console.log('renderedHtml', renderedHtml);
|
|
181
184
|
return HTML2PDF(renderedHtml);
|
|
182
185
|
`;
|
|
183
186
|
const options = {
|
|
@@ -195,13 +198,20 @@ class InvoiceGenerator {
|
|
|
195
198
|
encoding: 'binary',
|
|
196
199
|
json: true,
|
|
197
200
|
};
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
const response = await this.helpers.request(options);
|
|
202
|
+
if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
|
|
203
|
+
// No binary data returned; emit only JSON without a binary property
|
|
204
|
+
returnData.push({
|
|
205
|
+
json: items[i].json,
|
|
206
|
+
});
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
const binaryData = await this.helpers.prepareBinaryData(response, "Invoice.pdf");
|
|
202
210
|
returnData.push({
|
|
203
|
-
json:
|
|
204
|
-
binary: {
|
|
211
|
+
json: items[i].json,
|
|
212
|
+
binary: {
|
|
213
|
+
data: binaryData,
|
|
214
|
+
},
|
|
205
215
|
});
|
|
206
216
|
}
|
|
207
217
|
return [returnData];
|