@pdfgeneratorapi/n8n-nodes-pdf-generator-api 0.2.6 → 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.
|
@@ -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
|
{
|
|
@@ -1593,24 +1585,27 @@ class PdfGeneratorApi {
|
|
|
1593
1585
|
const items = this.getInputData();
|
|
1594
1586
|
const returnData = [];
|
|
1595
1587
|
const resource = this.getNodeParameter('resource', 0);
|
|
1596
|
-
|
|
1597
|
-
switch (resource) {
|
|
1598
|
-
case 'conversion':
|
|
1599
|
-
operation = this.getNodeParameter('conversionOperation', 0);
|
|
1600
|
-
break;
|
|
1601
|
-
case 'document':
|
|
1602
|
-
operation = this.getNodeParameter('documentOperation', 0);
|
|
1603
|
-
break;
|
|
1604
|
-
case 'pdfServices':
|
|
1605
|
-
operation = this.getNodeParameter('pdfServicesOperation', 0);
|
|
1606
|
-
break;
|
|
1607
|
-
case 'template':
|
|
1608
|
-
case 'workspace':
|
|
1609
|
-
default:
|
|
1610
|
-
operation = this.getNodeParameter('operation', 0);
|
|
1611
|
-
}
|
|
1588
|
+
const operation = this.getNodeParameter('operation', 0);
|
|
1612
1589
|
const credentials = await this.getCredentials('pdfGeneratorApi');
|
|
1613
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
|
+
};
|
|
1614
1609
|
for (let i = 0; i < items.length; i++) {
|
|
1615
1610
|
try {
|
|
1616
1611
|
let responseData;
|
|
@@ -1641,7 +1636,7 @@ class PdfGeneratorApi {
|
|
|
1641
1636
|
const body = {
|
|
1642
1637
|
paper_size: conversionOptions.paper_size || 'a4',
|
|
1643
1638
|
orientation: conversionOptions.orientation || 'portrait',
|
|
1644
|
-
output: conversionOptions.
|
|
1639
|
+
output: conversionOptions.conversionOutput || 'base64',
|
|
1645
1640
|
filename: filename || 'document',
|
|
1646
1641
|
};
|
|
1647
1642
|
if (operation === 'htmlToPdf') {
|
|
@@ -1675,14 +1670,13 @@ class PdfGeneratorApi {
|
|
|
1675
1670
|
if (outputFormat === 'file') {
|
|
1676
1671
|
const binaryData = {};
|
|
1677
1672
|
const fileName = `${filename}.pdf`;
|
|
1678
|
-
|
|
1679
|
-
binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, 'application/pdf');
|
|
1673
|
+
binaryData[fileName] = await this.helpers.prepareBinaryData(responseData, fileName, 'application/pdf');
|
|
1680
1674
|
returnData.push({
|
|
1681
1675
|
json: {
|
|
1682
1676
|
success: true,
|
|
1683
1677
|
filename: `${filename}.pdf`,
|
|
1684
1678
|
format: outputFormat,
|
|
1685
|
-
fileSize:
|
|
1679
|
+
fileSize: responseData.length,
|
|
1686
1680
|
},
|
|
1687
1681
|
binary: binaryData,
|
|
1688
1682
|
});
|
|
@@ -1702,18 +1696,18 @@ class PdfGeneratorApi {
|
|
|
1702
1696
|
}
|
|
1703
1697
|
else if (resource === 'document') {
|
|
1704
1698
|
if (operation === 'list') {
|
|
1705
|
-
const
|
|
1699
|
+
const documentListOptions = this.getNodeParameter('documentListOptions', i, {});
|
|
1706
1700
|
const qs = {};
|
|
1707
|
-
if (
|
|
1708
|
-
qs.template_id =
|
|
1709
|
-
if (
|
|
1710
|
-
qs.start_date =
|
|
1711
|
-
if (
|
|
1712
|
-
qs.end_date =
|
|
1713
|
-
if (
|
|
1714
|
-
qs.page =
|
|
1715
|
-
if (
|
|
1716
|
-
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;
|
|
1717
1711
|
const options = {
|
|
1718
1712
|
method: 'GET',
|
|
1719
1713
|
baseURL,
|
|
@@ -1753,12 +1747,12 @@ class PdfGeneratorApi {
|
|
|
1753
1747
|
const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
|
|
1754
1748
|
const data = this.getNodeParameter('data', i);
|
|
1755
1749
|
const format = this.getNodeParameter('format', i, 'pdf');
|
|
1756
|
-
const output = this.getNodeParameter('
|
|
1750
|
+
const output = this.getNodeParameter('documentOutput', i, 'base64');
|
|
1757
1751
|
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
|
1758
1752
|
const body = {
|
|
1759
1753
|
template: {
|
|
1760
1754
|
id: templateId,
|
|
1761
|
-
data:
|
|
1755
|
+
data: parseJSON(data, 'data'),
|
|
1762
1756
|
},
|
|
1763
1757
|
format,
|
|
1764
1758
|
output,
|
|
@@ -1780,14 +1774,13 @@ class PdfGeneratorApi {
|
|
|
1780
1774
|
if (output === 'file') {
|
|
1781
1775
|
const binaryData = {};
|
|
1782
1776
|
const fileName = `${additionalFields.outputName || 'document'}.${format}`;
|
|
1783
|
-
|
|
1784
|
-
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));
|
|
1785
1778
|
returnData.push({
|
|
1786
1779
|
json: {
|
|
1787
1780
|
success: true,
|
|
1788
1781
|
filename: fileName,
|
|
1789
1782
|
format: output,
|
|
1790
|
-
fileSize:
|
|
1783
|
+
fileSize: responseData.length,
|
|
1791
1784
|
},
|
|
1792
1785
|
binary: binaryData,
|
|
1793
1786
|
});
|
|
@@ -1811,13 +1804,13 @@ class PdfGeneratorApi {
|
|
|
1811
1804
|
const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
|
|
1812
1805
|
const data = this.getNodeParameter('data', i);
|
|
1813
1806
|
const format = this.getNodeParameter('format', i, 'pdf');
|
|
1814
|
-
const output = this.getNodeParameter('
|
|
1807
|
+
const output = this.getNodeParameter('documentOutputAsync', i, 'base64');
|
|
1815
1808
|
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
|
1816
1809
|
const callbackOptions = this.getNodeParameter('callbackOptions', i, {});
|
|
1817
1810
|
const body = {
|
|
1818
1811
|
template: {
|
|
1819
1812
|
id: templateId,
|
|
1820
|
-
data:
|
|
1813
|
+
data: parseJSON(data, 'data'),
|
|
1821
1814
|
},
|
|
1822
1815
|
format,
|
|
1823
1816
|
output,
|
|
@@ -1827,7 +1820,7 @@ class PdfGeneratorApi {
|
|
|
1827
1820
|
url: callbackOptions.url,
|
|
1828
1821
|
};
|
|
1829
1822
|
if (callbackOptions.headers) {
|
|
1830
|
-
body.callback.headers =
|
|
1823
|
+
body.callback.headers = parseJSON(callbackOptions.headers, 'callbackOptions.headers');
|
|
1831
1824
|
}
|
|
1832
1825
|
}
|
|
1833
1826
|
if (additionalFields.outputName)
|
|
@@ -1846,13 +1839,13 @@ class PdfGeneratorApi {
|
|
|
1846
1839
|
else if (operation === 'generateBatch') {
|
|
1847
1840
|
const templates = this.getNodeParameter('templates', i);
|
|
1848
1841
|
const format = this.getNodeParameter('format', i, 'pdf');
|
|
1849
|
-
const output = this.getNodeParameter('
|
|
1842
|
+
const output = this.getNodeParameter('documentOutput', i, 'base64');
|
|
1850
1843
|
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
|
1851
1844
|
const templateArray = templates.templateList.map((template) => {
|
|
1852
1845
|
const templateId = typeof template.templateId === 'string' ? template.templateId : template.templateId.value;
|
|
1853
1846
|
return {
|
|
1854
1847
|
id: templateId,
|
|
1855
|
-
data:
|
|
1848
|
+
data: parseJSON(template.data, 'template.data'),
|
|
1856
1849
|
};
|
|
1857
1850
|
});
|
|
1858
1851
|
const body = {
|
|
@@ -1869,40 +1862,21 @@ class PdfGeneratorApi {
|
|
|
1869
1862
|
baseURL,
|
|
1870
1863
|
url: '/documents/generate/batch',
|
|
1871
1864
|
body,
|
|
1872
|
-
json:
|
|
1865
|
+
json: output !== 'file',
|
|
1866
|
+
encoding: output === 'file' ? null : 'utf8',
|
|
1873
1867
|
};
|
|
1874
1868
|
responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
|
|
1875
1869
|
if (responseData && output !== 'url') {
|
|
1876
1870
|
if (output === 'file') {
|
|
1877
|
-
let fileData = responseData.response || responseData.data || responseData;
|
|
1878
|
-
if (!fileData) {
|
|
1879
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `No file data received from API. Response structure: ${JSON.stringify(Object.keys(responseData))}`, { itemIndex: i });
|
|
1880
|
-
}
|
|
1881
1871
|
const binaryData = {};
|
|
1882
1872
|
const fileName = `${additionalFields.outputName || 'batch-documents'}.${format}`;
|
|
1883
|
-
|
|
1884
|
-
if (typeof fileData === 'string') {
|
|
1885
|
-
if (fileData.startsWith('data:')) {
|
|
1886
|
-
const base64Data = fileData.split(',')[1];
|
|
1887
|
-
binaryBuffer = Buffer.from(base64Data, 'base64');
|
|
1888
|
-
}
|
|
1889
|
-
else {
|
|
1890
|
-
binaryBuffer = Buffer.from(fileData, 'base64');
|
|
1891
|
-
}
|
|
1892
|
-
}
|
|
1893
|
-
else if (Buffer.isBuffer(fileData)) {
|
|
1894
|
-
binaryBuffer = fileData;
|
|
1895
|
-
}
|
|
1896
|
-
else {
|
|
1897
|
-
binaryBuffer = Buffer.from(fileData);
|
|
1898
|
-
}
|
|
1899
|
-
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));
|
|
1900
1874
|
returnData.push({
|
|
1901
1875
|
json: {
|
|
1902
1876
|
success: true,
|
|
1903
1877
|
filename: fileName,
|
|
1904
1878
|
format: output,
|
|
1905
|
-
|
|
1879
|
+
fileSize: responseData.length,
|
|
1906
1880
|
},
|
|
1907
1881
|
binary: binaryData,
|
|
1908
1882
|
});
|
|
@@ -1924,14 +1898,14 @@ class PdfGeneratorApi {
|
|
|
1924
1898
|
else if (operation === 'generateBatchAsync') {
|
|
1925
1899
|
const templates = this.getNodeParameter('templates', i);
|
|
1926
1900
|
const format = this.getNodeParameter('format', i, 'pdf');
|
|
1927
|
-
const output = this.getNodeParameter('
|
|
1901
|
+
const output = this.getNodeParameter('documentOutputAsync', i, 'base64');
|
|
1928
1902
|
const additionalFields = this.getNodeParameter('additionalFields', i, {});
|
|
1929
1903
|
const callbackOptions = this.getNodeParameter('callbackOptions', i, {});
|
|
1930
1904
|
const templateArray = templates.templateList.map((template) => {
|
|
1931
1905
|
const templateId = typeof template.templateId === 'string' ? template.templateId : template.templateId.value;
|
|
1932
1906
|
return {
|
|
1933
1907
|
id: templateId,
|
|
1934
|
-
data:
|
|
1908
|
+
data: parseJSON(template.data, 'template.data'),
|
|
1935
1909
|
};
|
|
1936
1910
|
});
|
|
1937
1911
|
const body = {
|
|
@@ -1944,7 +1918,7 @@ class PdfGeneratorApi {
|
|
|
1944
1918
|
url: callbackOptions.url,
|
|
1945
1919
|
};
|
|
1946
1920
|
if (callbackOptions.headers) {
|
|
1947
|
-
body.callback.headers =
|
|
1921
|
+
body.callback.headers = parseJSON(callbackOptions.headers, 'callbackOptions.headers');
|
|
1948
1922
|
}
|
|
1949
1923
|
}
|
|
1950
1924
|
if (additionalFields.outputName)
|
|
@@ -1963,18 +1937,18 @@ class PdfGeneratorApi {
|
|
|
1963
1937
|
}
|
|
1964
1938
|
else if (resource === 'template') {
|
|
1965
1939
|
if (operation === 'list') {
|
|
1966
|
-
const
|
|
1940
|
+
const templateListOptions = this.getNodeParameter('templateListOptions', i, {});
|
|
1967
1941
|
const qs = {};
|
|
1968
|
-
if (
|
|
1969
|
-
qs.name =
|
|
1970
|
-
if (
|
|
1971
|
-
qs.tags =
|
|
1972
|
-
if (
|
|
1973
|
-
qs.access =
|
|
1974
|
-
if (
|
|
1975
|
-
qs.page =
|
|
1976
|
-
if (
|
|
1977
|
-
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;
|
|
1978
1952
|
const options = {
|
|
1979
1953
|
method: 'GET',
|
|
1980
1954
|
baseURL,
|
|
@@ -1997,7 +1971,7 @@ class PdfGeneratorApi {
|
|
|
1997
1971
|
}
|
|
1998
1972
|
else if (operation === 'create') {
|
|
1999
1973
|
const templateConfiguration = this.getNodeParameter('templateConfiguration', i);
|
|
2000
|
-
const body =
|
|
1974
|
+
const body = parseJSON(templateConfiguration, 'templateConfiguration');
|
|
2001
1975
|
const options = {
|
|
2002
1976
|
method: 'POST',
|
|
2003
1977
|
baseURL,
|
|
@@ -2011,7 +1985,7 @@ class PdfGeneratorApi {
|
|
|
2011
1985
|
const templateIdParam = this.getNodeParameter('templateId', i);
|
|
2012
1986
|
const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
|
|
2013
1987
|
const templateConfiguration = this.getNodeParameter('templateConfiguration', i);
|
|
2014
|
-
const body =
|
|
1988
|
+
const body = parseJSON(templateConfiguration, 'templateConfiguration');
|
|
2015
1989
|
const options = {
|
|
2016
1990
|
method: 'PUT',
|
|
2017
1991
|
baseURL,
|
|
@@ -2039,7 +2013,7 @@ class PdfGeneratorApi {
|
|
|
2039
2013
|
}
|
|
2040
2014
|
else if (operation === 'validate') {
|
|
2041
2015
|
const templateConfig = this.getNodeParameter('templateConfig', i);
|
|
2042
|
-
const body =
|
|
2016
|
+
const body = parseJSON(templateConfig, 'templateConfig');
|
|
2043
2017
|
if (!body || typeof body !== 'object') {
|
|
2044
2018
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Template configuration must be a valid JSON object', { itemIndex: i });
|
|
2045
2019
|
}
|
|
@@ -2085,7 +2059,7 @@ class PdfGeneratorApi {
|
|
|
2085
2059
|
const editorOptions = this.getNodeParameter('editorOptions', i, {});
|
|
2086
2060
|
const body = {};
|
|
2087
2061
|
if (editorOptions.data)
|
|
2088
|
-
body.data =
|
|
2062
|
+
body.data = parseJSON(editorOptions.data, 'editorOptions.data');
|
|
2089
2063
|
if (editorOptions.language)
|
|
2090
2064
|
body.language = editorOptions.language;
|
|
2091
2065
|
const options = {
|
|
@@ -2101,6 +2075,7 @@ class PdfGeneratorApi {
|
|
|
2101
2075
|
else if (resource === 'pdfServices') {
|
|
2102
2076
|
const pdfSource = this.getNodeParameter('pdfSource', i);
|
|
2103
2077
|
const outputFormat = this.getNodeParameter('outputFormat', i, 'base64');
|
|
2078
|
+
let optimizationStats = null;
|
|
2104
2079
|
const body = {};
|
|
2105
2080
|
if (pdfSource === 'url') {
|
|
2106
2081
|
body.file_url = this.getNodeParameter('fileUrl', i);
|
|
@@ -2205,13 +2180,7 @@ class PdfGeneratorApi {
|
|
|
2205
2180
|
}
|
|
2206
2181
|
else if (operation === 'fillFormFields') {
|
|
2207
2182
|
const formFieldsData = this.getNodeParameter('formFieldsData', i);
|
|
2208
|
-
|
|
2209
|
-
try {
|
|
2210
|
-
parsedData = typeof formFieldsData === 'string' ? JSON.parse(formFieldsData) : formFieldsData;
|
|
2211
|
-
}
|
|
2212
|
-
catch (error) {
|
|
2213
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Form Fields Data must be valid JSON');
|
|
2214
|
-
}
|
|
2183
|
+
const parsedData = parseJSON(formFieldsData, 'Form Fields Data');
|
|
2215
2184
|
body.data = parsedData;
|
|
2216
2185
|
const options = {
|
|
2217
2186
|
method: 'POST',
|
|
@@ -2238,7 +2207,7 @@ class PdfGeneratorApi {
|
|
|
2238
2207
|
const headers = fullResponse.headers || {};
|
|
2239
2208
|
const originalSize = headers['x-original-size'] ? parseInt(headers['x-original-size'], 10) : null;
|
|
2240
2209
|
const optimizedSize = headers['x-optimized-size'] ? parseInt(headers['x-optimized-size'], 10) : null;
|
|
2241
|
-
|
|
2210
|
+
optimizationStats = {
|
|
2242
2211
|
originalSize,
|
|
2243
2212
|
optimizedSize,
|
|
2244
2213
|
compressionRatio: originalSize && optimizedSize ? ((originalSize - optimizedSize) / originalSize * 100) : null
|
|
@@ -2257,22 +2226,20 @@ class PdfGeneratorApi {
|
|
|
2257
2226
|
else if (outputFormat === 'file') {
|
|
2258
2227
|
const binaryData = {};
|
|
2259
2228
|
const fileName = `processed-document.pdf`;
|
|
2260
|
-
|
|
2261
|
-
binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, 'application/pdf');
|
|
2229
|
+
binaryData[fileName] = await this.helpers.prepareBinaryData(responseData, fileName, 'application/pdf');
|
|
2262
2230
|
const jsonResponse = {
|
|
2263
2231
|
success: true,
|
|
2264
2232
|
operation,
|
|
2265
2233
|
filename: fileName,
|
|
2266
2234
|
format: outputFormat,
|
|
2267
|
-
fileSize:
|
|
2235
|
+
fileSize: responseData.length,
|
|
2268
2236
|
};
|
|
2269
|
-
if (operation === 'optimize' &&
|
|
2270
|
-
const stats = responseData.__optimizationStats;
|
|
2237
|
+
if (operation === 'optimize' && optimizationStats) {
|
|
2271
2238
|
jsonResponse.optimizationStats = {
|
|
2272
|
-
originalSize:
|
|
2273
|
-
optimizedSize:
|
|
2274
|
-
savedBytes:
|
|
2275
|
-
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
|
|
2276
2243
|
};
|
|
2277
2244
|
}
|
|
2278
2245
|
returnData.push({
|
|
@@ -2287,15 +2254,13 @@ class PdfGeneratorApi {
|
|
|
2287
2254
|
format: outputFormat,
|
|
2288
2255
|
...responseData,
|
|
2289
2256
|
};
|
|
2290
|
-
if (operation === 'optimize' &&
|
|
2291
|
-
const stats = responseData.__optimizationStats;
|
|
2257
|
+
if (operation === 'optimize' && optimizationStats) {
|
|
2292
2258
|
jsonResponse.optimizationStats = {
|
|
2293
|
-
originalSize:
|
|
2294
|
-
optimizedSize:
|
|
2295
|
-
savedBytes:
|
|
2296
|
-
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
|
|
2297
2263
|
};
|
|
2298
|
-
delete jsonResponse.__optimizationStats;
|
|
2299
2264
|
}
|
|
2300
2265
|
returnData.push({
|
|
2301
2266
|
json: jsonResponse,
|
|
@@ -2306,12 +2271,12 @@ class PdfGeneratorApi {
|
|
|
2306
2271
|
}
|
|
2307
2272
|
else if (resource === 'workspace') {
|
|
2308
2273
|
if (operation === 'list') {
|
|
2309
|
-
const
|
|
2274
|
+
const workspaceListOptions = this.getNodeParameter('workspaceListOptions', i, {});
|
|
2310
2275
|
const qs = {};
|
|
2311
|
-
if (
|
|
2312
|
-
qs.page =
|
|
2313
|
-
if (
|
|
2314
|
-
qs.per_page =
|
|
2276
|
+
if (workspaceListOptions.page)
|
|
2277
|
+
qs.page = workspaceListOptions.page;
|
|
2278
|
+
if (workspaceListOptions.per_page)
|
|
2279
|
+
qs.per_page = workspaceListOptions.per_page;
|
|
2315
2280
|
const options = {
|
|
2316
2281
|
method: 'GET',
|
|
2317
2282
|
baseURL,
|