@pdfgeneratorapi/n8n-nodes-pdf-generator-api 0.2.5 → 0.3.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 +19 -0
- package/dist/credentials/PdfGeneratorApi.credentials.js +26 -12
- package/dist/credentials/PdfGeneratorApi.credentials.js.map +1 -1
- package/dist/nodes/PdfGeneratorApi/PdfGeneratorApi.node.js +123 -155
- package/dist/nodes/PdfGeneratorApi/PdfGeneratorApi.node.js.map +1 -1
- package/dist/package.json +1 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -5
|
@@ -67,8 +67,8 @@ class PdfGeneratorApi {
|
|
|
67
67
|
description: 'Choose the type of PDF operation: generate documents from templates, convert HTML/URLs, process existing PDFs, or manage templates and workspaces',
|
|
68
68
|
},
|
|
69
69
|
{
|
|
70
|
-
displayName: '
|
|
71
|
-
name: '
|
|
70
|
+
displayName: 'Conversion Operations',
|
|
71
|
+
name: 'operation',
|
|
72
72
|
type: 'options',
|
|
73
73
|
noDataExpression: true,
|
|
74
74
|
displayOptions: {
|
|
@@ -93,8 +93,8 @@ class PdfGeneratorApi {
|
|
|
93
93
|
default: 'htmlToPdf',
|
|
94
94
|
},
|
|
95
95
|
{
|
|
96
|
-
displayName: '
|
|
97
|
-
name: '
|
|
96
|
+
displayName: 'Document Operations',
|
|
97
|
+
name: 'operation',
|
|
98
98
|
type: 'options',
|
|
99
99
|
noDataExpression: true,
|
|
100
100
|
displayOptions: {
|
|
@@ -149,8 +149,8 @@ class PdfGeneratorApi {
|
|
|
149
149
|
default: 'generate',
|
|
150
150
|
},
|
|
151
151
|
{
|
|
152
|
-
displayName: '
|
|
153
|
-
name: '
|
|
152
|
+
displayName: 'Services Operations',
|
|
153
|
+
name: 'operation',
|
|
154
154
|
type: 'options',
|
|
155
155
|
noDataExpression: true,
|
|
156
156
|
displayOptions: {
|
|
@@ -304,7 +304,7 @@ class PdfGeneratorApi {
|
|
|
304
304
|
displayOptions: {
|
|
305
305
|
show: {
|
|
306
306
|
resource: ['pdfServices'],
|
|
307
|
-
|
|
307
|
+
operation: ['addWatermark'],
|
|
308
308
|
},
|
|
309
309
|
},
|
|
310
310
|
description: 'Type of watermark to add (can select both text and image)',
|
|
@@ -316,7 +316,7 @@ class PdfGeneratorApi {
|
|
|
316
316
|
displayOptions: {
|
|
317
317
|
show: {
|
|
318
318
|
resource: ['pdfServices'],
|
|
319
|
-
|
|
319
|
+
operation: ['addWatermark'],
|
|
320
320
|
watermarkType: ['text'],
|
|
321
321
|
},
|
|
322
322
|
},
|
|
@@ -331,7 +331,7 @@ class PdfGeneratorApi {
|
|
|
331
331
|
displayOptions: {
|
|
332
332
|
show: {
|
|
333
333
|
resource: ['pdfServices'],
|
|
334
|
-
|
|
334
|
+
operation: ['addWatermark'],
|
|
335
335
|
watermarkType: ['image'],
|
|
336
336
|
},
|
|
337
337
|
},
|
|
@@ -348,7 +348,7 @@ class PdfGeneratorApi {
|
|
|
348
348
|
displayOptions: {
|
|
349
349
|
show: {
|
|
350
350
|
resource: ['pdfServices'],
|
|
351
|
-
|
|
351
|
+
operation: ['addWatermark'],
|
|
352
352
|
watermarkType: ['text'],
|
|
353
353
|
},
|
|
354
354
|
},
|
|
@@ -451,7 +451,7 @@ class PdfGeneratorApi {
|
|
|
451
451
|
displayOptions: {
|
|
452
452
|
show: {
|
|
453
453
|
resource: ['pdfServices'],
|
|
454
|
-
|
|
454
|
+
operation: ['addWatermark'],
|
|
455
455
|
watermarkType: ['image'],
|
|
456
456
|
},
|
|
457
457
|
},
|
|
@@ -537,7 +537,7 @@ class PdfGeneratorApi {
|
|
|
537
537
|
displayOptions: {
|
|
538
538
|
show: {
|
|
539
539
|
resource: ['pdfServices'],
|
|
540
|
-
|
|
540
|
+
operation: ['encrypt'],
|
|
541
541
|
},
|
|
542
542
|
},
|
|
543
543
|
default: '',
|
|
@@ -554,7 +554,7 @@ class PdfGeneratorApi {
|
|
|
554
554
|
displayOptions: {
|
|
555
555
|
show: {
|
|
556
556
|
resource: ['pdfServices'],
|
|
557
|
-
|
|
557
|
+
operation: ['encrypt'],
|
|
558
558
|
},
|
|
559
559
|
},
|
|
560
560
|
default: '',
|
|
@@ -572,7 +572,7 @@ class PdfGeneratorApi {
|
|
|
572
572
|
displayOptions: {
|
|
573
573
|
show: {
|
|
574
574
|
resource: ['pdfServices'],
|
|
575
|
-
|
|
575
|
+
operation: ['decrypt'],
|
|
576
576
|
},
|
|
577
577
|
},
|
|
578
578
|
default: '',
|
|
@@ -587,7 +587,7 @@ class PdfGeneratorApi {
|
|
|
587
587
|
displayOptions: {
|
|
588
588
|
show: {
|
|
589
589
|
resource: ['pdfServices'],
|
|
590
|
-
|
|
590
|
+
operation: ['fillFormFields'],
|
|
591
591
|
},
|
|
592
592
|
},
|
|
593
593
|
default: '{}',
|
|
@@ -602,7 +602,7 @@ class PdfGeneratorApi {
|
|
|
602
602
|
displayOptions: {
|
|
603
603
|
show: {
|
|
604
604
|
resource: ['document'],
|
|
605
|
-
|
|
605
|
+
operation: ['get', 'delete'],
|
|
606
606
|
},
|
|
607
607
|
},
|
|
608
608
|
default: '',
|
|
@@ -610,14 +610,14 @@ class PdfGeneratorApi {
|
|
|
610
610
|
},
|
|
611
611
|
{
|
|
612
612
|
displayName: 'List Options',
|
|
613
|
-
name: '
|
|
613
|
+
name: 'documentListOptions',
|
|
614
614
|
type: 'collection',
|
|
615
615
|
placeholder: 'Add Option',
|
|
616
616
|
default: {},
|
|
617
617
|
displayOptions: {
|
|
618
618
|
show: {
|
|
619
619
|
resource: ['document'],
|
|
620
|
-
|
|
620
|
+
operation: ['list'],
|
|
621
621
|
},
|
|
622
622
|
},
|
|
623
623
|
options: [
|
|
@@ -673,7 +673,7 @@ class PdfGeneratorApi {
|
|
|
673
673
|
displayOptions: {
|
|
674
674
|
show: {
|
|
675
675
|
resource: ['document'],
|
|
676
|
-
|
|
676
|
+
operation: ['generateBatch', 'generateBatchAsync'],
|
|
677
677
|
},
|
|
678
678
|
},
|
|
679
679
|
default: { templateList: [{}] },
|
|
@@ -740,7 +740,7 @@ class PdfGeneratorApi {
|
|
|
740
740
|
displayOptions: {
|
|
741
741
|
show: {
|
|
742
742
|
resource: ['document'],
|
|
743
|
-
|
|
743
|
+
operation: ['generateAsync', 'generateBatchAsync'],
|
|
744
744
|
},
|
|
745
745
|
},
|
|
746
746
|
options: [
|
|
@@ -837,7 +837,7 @@ class PdfGeneratorApi {
|
|
|
837
837
|
displayOptions: {
|
|
838
838
|
show: {
|
|
839
839
|
resource: ['document'],
|
|
840
|
-
|
|
840
|
+
operation: ['generate', 'generateAsync'],
|
|
841
841
|
},
|
|
842
842
|
},
|
|
843
843
|
modes: [
|
|
@@ -920,7 +920,7 @@ class PdfGeneratorApi {
|
|
|
920
920
|
displayOptions: {
|
|
921
921
|
show: {
|
|
922
922
|
resource: ['document'],
|
|
923
|
-
|
|
923
|
+
operation: ['getOutput'],
|
|
924
924
|
},
|
|
925
925
|
},
|
|
926
926
|
default: '',
|
|
@@ -934,7 +934,7 @@ class PdfGeneratorApi {
|
|
|
934
934
|
displayOptions: {
|
|
935
935
|
show: {
|
|
936
936
|
resource: ['document'],
|
|
937
|
-
|
|
937
|
+
operation: ['generate', 'generateAsync'],
|
|
938
938
|
},
|
|
939
939
|
},
|
|
940
940
|
default: '{}',
|
|
@@ -947,7 +947,7 @@ class PdfGeneratorApi {
|
|
|
947
947
|
displayOptions: {
|
|
948
948
|
show: {
|
|
949
949
|
resource: ['document'],
|
|
950
|
-
|
|
950
|
+
operation: ['generate', 'generateAsync', 'generateBatch', 'generateBatchAsync'],
|
|
951
951
|
},
|
|
952
952
|
},
|
|
953
953
|
options: [
|
|
@@ -959,26 +959,18 @@ class PdfGeneratorApi {
|
|
|
959
959
|
name: 'HTML',
|
|
960
960
|
value: 'html',
|
|
961
961
|
},
|
|
962
|
-
{
|
|
963
|
-
name: 'ZIP',
|
|
964
|
-
value: 'zip',
|
|
965
|
-
},
|
|
966
|
-
{
|
|
967
|
-
name: 'XLSX',
|
|
968
|
-
value: 'xlsx',
|
|
969
|
-
},
|
|
970
962
|
],
|
|
971
963
|
default: 'pdf',
|
|
972
|
-
description: 'Document format
|
|
964
|
+
description: 'Document format',
|
|
973
965
|
},
|
|
974
966
|
{
|
|
975
967
|
displayName: 'Output',
|
|
976
|
-
name: '
|
|
968
|
+
name: 'documentOutput',
|
|
977
969
|
type: 'options',
|
|
978
970
|
displayOptions: {
|
|
979
971
|
show: {
|
|
980
972
|
resource: ['document'],
|
|
981
|
-
|
|
973
|
+
operation: ['generate', 'generateBatch'],
|
|
982
974
|
},
|
|
983
975
|
},
|
|
984
976
|
options: [
|
|
@@ -1000,12 +992,12 @@ class PdfGeneratorApi {
|
|
|
1000
992
|
},
|
|
1001
993
|
{
|
|
1002
994
|
displayName: 'Output',
|
|
1003
|
-
name: '
|
|
995
|
+
name: 'documentOutputAsync',
|
|
1004
996
|
type: 'options',
|
|
1005
997
|
displayOptions: {
|
|
1006
998
|
show: {
|
|
1007
999
|
resource: ['document'],
|
|
1008
|
-
|
|
1000
|
+
operation: ['generateAsync', 'generateBatchAsync'],
|
|
1009
1001
|
},
|
|
1010
1002
|
},
|
|
1011
1003
|
options: [
|
|
@@ -1030,7 +1022,7 @@ class PdfGeneratorApi {
|
|
|
1030
1022
|
displayOptions: {
|
|
1031
1023
|
show: {
|
|
1032
1024
|
resource: ['document'],
|
|
1033
|
-
|
|
1025
|
+
operation: ['generate', 'generateAsync', 'generateBatch', 'generateBatchAsync'],
|
|
1034
1026
|
},
|
|
1035
1027
|
},
|
|
1036
1028
|
options: [
|
|
@@ -1130,7 +1122,7 @@ class PdfGeneratorApi {
|
|
|
1130
1122
|
},
|
|
1131
1123
|
{
|
|
1132
1124
|
displayName: 'List Options',
|
|
1133
|
-
name: '
|
|
1125
|
+
name: 'templateListOptions',
|
|
1134
1126
|
type: 'collection',
|
|
1135
1127
|
placeholder: 'Add Option',
|
|
1136
1128
|
default: {},
|
|
@@ -1184,7 +1176,7 @@ class PdfGeneratorApi {
|
|
|
1184
1176
|
],
|
|
1185
1177
|
},
|
|
1186
1178
|
{
|
|
1187
|
-
displayName: '
|
|
1179
|
+
displayName: 'Workspace Operations',
|
|
1188
1180
|
name: 'operation',
|
|
1189
1181
|
type: 'options',
|
|
1190
1182
|
noDataExpression: true,
|
|
@@ -1223,7 +1215,7 @@ class PdfGeneratorApi {
|
|
|
1223
1215
|
},
|
|
1224
1216
|
{
|
|
1225
1217
|
displayName: 'List Options',
|
|
1226
|
-
name: '
|
|
1218
|
+
name: 'workspaceListOptions',
|
|
1227
1219
|
type: 'collection',
|
|
1228
1220
|
placeholder: 'Add Option',
|
|
1229
1221
|
default: {},
|
|
@@ -1305,7 +1297,7 @@ class PdfGeneratorApi {
|
|
|
1305
1297
|
displayOptions: {
|
|
1306
1298
|
show: {
|
|
1307
1299
|
resource: ['conversion'],
|
|
1308
|
-
|
|
1300
|
+
operation: ['htmlToPdf'],
|
|
1309
1301
|
},
|
|
1310
1302
|
},
|
|
1311
1303
|
default: `<!DOCTYPE html>
|
|
@@ -1414,7 +1406,7 @@ class PdfGeneratorApi {
|
|
|
1414
1406
|
displayOptions: {
|
|
1415
1407
|
show: {
|
|
1416
1408
|
resource: ['conversion'],
|
|
1417
|
-
|
|
1409
|
+
operation: ['urlToPdf'],
|
|
1418
1410
|
},
|
|
1419
1411
|
},
|
|
1420
1412
|
default: '',
|
|
@@ -1525,7 +1517,7 @@ class PdfGeneratorApi {
|
|
|
1525
1517
|
},
|
|
1526
1518
|
{
|
|
1527
1519
|
displayName: 'Output Format',
|
|
1528
|
-
name: '
|
|
1520
|
+
name: 'conversionOutput',
|
|
1529
1521
|
type: 'options',
|
|
1530
1522
|
options: [
|
|
1531
1523
|
{
|
|
@@ -1577,6 +1569,9 @@ class PdfGeneratorApi {
|
|
|
1577
1569
|
}
|
|
1578
1570
|
}
|
|
1579
1571
|
catch (error) {
|
|
1572
|
+
return {
|
|
1573
|
+
results: [],
|
|
1574
|
+
};
|
|
1580
1575
|
}
|
|
1581
1576
|
const sortedResults = returnData.sort((a, b) => a.name.localeCompare(b.name));
|
|
1582
1577
|
return {
|
|
@@ -1590,24 +1585,27 @@ class PdfGeneratorApi {
|
|
|
1590
1585
|
const items = this.getInputData();
|
|
1591
1586
|
const returnData = [];
|
|
1592
1587
|
const resource = this.getNodeParameter('resource', 0);
|
|
1593
|
-
|
|
1594
|
-
switch (resource) {
|
|
1595
|
-
case 'conversion':
|
|
1596
|
-
operation = this.getNodeParameter('conversionOperation', 0);
|
|
1597
|
-
break;
|
|
1598
|
-
case 'document':
|
|
1599
|
-
operation = this.getNodeParameter('documentOperation', 0);
|
|
1600
|
-
break;
|
|
1601
|
-
case 'pdfServices':
|
|
1602
|
-
operation = this.getNodeParameter('pdfServicesOperation', 0);
|
|
1603
|
-
break;
|
|
1604
|
-
case 'template':
|
|
1605
|
-
case 'workspace':
|
|
1606
|
-
default:
|
|
1607
|
-
operation = this.getNodeParameter('operation', 0);
|
|
1608
|
-
}
|
|
1588
|
+
const operation = this.getNodeParameter('operation', 0);
|
|
1609
1589
|
const credentials = await this.getCredentials('pdfGeneratorApi');
|
|
1610
1590
|
const baseURL = credentials.baseUrl || 'https://us1.pdfgeneratorapi.com/api/v4';
|
|
1591
|
+
const parseJSON = (value, field) => {
|
|
1592
|
+
try {
|
|
1593
|
+
return typeof value === 'string' ? JSON.parse(value) : value;
|
|
1594
|
+
}
|
|
1595
|
+
catch (error) {
|
|
1596
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${field} must be valid JSON`);
|
|
1597
|
+
}
|
|
1598
|
+
};
|
|
1599
|
+
const getMimeType = (format) => {
|
|
1600
|
+
switch (format) {
|
|
1601
|
+
case 'pdf':
|
|
1602
|
+
return 'application/pdf';
|
|
1603
|
+
case 'html':
|
|
1604
|
+
return 'text/html';
|
|
1605
|
+
default:
|
|
1606
|
+
return 'application/octet-stream';
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1611
1609
|
for (let i = 0; i < items.length; i++) {
|
|
1612
1610
|
try {
|
|
1613
1611
|
let responseData;
|
|
@@ -1638,7 +1636,7 @@ class PdfGeneratorApi {
|
|
|
1638
1636
|
const body = {
|
|
1639
1637
|
paper_size: conversionOptions.paper_size || 'a4',
|
|
1640
1638
|
orientation: conversionOptions.orientation || 'portrait',
|
|
1641
|
-
output: conversionOptions.
|
|
1639
|
+
output: conversionOptions.conversionOutput || 'base64',
|
|
1642
1640
|
filename: filename || 'document',
|
|
1643
1641
|
};
|
|
1644
1642
|
if (operation === 'htmlToPdf') {
|
|
@@ -1672,14 +1670,13 @@ class PdfGeneratorApi {
|
|
|
1672
1670
|
if (outputFormat === 'file') {
|
|
1673
1671
|
const binaryData = {};
|
|
1674
1672
|
const fileName = `${filename}.pdf`;
|
|
1675
|
-
|
|
1676
|
-
binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, 'application/pdf');
|
|
1673
|
+
binaryData[fileName] = await this.helpers.prepareBinaryData(responseData, fileName, 'application/pdf');
|
|
1677
1674
|
returnData.push({
|
|
1678
1675
|
json: {
|
|
1679
1676
|
success: true,
|
|
1680
1677
|
filename: `${filename}.pdf`,
|
|
1681
1678
|
format: outputFormat,
|
|
1682
|
-
fileSize:
|
|
1679
|
+
fileSize: responseData.length,
|
|
1683
1680
|
},
|
|
1684
1681
|
binary: binaryData,
|
|
1685
1682
|
});
|
|
@@ -1699,18 +1696,18 @@ class PdfGeneratorApi {
|
|
|
1699
1696
|
}
|
|
1700
1697
|
else if (resource === 'document') {
|
|
1701
1698
|
if (operation === 'list') {
|
|
1702
|
-
const
|
|
1699
|
+
const documentListOptions = this.getNodeParameter('documentListOptions', i, {});
|
|
1703
1700
|
const qs = {};
|
|
1704
|
-
if (
|
|
1705
|
-
qs.template_id =
|
|
1706
|
-
if (
|
|
1707
|
-
qs.start_date =
|
|
1708
|
-
if (
|
|
1709
|
-
qs.end_date =
|
|
1710
|
-
if (
|
|
1711
|
-
qs.page =
|
|
1712
|
-
if (
|
|
1713
|
-
qs.per_page =
|
|
1701
|
+
if (documentListOptions.template_id)
|
|
1702
|
+
qs.template_id = documentListOptions.template_id;
|
|
1703
|
+
if (documentListOptions.start_date)
|
|
1704
|
+
qs.start_date = documentListOptions.start_date;
|
|
1705
|
+
if (documentListOptions.end_date)
|
|
1706
|
+
qs.end_date = documentListOptions.end_date;
|
|
1707
|
+
if (documentListOptions.page)
|
|
1708
|
+
qs.page = documentListOptions.page;
|
|
1709
|
+
if (documentListOptions.per_page)
|
|
1710
|
+
qs.per_page = documentListOptions.per_page;
|
|
1714
1711
|
const options = {
|
|
1715
1712
|
method: 'GET',
|
|
1716
1713
|
baseURL,
|
|
@@ -1750,12 +1747,12 @@ class PdfGeneratorApi {
|
|
|
1750
1747
|
const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
|
|
1751
1748
|
const data = this.getNodeParameter('data', i);
|
|
1752
1749
|
const format = this.getNodeParameter('format', i, 'pdf');
|
|
1753
|
-
const output = this.getNodeParameter('
|
|
1750
|
+
const output = this.getNodeParameter('documentOutput', i, 'base64');
|
|
1754
1751
|
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
|
1755
1752
|
const body = {
|
|
1756
1753
|
template: {
|
|
1757
1754
|
id: templateId,
|
|
1758
|
-
data:
|
|
1755
|
+
data: parseJSON(data, 'data'),
|
|
1759
1756
|
},
|
|
1760
1757
|
format,
|
|
1761
1758
|
output,
|
|
@@ -1777,14 +1774,13 @@ class PdfGeneratorApi {
|
|
|
1777
1774
|
if (output === 'file') {
|
|
1778
1775
|
const binaryData = {};
|
|
1779
1776
|
const fileName = `${additionalFields.outputName || 'document'}.${format}`;
|
|
1780
|
-
|
|
1781
|
-
binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, format === 'pdf' ? 'application/pdf' : `application/${format}`);
|
|
1777
|
+
binaryData[fileName] = await this.helpers.prepareBinaryData(responseData, fileName, getMimeType(format));
|
|
1782
1778
|
returnData.push({
|
|
1783
1779
|
json: {
|
|
1784
1780
|
success: true,
|
|
1785
1781
|
filename: fileName,
|
|
1786
1782
|
format: output,
|
|
1787
|
-
fileSize:
|
|
1783
|
+
fileSize: responseData.length,
|
|
1788
1784
|
},
|
|
1789
1785
|
binary: binaryData,
|
|
1790
1786
|
});
|
|
@@ -1808,13 +1804,13 @@ class PdfGeneratorApi {
|
|
|
1808
1804
|
const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
|
|
1809
1805
|
const data = this.getNodeParameter('data', i);
|
|
1810
1806
|
const format = this.getNodeParameter('format', i, 'pdf');
|
|
1811
|
-
const output = this.getNodeParameter('
|
|
1807
|
+
const output = this.getNodeParameter('documentOutputAsync', i, 'base64');
|
|
1812
1808
|
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
|
1813
1809
|
const callbackOptions = this.getNodeParameter('callbackOptions', i, {});
|
|
1814
1810
|
const body = {
|
|
1815
1811
|
template: {
|
|
1816
1812
|
id: templateId,
|
|
1817
|
-
data:
|
|
1813
|
+
data: parseJSON(data, 'data'),
|
|
1818
1814
|
},
|
|
1819
1815
|
format,
|
|
1820
1816
|
output,
|
|
@@ -1824,7 +1820,7 @@ class PdfGeneratorApi {
|
|
|
1824
1820
|
url: callbackOptions.url,
|
|
1825
1821
|
};
|
|
1826
1822
|
if (callbackOptions.headers) {
|
|
1827
|
-
body.callback.headers =
|
|
1823
|
+
body.callback.headers = parseJSON(callbackOptions.headers, 'callbackOptions.headers');
|
|
1828
1824
|
}
|
|
1829
1825
|
}
|
|
1830
1826
|
if (additionalFields.outputName)
|
|
@@ -1843,13 +1839,13 @@ class PdfGeneratorApi {
|
|
|
1843
1839
|
else if (operation === 'generateBatch') {
|
|
1844
1840
|
const templates = this.getNodeParameter('templates', i);
|
|
1845
1841
|
const format = this.getNodeParameter('format', i, 'pdf');
|
|
1846
|
-
const output = this.getNodeParameter('
|
|
1842
|
+
const output = this.getNodeParameter('documentOutput', i, 'base64');
|
|
1847
1843
|
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
|
1848
1844
|
const templateArray = templates.templateList.map((template) => {
|
|
1849
1845
|
const templateId = typeof template.templateId === 'string' ? template.templateId : template.templateId.value;
|
|
1850
1846
|
return {
|
|
1851
1847
|
id: templateId,
|
|
1852
|
-
data:
|
|
1848
|
+
data: parseJSON(template.data, 'template.data'),
|
|
1853
1849
|
};
|
|
1854
1850
|
});
|
|
1855
1851
|
const body = {
|
|
@@ -1866,40 +1862,21 @@ class PdfGeneratorApi {
|
|
|
1866
1862
|
baseURL,
|
|
1867
1863
|
url: '/documents/generate/batch',
|
|
1868
1864
|
body,
|
|
1869
|
-
json:
|
|
1865
|
+
json: output !== 'file',
|
|
1866
|
+
encoding: output === 'file' ? null : 'utf8',
|
|
1870
1867
|
};
|
|
1871
1868
|
responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
|
|
1872
1869
|
if (responseData && output !== 'url') {
|
|
1873
1870
|
if (output === 'file') {
|
|
1874
|
-
let fileData = responseData.response || responseData.data || responseData;
|
|
1875
|
-
if (!fileData) {
|
|
1876
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `No file data received from API. Response structure: ${JSON.stringify(Object.keys(responseData))}`, { itemIndex: i });
|
|
1877
|
-
}
|
|
1878
1871
|
const binaryData = {};
|
|
1879
1872
|
const fileName = `${additionalFields.outputName || 'batch-documents'}.${format}`;
|
|
1880
|
-
|
|
1881
|
-
if (typeof fileData === 'string') {
|
|
1882
|
-
if (fileData.startsWith('data:')) {
|
|
1883
|
-
const base64Data = fileData.split(',')[1];
|
|
1884
|
-
binaryBuffer = Buffer.from(base64Data, 'base64');
|
|
1885
|
-
}
|
|
1886
|
-
else {
|
|
1887
|
-
binaryBuffer = Buffer.from(fileData, 'base64');
|
|
1888
|
-
}
|
|
1889
|
-
}
|
|
1890
|
-
else if (Buffer.isBuffer(fileData)) {
|
|
1891
|
-
binaryBuffer = fileData;
|
|
1892
|
-
}
|
|
1893
|
-
else {
|
|
1894
|
-
binaryBuffer = Buffer.from(fileData);
|
|
1895
|
-
}
|
|
1896
|
-
binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, format === 'pdf' ? 'application/pdf' : `application/${format}`);
|
|
1873
|
+
binaryData[fileName] = await this.helpers.prepareBinaryData(responseData, fileName, getMimeType(format));
|
|
1897
1874
|
returnData.push({
|
|
1898
1875
|
json: {
|
|
1899
1876
|
success: true,
|
|
1900
1877
|
filename: fileName,
|
|
1901
1878
|
format: output,
|
|
1902
|
-
|
|
1879
|
+
fileSize: responseData.length,
|
|
1903
1880
|
},
|
|
1904
1881
|
binary: binaryData,
|
|
1905
1882
|
});
|
|
@@ -1921,14 +1898,14 @@ class PdfGeneratorApi {
|
|
|
1921
1898
|
else if (operation === 'generateBatchAsync') {
|
|
1922
1899
|
const templates = this.getNodeParameter('templates', i);
|
|
1923
1900
|
const format = this.getNodeParameter('format', i, 'pdf');
|
|
1924
|
-
const output = this.getNodeParameter('
|
|
1901
|
+
const output = this.getNodeParameter('documentOutputAsync', i, 'base64');
|
|
1925
1902
|
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
|
1926
1903
|
const callbackOptions = this.getNodeParameter('callbackOptions', i, {});
|
|
1927
1904
|
const templateArray = templates.templateList.map((template) => {
|
|
1928
1905
|
const templateId = typeof template.templateId === 'string' ? template.templateId : template.templateId.value;
|
|
1929
1906
|
return {
|
|
1930
1907
|
id: templateId,
|
|
1931
|
-
data:
|
|
1908
|
+
data: parseJSON(template.data, 'template.data'),
|
|
1932
1909
|
};
|
|
1933
1910
|
});
|
|
1934
1911
|
const body = {
|
|
@@ -1941,7 +1918,7 @@ class PdfGeneratorApi {
|
|
|
1941
1918
|
url: callbackOptions.url,
|
|
1942
1919
|
};
|
|
1943
1920
|
if (callbackOptions.headers) {
|
|
1944
|
-
body.callback.headers =
|
|
1921
|
+
body.callback.headers = parseJSON(callbackOptions.headers, 'callbackOptions.headers');
|
|
1945
1922
|
}
|
|
1946
1923
|
}
|
|
1947
1924
|
if (additionalFields.outputName)
|
|
@@ -1960,18 +1937,18 @@ class PdfGeneratorApi {
|
|
|
1960
1937
|
}
|
|
1961
1938
|
else if (resource === 'template') {
|
|
1962
1939
|
if (operation === 'list') {
|
|
1963
|
-
const
|
|
1940
|
+
const templateListOptions = this.getNodeParameter('templateListOptions', i, {});
|
|
1964
1941
|
const qs = {};
|
|
1965
|
-
if (
|
|
1966
|
-
qs.name =
|
|
1967
|
-
if (
|
|
1968
|
-
qs.tags =
|
|
1969
|
-
if (
|
|
1970
|
-
qs.access =
|
|
1971
|
-
if (
|
|
1972
|
-
qs.page =
|
|
1973
|
-
if (
|
|
1974
|
-
qs.per_page =
|
|
1942
|
+
if (templateListOptions.name)
|
|
1943
|
+
qs.name = templateListOptions.name;
|
|
1944
|
+
if (templateListOptions.tags)
|
|
1945
|
+
qs.tags = templateListOptions.tags;
|
|
1946
|
+
if (templateListOptions.access)
|
|
1947
|
+
qs.access = templateListOptions.access;
|
|
1948
|
+
if (templateListOptions.page)
|
|
1949
|
+
qs.page = templateListOptions.page;
|
|
1950
|
+
if (templateListOptions.per_page)
|
|
1951
|
+
qs.per_page = templateListOptions.per_page;
|
|
1975
1952
|
const options = {
|
|
1976
1953
|
method: 'GET',
|
|
1977
1954
|
baseURL,
|
|
@@ -1994,7 +1971,7 @@ class PdfGeneratorApi {
|
|
|
1994
1971
|
}
|
|
1995
1972
|
else if (operation === 'create') {
|
|
1996
1973
|
const templateConfiguration = this.getNodeParameter('templateConfiguration', i);
|
|
1997
|
-
const body =
|
|
1974
|
+
const body = parseJSON(templateConfiguration, 'templateConfiguration');
|
|
1998
1975
|
const options = {
|
|
1999
1976
|
method: 'POST',
|
|
2000
1977
|
baseURL,
|
|
@@ -2008,7 +1985,7 @@ class PdfGeneratorApi {
|
|
|
2008
1985
|
const templateIdParam = this.getNodeParameter('templateId', i);
|
|
2009
1986
|
const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
|
|
2010
1987
|
const templateConfiguration = this.getNodeParameter('templateConfiguration', i);
|
|
2011
|
-
const body =
|
|
1988
|
+
const body = parseJSON(templateConfiguration, 'templateConfiguration');
|
|
2012
1989
|
const options = {
|
|
2013
1990
|
method: 'PUT',
|
|
2014
1991
|
baseURL,
|
|
@@ -2036,7 +2013,7 @@ class PdfGeneratorApi {
|
|
|
2036
2013
|
}
|
|
2037
2014
|
else if (operation === 'validate') {
|
|
2038
2015
|
const templateConfig = this.getNodeParameter('templateConfig', i);
|
|
2039
|
-
const body =
|
|
2016
|
+
const body = parseJSON(templateConfig, 'templateConfig');
|
|
2040
2017
|
if (!body || typeof body !== 'object') {
|
|
2041
2018
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Template configuration must be a valid JSON object', { itemIndex: i });
|
|
2042
2019
|
}
|
|
@@ -2082,7 +2059,7 @@ class PdfGeneratorApi {
|
|
|
2082
2059
|
const editorOptions = this.getNodeParameter('editorOptions', i, {});
|
|
2083
2060
|
const body = {};
|
|
2084
2061
|
if (editorOptions.data)
|
|
2085
|
-
body.data =
|
|
2062
|
+
body.data = parseJSON(editorOptions.data, 'editorOptions.data');
|
|
2086
2063
|
if (editorOptions.language)
|
|
2087
2064
|
body.language = editorOptions.language;
|
|
2088
2065
|
const options = {
|
|
@@ -2098,6 +2075,7 @@ class PdfGeneratorApi {
|
|
|
2098
2075
|
else if (resource === 'pdfServices') {
|
|
2099
2076
|
const pdfSource = this.getNodeParameter('pdfSource', i);
|
|
2100
2077
|
const outputFormat = this.getNodeParameter('outputFormat', i, 'base64');
|
|
2078
|
+
let optimizationStats = null;
|
|
2101
2079
|
const body = {};
|
|
2102
2080
|
if (pdfSource === 'url') {
|
|
2103
2081
|
body.file_url = this.getNodeParameter('fileUrl', i);
|
|
@@ -2202,13 +2180,7 @@ class PdfGeneratorApi {
|
|
|
2202
2180
|
}
|
|
2203
2181
|
else if (operation === 'fillFormFields') {
|
|
2204
2182
|
const formFieldsData = this.getNodeParameter('formFieldsData', i);
|
|
2205
|
-
|
|
2206
|
-
try {
|
|
2207
|
-
parsedData = typeof formFieldsData === 'string' ? JSON.parse(formFieldsData) : formFieldsData;
|
|
2208
|
-
}
|
|
2209
|
-
catch (error) {
|
|
2210
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Form Fields Data must be valid JSON');
|
|
2211
|
-
}
|
|
2183
|
+
const parsedData = parseJSON(formFieldsData, 'Form Fields Data');
|
|
2212
2184
|
body.data = parsedData;
|
|
2213
2185
|
const options = {
|
|
2214
2186
|
method: 'POST',
|
|
@@ -2235,7 +2207,7 @@ class PdfGeneratorApi {
|
|
|
2235
2207
|
const headers = fullResponse.headers || {};
|
|
2236
2208
|
const originalSize = headers['x-original-size'] ? parseInt(headers['x-original-size'], 10) : null;
|
|
2237
2209
|
const optimizedSize = headers['x-optimized-size'] ? parseInt(headers['x-optimized-size'], 10) : null;
|
|
2238
|
-
|
|
2210
|
+
optimizationStats = {
|
|
2239
2211
|
originalSize,
|
|
2240
2212
|
optimizedSize,
|
|
2241
2213
|
compressionRatio: originalSize && optimizedSize ? ((originalSize - optimizedSize) / originalSize * 100) : null
|
|
@@ -2254,22 +2226,20 @@ class PdfGeneratorApi {
|
|
|
2254
2226
|
else if (outputFormat === 'file') {
|
|
2255
2227
|
const binaryData = {};
|
|
2256
2228
|
const fileName = `processed-document.pdf`;
|
|
2257
|
-
|
|
2258
|
-
binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, 'application/pdf');
|
|
2229
|
+
binaryData[fileName] = await this.helpers.prepareBinaryData(responseData, fileName, 'application/pdf');
|
|
2259
2230
|
const jsonResponse = {
|
|
2260
2231
|
success: true,
|
|
2261
2232
|
operation,
|
|
2262
2233
|
filename: fileName,
|
|
2263
2234
|
format: outputFormat,
|
|
2264
|
-
fileSize:
|
|
2235
|
+
fileSize: responseData.length,
|
|
2265
2236
|
};
|
|
2266
|
-
if (operation === 'optimize' &&
|
|
2267
|
-
const stats = responseData.__optimizationStats;
|
|
2237
|
+
if (operation === 'optimize' && optimizationStats) {
|
|
2268
2238
|
jsonResponse.optimizationStats = {
|
|
2269
|
-
originalSize:
|
|
2270
|
-
optimizedSize:
|
|
2271
|
-
savedBytes:
|
|
2272
|
-
compressionRatio:
|
|
2239
|
+
originalSize: optimizationStats.originalSize,
|
|
2240
|
+
optimizedSize: optimizationStats.optimizedSize,
|
|
2241
|
+
savedBytes: optimizationStats.originalSize && optimizationStats.optimizedSize ? optimizationStats.originalSize - optimizationStats.optimizedSize : null,
|
|
2242
|
+
compressionRatio: optimizationStats.compressionRatio ? `${optimizationStats.compressionRatio.toFixed(2)}%` : null
|
|
2273
2243
|
};
|
|
2274
2244
|
}
|
|
2275
2245
|
returnData.push({
|
|
@@ -2284,15 +2254,13 @@ class PdfGeneratorApi {
|
|
|
2284
2254
|
format: outputFormat,
|
|
2285
2255
|
...responseData,
|
|
2286
2256
|
};
|
|
2287
|
-
if (operation === 'optimize' &&
|
|
2288
|
-
const stats = responseData.__optimizationStats;
|
|
2257
|
+
if (operation === 'optimize' && optimizationStats) {
|
|
2289
2258
|
jsonResponse.optimizationStats = {
|
|
2290
|
-
originalSize:
|
|
2291
|
-
optimizedSize:
|
|
2292
|
-
savedBytes:
|
|
2293
|
-
compressionRatio:
|
|
2259
|
+
originalSize: optimizationStats.originalSize,
|
|
2260
|
+
optimizedSize: optimizationStats.optimizedSize,
|
|
2261
|
+
savedBytes: optimizationStats.originalSize && optimizationStats.optimizedSize ? optimizationStats.originalSize - optimizationStats.optimizedSize : null,
|
|
2262
|
+
compressionRatio: optimizationStats.compressionRatio ? `${optimizationStats.compressionRatio.toFixed(2)}%` : null
|
|
2294
2263
|
};
|
|
2295
|
-
delete jsonResponse.__optimizationStats;
|
|
2296
2264
|
}
|
|
2297
2265
|
returnData.push({
|
|
2298
2266
|
json: jsonResponse,
|
|
@@ -2303,12 +2271,12 @@ class PdfGeneratorApi {
|
|
|
2303
2271
|
}
|
|
2304
2272
|
else if (resource === 'workspace') {
|
|
2305
2273
|
if (operation === 'list') {
|
|
2306
|
-
const
|
|
2274
|
+
const workspaceListOptions = this.getNodeParameter('workspaceListOptions', i, {});
|
|
2307
2275
|
const qs = {};
|
|
2308
|
-
if (
|
|
2309
|
-
qs.page =
|
|
2310
|
-
if (
|
|
2311
|
-
qs.per_page =
|
|
2276
|
+
if (workspaceListOptions.page)
|
|
2277
|
+
qs.page = workspaceListOptions.page;
|
|
2278
|
+
if (workspaceListOptions.per_page)
|
|
2279
|
+
qs.per_page = workspaceListOptions.per_page;
|
|
2312
2280
|
const options = {
|
|
2313
2281
|
method: 'GET',
|
|
2314
2282
|
baseURL,
|