@pdfgeneratorapi/n8n-nodes-pdf-generator-api 0.2.6 → 0.4.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.
@@ -37,6 +37,11 @@ class PdfGeneratorApi {
37
37
  type: 'options',
38
38
  noDataExpression: true,
39
39
  options: [
40
+ {
41
+ name: 'Asset',
42
+ value: 'asset',
43
+ description: 'Generate QR codes and other assets for use in documents',
44
+ },
40
45
  {
41
46
  name: 'Conversion',
42
47
  value: 'conversion',
@@ -67,8 +72,28 @@ class PdfGeneratorApi {
67
72
  description: 'Choose the type of PDF operation: generate documents from templates, convert HTML/URLs, process existing PDFs, or manage templates and workspaces',
68
73
  },
69
74
  {
70
- displayName: 'Operation',
71
- name: 'conversionOperation',
75
+ displayName: 'Asset Operations',
76
+ name: 'operation',
77
+ type: 'options',
78
+ noDataExpression: true,
79
+ displayOptions: {
80
+ show: {
81
+ resource: ['asset'],
82
+ },
83
+ },
84
+ options: [
85
+ {
86
+ name: 'Generate QR Code',
87
+ value: 'generateQRCode',
88
+ description: 'Generate a QR code image',
89
+ action: 'Generate a QR code image',
90
+ },
91
+ ],
92
+ default: 'generateQRCode',
93
+ },
94
+ {
95
+ displayName: 'Conversion Operations',
96
+ name: 'operation',
72
97
  type: 'options',
73
98
  noDataExpression: true,
74
99
  displayOptions: {
@@ -93,8 +118,8 @@ class PdfGeneratorApi {
93
118
  default: 'htmlToPdf',
94
119
  },
95
120
  {
96
- displayName: 'Operation',
97
- name: 'documentOperation',
121
+ displayName: 'Document Operations',
122
+ name: 'operation',
98
123
  type: 'options',
99
124
  noDataExpression: true,
100
125
  displayOptions: {
@@ -149,8 +174,8 @@ class PdfGeneratorApi {
149
174
  default: 'generate',
150
175
  },
151
176
  {
152
- displayName: 'Operation',
153
- name: 'pdfServicesOperation',
177
+ displayName: 'Services Operations',
178
+ name: 'operation',
154
179
  type: 'options',
155
180
  noDataExpression: true,
156
181
  displayOptions: {
@@ -304,7 +329,7 @@ class PdfGeneratorApi {
304
329
  displayOptions: {
305
330
  show: {
306
331
  resource: ['pdfServices'],
307
- pdfServicesOperation: ['addWatermark'],
332
+ operation: ['addWatermark'],
308
333
  },
309
334
  },
310
335
  description: 'Type of watermark to add (can select both text and image)',
@@ -316,7 +341,7 @@ class PdfGeneratorApi {
316
341
  displayOptions: {
317
342
  show: {
318
343
  resource: ['pdfServices'],
319
- pdfServicesOperation: ['addWatermark'],
344
+ operation: ['addWatermark'],
320
345
  watermarkType: ['text'],
321
346
  },
322
347
  },
@@ -331,7 +356,7 @@ class PdfGeneratorApi {
331
356
  displayOptions: {
332
357
  show: {
333
358
  resource: ['pdfServices'],
334
- pdfServicesOperation: ['addWatermark'],
359
+ operation: ['addWatermark'],
335
360
  watermarkType: ['image'],
336
361
  },
337
362
  },
@@ -348,7 +373,7 @@ class PdfGeneratorApi {
348
373
  displayOptions: {
349
374
  show: {
350
375
  resource: ['pdfServices'],
351
- pdfServicesOperation: ['addWatermark'],
376
+ operation: ['addWatermark'],
352
377
  watermarkType: ['text'],
353
378
  },
354
379
  },
@@ -451,7 +476,7 @@ class PdfGeneratorApi {
451
476
  displayOptions: {
452
477
  show: {
453
478
  resource: ['pdfServices'],
454
- pdfServicesOperation: ['addWatermark'],
479
+ operation: ['addWatermark'],
455
480
  watermarkType: ['image'],
456
481
  },
457
482
  },
@@ -537,7 +562,7 @@ class PdfGeneratorApi {
537
562
  displayOptions: {
538
563
  show: {
539
564
  resource: ['pdfServices'],
540
- pdfServicesOperation: ['encrypt'],
565
+ operation: ['encrypt'],
541
566
  },
542
567
  },
543
568
  default: '',
@@ -554,7 +579,7 @@ class PdfGeneratorApi {
554
579
  displayOptions: {
555
580
  show: {
556
581
  resource: ['pdfServices'],
557
- pdfServicesOperation: ['encrypt'],
582
+ operation: ['encrypt'],
558
583
  },
559
584
  },
560
585
  default: '',
@@ -572,7 +597,7 @@ class PdfGeneratorApi {
572
597
  displayOptions: {
573
598
  show: {
574
599
  resource: ['pdfServices'],
575
- pdfServicesOperation: ['decrypt'],
600
+ operation: ['decrypt'],
576
601
  },
577
602
  },
578
603
  default: '',
@@ -587,7 +612,7 @@ class PdfGeneratorApi {
587
612
  displayOptions: {
588
613
  show: {
589
614
  resource: ['pdfServices'],
590
- pdfServicesOperation: ['fillFormFields'],
615
+ operation: ['fillFormFields'],
591
616
  },
592
617
  },
593
618
  default: '{}',
@@ -602,7 +627,7 @@ class PdfGeneratorApi {
602
627
  displayOptions: {
603
628
  show: {
604
629
  resource: ['document'],
605
- documentOperation: ['get', 'delete'],
630
+ operation: ['get', 'delete'],
606
631
  },
607
632
  },
608
633
  default: '',
@@ -610,14 +635,14 @@ class PdfGeneratorApi {
610
635
  },
611
636
  {
612
637
  displayName: 'List Options',
613
- name: 'listOptions',
638
+ name: 'documentListOptions',
614
639
  type: 'collection',
615
640
  placeholder: 'Add Option',
616
641
  default: {},
617
642
  displayOptions: {
618
643
  show: {
619
644
  resource: ['document'],
620
- documentOperation: ['list'],
645
+ operation: ['list'],
621
646
  },
622
647
  },
623
648
  options: [
@@ -673,7 +698,7 @@ class PdfGeneratorApi {
673
698
  displayOptions: {
674
699
  show: {
675
700
  resource: ['document'],
676
- documentOperation: ['generateBatch', 'generateBatchAsync'],
701
+ operation: ['generateBatch', 'generateBatchAsync'],
677
702
  },
678
703
  },
679
704
  default: { templateList: [{}] },
@@ -740,7 +765,7 @@ class PdfGeneratorApi {
740
765
  displayOptions: {
741
766
  show: {
742
767
  resource: ['document'],
743
- documentOperation: ['generateAsync', 'generateBatchAsync'],
768
+ operation: ['generateAsync', 'generateBatchAsync'],
744
769
  },
745
770
  },
746
771
  options: [
@@ -801,6 +826,12 @@ class PdfGeneratorApi {
801
826
  description: 'Get template data fields',
802
827
  action: 'Get template data fields',
803
828
  },
829
+ {
830
+ name: 'Get Template Schema',
831
+ value: 'getTemplateSchema',
832
+ description: 'Get template JSON schema',
833
+ action: 'Get template JSON schema',
834
+ },
804
835
  {
805
836
  name: 'List',
806
837
  value: 'list',
@@ -837,7 +868,7 @@ class PdfGeneratorApi {
837
868
  displayOptions: {
838
869
  show: {
839
870
  resource: ['document'],
840
- documentOperation: ['generate', 'generateAsync'],
871
+ operation: ['generate', 'generateAsync'],
841
872
  },
842
873
  },
843
874
  modes: [
@@ -920,7 +951,7 @@ class PdfGeneratorApi {
920
951
  displayOptions: {
921
952
  show: {
922
953
  resource: ['document'],
923
- documentOperation: ['getOutput'],
954
+ operation: ['getOutput'],
924
955
  },
925
956
  },
926
957
  default: '',
@@ -934,7 +965,7 @@ class PdfGeneratorApi {
934
965
  displayOptions: {
935
966
  show: {
936
967
  resource: ['document'],
937
- documentOperation: ['generate', 'generateAsync'],
968
+ operation: ['generate', 'generateAsync'],
938
969
  },
939
970
  },
940
971
  default: '{}',
@@ -947,7 +978,7 @@ class PdfGeneratorApi {
947
978
  displayOptions: {
948
979
  show: {
949
980
  resource: ['document'],
950
- documentOperation: ['generate', 'generateAsync', 'generateBatch', 'generateBatchAsync'],
981
+ operation: ['generate', 'generateAsync', 'generateBatch', 'generateBatchAsync'],
951
982
  },
952
983
  },
953
984
  options: [
@@ -959,26 +990,18 @@ class PdfGeneratorApi {
959
990
  name: 'HTML',
960
991
  value: 'html',
961
992
  },
962
- {
963
- name: 'ZIP',
964
- value: 'zip',
965
- },
966
- {
967
- name: 'XLSX',
968
- value: 'xlsx',
969
- },
970
993
  ],
971
994
  default: 'pdf',
972
- description: 'Document format. ZIP option returns a ZIP file with PDF files.',
995
+ description: 'Document format',
973
996
  },
974
997
  {
975
998
  displayName: 'Output',
976
- name: 'output',
999
+ name: 'documentOutput',
977
1000
  type: 'options',
978
1001
  displayOptions: {
979
1002
  show: {
980
1003
  resource: ['document'],
981
- documentOperation: ['generate', 'generateBatch'],
1004
+ operation: ['generate', 'generateBatch'],
982
1005
  },
983
1006
  },
984
1007
  options: [
@@ -994,18 +1017,22 @@ class PdfGeneratorApi {
994
1017
  name: 'URL',
995
1018
  value: 'url',
996
1019
  },
1020
+ {
1021
+ name: 'Viewer',
1022
+ value: 'viewer',
1023
+ },
997
1024
  ],
998
1025
  default: 'base64',
999
- description: 'Response format. File option returns the file inline. URL option stores document for 30 days.',
1026
+ description: 'Response format. File returns inline. URL and Viewer store document for 30 days.',
1000
1027
  },
1001
1028
  {
1002
1029
  displayName: 'Output',
1003
- name: 'output',
1030
+ name: 'documentOutputAsync',
1004
1031
  type: 'options',
1005
1032
  displayOptions: {
1006
1033
  show: {
1007
1034
  resource: ['document'],
1008
- documentOperation: ['generateAsync', 'generateBatchAsync'],
1035
+ operation: ['generateAsync', 'generateBatchAsync'],
1009
1036
  },
1010
1037
  },
1011
1038
  options: [
@@ -1017,9 +1044,13 @@ class PdfGeneratorApi {
1017
1044
  name: 'URL',
1018
1045
  value: 'url',
1019
1046
  },
1047
+ {
1048
+ name: 'Viewer',
1049
+ value: 'viewer',
1050
+ },
1020
1051
  ],
1021
1052
  default: 'base64',
1022
- description: 'Response format. URL option stores document for 30 days.',
1053
+ description: 'Response format. File returns inline. URL and Viewer store document for 30 days.',
1023
1054
  },
1024
1055
  {
1025
1056
  displayName: 'Additional Fields',
@@ -1030,7 +1061,7 @@ class PdfGeneratorApi {
1030
1061
  displayOptions: {
1031
1062
  show: {
1032
1063
  resource: ['document'],
1033
- documentOperation: ['generate', 'generateAsync', 'generateBatch', 'generateBatchAsync'],
1064
+ operation: ['generate', 'generateAsync', 'generateBatch', 'generateBatchAsync'],
1034
1065
  },
1035
1066
  },
1036
1067
  options: [
@@ -1130,7 +1161,7 @@ class PdfGeneratorApi {
1130
1161
  },
1131
1162
  {
1132
1163
  displayName: 'List Options',
1133
- name: 'listOptions',
1164
+ name: 'templateListOptions',
1134
1165
  type: 'collection',
1135
1166
  placeholder: 'Add Option',
1136
1167
  default: {},
@@ -1184,7 +1215,7 @@ class PdfGeneratorApi {
1184
1215
  ],
1185
1216
  },
1186
1217
  {
1187
- displayName: 'Operation',
1218
+ displayName: 'Workspace Operations',
1188
1219
  name: 'operation',
1189
1220
  type: 'options',
1190
1221
  noDataExpression: true,
@@ -1223,7 +1254,7 @@ class PdfGeneratorApi {
1223
1254
  },
1224
1255
  {
1225
1256
  displayName: 'List Options',
1226
- name: 'listOptions',
1257
+ name: 'workspaceListOptions',
1227
1258
  type: 'collection',
1228
1259
  placeholder: 'Add Option',
1229
1260
  default: {},
@@ -1285,6 +1316,129 @@ class PdfGeneratorApi {
1285
1316
  default: '',
1286
1317
  description: 'A unique identifier for the new workspace',
1287
1318
  },
1319
+ {
1320
+ displayName: 'Content',
1321
+ name: 'qrContent',
1322
+ type: 'string',
1323
+ required: true,
1324
+ displayOptions: {
1325
+ show: {
1326
+ resource: ['asset'],
1327
+ operation: ['generateQRCode'],
1328
+ },
1329
+ },
1330
+ default: '',
1331
+ description: 'The content to encode in the QR code (URL, text, etc.)',
1332
+ placeholder: 'https://example.com',
1333
+ },
1334
+ {
1335
+ displayName: 'Output Format',
1336
+ name: 'qrOutputFormat',
1337
+ type: 'options',
1338
+ options: [
1339
+ {
1340
+ name: 'Base64 (JSON)',
1341
+ value: 'base64',
1342
+ description: 'Returns JSON response with base64 encoded PNG image',
1343
+ },
1344
+ {
1345
+ name: 'File (Binary)',
1346
+ value: 'file',
1347
+ description: 'Returns binary PNG image file data',
1348
+ },
1349
+ ],
1350
+ default: 'base64',
1351
+ displayOptions: {
1352
+ show: {
1353
+ resource: ['asset'],
1354
+ operation: ['generateQRCode'],
1355
+ },
1356
+ },
1357
+ description: 'Choose output format for the QR code',
1358
+ },
1359
+ {
1360
+ displayName: 'Logo Source',
1361
+ name: 'logoSource',
1362
+ type: 'options',
1363
+ options: [
1364
+ {
1365
+ name: 'None',
1366
+ value: 'none',
1367
+ },
1368
+ {
1369
+ name: 'From URL',
1370
+ value: 'url',
1371
+ },
1372
+ {
1373
+ name: 'From Base64',
1374
+ value: 'base64',
1375
+ },
1376
+ ],
1377
+ default: 'none',
1378
+ displayOptions: {
1379
+ show: {
1380
+ resource: ['asset'],
1381
+ operation: ['generateQRCode'],
1382
+ },
1383
+ },
1384
+ description: 'Add a logo to the QR code',
1385
+ },
1386
+ {
1387
+ displayName: 'Logo URL',
1388
+ name: 'logo_url',
1389
+ type: 'string',
1390
+ displayOptions: {
1391
+ show: {
1392
+ resource: ['asset'],
1393
+ operation: ['generateQRCode'],
1394
+ logoSource: ['url'],
1395
+ },
1396
+ },
1397
+ default: '',
1398
+ description: 'Logo URL to an image to add on the QR code',
1399
+ placeholder: 'https://example.com/logo.png',
1400
+ },
1401
+ {
1402
+ displayName: 'Logo Base64',
1403
+ name: 'logo_base64',
1404
+ type: 'string',
1405
+ typeOptions: {
1406
+ rows: 4,
1407
+ },
1408
+ displayOptions: {
1409
+ show: {
1410
+ resource: ['asset'],
1411
+ operation: ['generateQRCode'],
1412
+ logoSource: ['base64'],
1413
+ },
1414
+ },
1415
+ default: '',
1416
+ description: 'Logo as a base64 image string to add on the QR code',
1417
+ placeholder: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB...',
1418
+ },
1419
+ {
1420
+ displayName: 'Additional Options',
1421
+ name: 'qrCodeOptions',
1422
+ type: 'collection',
1423
+ placeholder: 'Add Option',
1424
+ default: {},
1425
+ displayOptions: {
1426
+ show: {
1427
+ resource: ['asset'],
1428
+ operation: ['generateQRCode'],
1429
+ },
1430
+ },
1431
+ description: 'Additional options for QR code generation',
1432
+ options: [
1433
+ {
1434
+ displayName: 'Color',
1435
+ name: 'color',
1436
+ type: 'color',
1437
+ default: '#000000',
1438
+ description: 'QR code color in hexadecimal format',
1439
+ },
1440
+ ],
1441
+ },
1288
1442
  {
1289
1443
  displayName: 'HTML Content',
1290
1444
  name: 'htmlContent',
@@ -1305,7 +1459,7 @@ class PdfGeneratorApi {
1305
1459
  displayOptions: {
1306
1460
  show: {
1307
1461
  resource: ['conversion'],
1308
- conversionOperation: ['htmlToPdf'],
1462
+ operation: ['htmlToPdf'],
1309
1463
  },
1310
1464
  },
1311
1465
  default: `<!DOCTYPE html>
@@ -1414,7 +1568,7 @@ class PdfGeneratorApi {
1414
1568
  displayOptions: {
1415
1569
  show: {
1416
1570
  resource: ['conversion'],
1417
- conversionOperation: ['urlToPdf'],
1571
+ operation: ['urlToPdf'],
1418
1572
  },
1419
1573
  },
1420
1574
  default: '',
@@ -1525,7 +1679,7 @@ class PdfGeneratorApi {
1525
1679
  },
1526
1680
  {
1527
1681
  displayName: 'Output Format',
1528
- name: 'output',
1682
+ name: 'conversionOutput',
1529
1683
  type: 'options',
1530
1684
  options: [
1531
1685
  {
@@ -1593,28 +1747,93 @@ class PdfGeneratorApi {
1593
1747
  const items = this.getInputData();
1594
1748
  const returnData = [];
1595
1749
  const resource = this.getNodeParameter('resource', 0);
1596
- let operation;
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
- }
1750
+ const operation = this.getNodeParameter('operation', 0);
1612
1751
  const credentials = await this.getCredentials('pdfGeneratorApi');
1613
1752
  const baseURL = credentials.baseUrl || 'https://us1.pdfgeneratorapi.com/api/v4';
1753
+ const parseJSON = (value, field) => {
1754
+ try {
1755
+ return typeof value === 'string' ? JSON.parse(value) : value;
1756
+ }
1757
+ catch (error) {
1758
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${field} must be valid JSON`);
1759
+ }
1760
+ };
1761
+ const getMimeType = (format) => {
1762
+ switch (format) {
1763
+ case 'pdf':
1764
+ return 'application/pdf';
1765
+ case 'html':
1766
+ return 'text/html';
1767
+ default:
1768
+ return 'application/octet-stream';
1769
+ }
1770
+ };
1614
1771
  for (let i = 0; i < items.length; i++) {
1615
1772
  try {
1616
1773
  let responseData;
1617
- if (resource === 'conversion') {
1774
+ if (resource === 'asset') {
1775
+ if (operation === 'generateQRCode') {
1776
+ const qrContent = this.getNodeParameter('qrContent', i);
1777
+ const qrOutputFormat = this.getNodeParameter('qrOutputFormat', i, 'base64');
1778
+ const logoSource = this.getNodeParameter('logoSource', i, 'none');
1779
+ const qrCodeOptions = this.getNodeParameter('qrCodeOptions', i, {});
1780
+ if (!qrContent || qrContent.trim() === '') {
1781
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Content is required for QR code generation', { itemIndex: i });
1782
+ }
1783
+ const body = {
1784
+ content: qrContent,
1785
+ output: qrOutputFormat,
1786
+ };
1787
+ if (qrCodeOptions.color)
1788
+ body.color = qrCodeOptions.color;
1789
+ if (logoSource === 'base64') {
1790
+ const logoBase64 = this.getNodeParameter('logo_base64', i, '');
1791
+ if (logoBase64)
1792
+ body.logo_base64 = logoBase64;
1793
+ }
1794
+ else if (logoSource === 'url') {
1795
+ const logoUrl = this.getNodeParameter('logo_url', i, '');
1796
+ if (logoUrl)
1797
+ body.logo_url = logoUrl;
1798
+ }
1799
+ const options = {
1800
+ method: 'POST',
1801
+ baseURL,
1802
+ url: '/assets/qrcode',
1803
+ body,
1804
+ json: qrOutputFormat !== 'file',
1805
+ encoding: qrOutputFormat === 'file' ? null : 'utf8',
1806
+ };
1807
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1808
+ if (responseData) {
1809
+ if (qrOutputFormat === 'file') {
1810
+ const binaryData = {};
1811
+ const fileName = 'qrcode.png';
1812
+ binaryData[fileName] = await this.helpers.prepareBinaryData(responseData, fileName, 'image/png');
1813
+ returnData.push({
1814
+ json: {
1815
+ success: true,
1816
+ filename: fileName,
1817
+ format: qrOutputFormat,
1818
+ fileSize: responseData.length,
1819
+ },
1820
+ binary: binaryData,
1821
+ });
1822
+ }
1823
+ else {
1824
+ returnData.push({
1825
+ json: {
1826
+ success: true,
1827
+ format: qrOutputFormat,
1828
+ ...responseData,
1829
+ },
1830
+ });
1831
+ }
1832
+ continue;
1833
+ }
1834
+ }
1835
+ }
1836
+ else if (resource === 'conversion') {
1618
1837
  const conversionOptions = this.getNodeParameter('conversionOptions', i, {});
1619
1838
  const filename = this.getNodeParameter('filename', i);
1620
1839
  if (!filename || filename.trim() === '') {
@@ -1641,7 +1860,7 @@ class PdfGeneratorApi {
1641
1860
  const body = {
1642
1861
  paper_size: conversionOptions.paper_size || 'a4',
1643
1862
  orientation: conversionOptions.orientation || 'portrait',
1644
- output: conversionOptions.output || 'base64',
1863
+ output: conversionOptions.conversionOutput || 'base64',
1645
1864
  filename: filename || 'document',
1646
1865
  };
1647
1866
  if (operation === 'htmlToPdf') {
@@ -1675,14 +1894,13 @@ class PdfGeneratorApi {
1675
1894
  if (outputFormat === 'file') {
1676
1895
  const binaryData = {};
1677
1896
  const fileName = `${filename}.pdf`;
1678
- const binaryBuffer = Buffer.isBuffer(responseData) ? responseData : Buffer.from(responseData);
1679
- binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, 'application/pdf');
1897
+ binaryData[fileName] = await this.helpers.prepareBinaryData(responseData, fileName, 'application/pdf');
1680
1898
  returnData.push({
1681
1899
  json: {
1682
1900
  success: true,
1683
1901
  filename: `${filename}.pdf`,
1684
1902
  format: outputFormat,
1685
- fileSize: binaryBuffer.length,
1903
+ fileSize: responseData.length,
1686
1904
  },
1687
1905
  binary: binaryData,
1688
1906
  });
@@ -1702,18 +1920,18 @@ class PdfGeneratorApi {
1702
1920
  }
1703
1921
  else if (resource === 'document') {
1704
1922
  if (operation === 'list') {
1705
- const listOptions = this.getNodeParameter('listOptions', i, {});
1923
+ const documentListOptions = this.getNodeParameter('documentListOptions', i, {});
1706
1924
  const qs = {};
1707
- if (listOptions.template_id)
1708
- qs.template_id = listOptions.template_id;
1709
- if (listOptions.start_date)
1710
- qs.start_date = listOptions.start_date;
1711
- if (listOptions.end_date)
1712
- qs.end_date = listOptions.end_date;
1713
- if (listOptions.page)
1714
- qs.page = listOptions.page;
1715
- if (listOptions.per_page)
1716
- qs.per_page = listOptions.per_page;
1925
+ if (documentListOptions.template_id)
1926
+ qs.template_id = documentListOptions.template_id;
1927
+ if (documentListOptions.start_date)
1928
+ qs.start_date = documentListOptions.start_date;
1929
+ if (documentListOptions.end_date)
1930
+ qs.end_date = documentListOptions.end_date;
1931
+ if (documentListOptions.page)
1932
+ qs.page = documentListOptions.page;
1933
+ if (documentListOptions.per_page)
1934
+ qs.per_page = documentListOptions.per_page;
1717
1935
  const options = {
1718
1936
  method: 'GET',
1719
1937
  baseURL,
@@ -1753,12 +1971,12 @@ class PdfGeneratorApi {
1753
1971
  const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
1754
1972
  const data = this.getNodeParameter('data', i);
1755
1973
  const format = this.getNodeParameter('format', i, 'pdf');
1756
- const output = this.getNodeParameter('output', i, 'base64');
1974
+ const output = this.getNodeParameter('documentOutput', i, 'base64');
1757
1975
  const additionalFields = this.getNodeParameter('additionalFields', i, {});
1758
1976
  const body = {
1759
1977
  template: {
1760
1978
  id: templateId,
1761
- data: JSON.parse(data),
1979
+ data: parseJSON(data, 'data'),
1762
1980
  },
1763
1981
  format,
1764
1982
  output,
@@ -1776,18 +1994,17 @@ class PdfGeneratorApi {
1776
1994
  encoding: output === 'file' ? null : 'utf8',
1777
1995
  };
1778
1996
  responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1779
- if (responseData && output !== 'url') {
1997
+ if (responseData && output !== 'url' && output !== 'viewer') {
1780
1998
  if (output === 'file') {
1781
1999
  const binaryData = {};
1782
2000
  const fileName = `${additionalFields.outputName || 'document'}.${format}`;
1783
- const binaryBuffer = Buffer.isBuffer(responseData) ? responseData : Buffer.from(responseData);
1784
- binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, format === 'pdf' ? 'application/pdf' : `application/${format}`);
2001
+ binaryData[fileName] = await this.helpers.prepareBinaryData(responseData, fileName, getMimeType(format));
1785
2002
  returnData.push({
1786
2003
  json: {
1787
2004
  success: true,
1788
2005
  filename: fileName,
1789
2006
  format: output,
1790
- fileSize: binaryBuffer.length,
2007
+ fileSize: responseData.length,
1791
2008
  },
1792
2009
  binary: binaryData,
1793
2010
  });
@@ -1811,13 +2028,13 @@ class PdfGeneratorApi {
1811
2028
  const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
1812
2029
  const data = this.getNodeParameter('data', i);
1813
2030
  const format = this.getNodeParameter('format', i, 'pdf');
1814
- const output = this.getNodeParameter('output', i, 'base64');
2031
+ const output = this.getNodeParameter('documentOutputAsync', i, 'base64');
1815
2032
  const additionalFields = this.getNodeParameter('additionalFields', i, {});
1816
2033
  const callbackOptions = this.getNodeParameter('callbackOptions', i, {});
1817
2034
  const body = {
1818
2035
  template: {
1819
2036
  id: templateId,
1820
- data: JSON.parse(data),
2037
+ data: parseJSON(data, 'data'),
1821
2038
  },
1822
2039
  format,
1823
2040
  output,
@@ -1827,7 +2044,7 @@ class PdfGeneratorApi {
1827
2044
  url: callbackOptions.url,
1828
2045
  };
1829
2046
  if (callbackOptions.headers) {
1830
- body.callback.headers = JSON.parse(callbackOptions.headers);
2047
+ body.callback.headers = parseJSON(callbackOptions.headers, 'callbackOptions.headers');
1831
2048
  }
1832
2049
  }
1833
2050
  if (additionalFields.outputName)
@@ -1846,13 +2063,13 @@ class PdfGeneratorApi {
1846
2063
  else if (operation === 'generateBatch') {
1847
2064
  const templates = this.getNodeParameter('templates', i);
1848
2065
  const format = this.getNodeParameter('format', i, 'pdf');
1849
- const output = this.getNodeParameter('output', i, 'base64');
2066
+ const output = this.getNodeParameter('documentOutput', i, 'base64');
1850
2067
  const additionalFields = this.getNodeParameter('additionalFields', i, {});
1851
2068
  const templateArray = templates.templateList.map((template) => {
1852
2069
  const templateId = typeof template.templateId === 'string' ? template.templateId : template.templateId.value;
1853
2070
  return {
1854
2071
  id: templateId,
1855
- data: JSON.parse(template.data),
2072
+ data: parseJSON(template.data, 'template.data'),
1856
2073
  };
1857
2074
  });
1858
2075
  const body = {
@@ -1869,40 +2086,21 @@ class PdfGeneratorApi {
1869
2086
  baseURL,
1870
2087
  url: '/documents/generate/batch',
1871
2088
  body,
1872
- json: true,
2089
+ json: output !== 'file',
2090
+ encoding: output === 'file' ? null : 'utf8',
1873
2091
  };
1874
2092
  responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1875
- if (responseData && output !== 'url') {
2093
+ if (responseData && output !== 'url' && output !== 'viewer') {
1876
2094
  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
2095
  const binaryData = {};
1882
2096
  const fileName = `${additionalFields.outputName || 'batch-documents'}.${format}`;
1883
- let binaryBuffer;
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}`);
2097
+ binaryData[fileName] = await this.helpers.prepareBinaryData(responseData, fileName, getMimeType(format));
1900
2098
  returnData.push({
1901
2099
  json: {
1902
2100
  success: true,
1903
2101
  filename: fileName,
1904
2102
  format: output,
1905
- ...responseData.meta,
2103
+ fileSize: responseData.length,
1906
2104
  },
1907
2105
  binary: binaryData,
1908
2106
  });
@@ -1924,14 +2122,14 @@ class PdfGeneratorApi {
1924
2122
  else if (operation === 'generateBatchAsync') {
1925
2123
  const templates = this.getNodeParameter('templates', i);
1926
2124
  const format = this.getNodeParameter('format', i, 'pdf');
1927
- const output = this.getNodeParameter('output', i, 'base64');
2125
+ const output = this.getNodeParameter('documentOutputAsync', i, 'base64');
1928
2126
  const additionalFields = this.getNodeParameter('additionalFields', i, {});
1929
2127
  const callbackOptions = this.getNodeParameter('callbackOptions', i, {});
1930
2128
  const templateArray = templates.templateList.map((template) => {
1931
2129
  const templateId = typeof template.templateId === 'string' ? template.templateId : template.templateId.value;
1932
2130
  return {
1933
2131
  id: templateId,
1934
- data: JSON.parse(template.data),
2132
+ data: parseJSON(template.data, 'template.data'),
1935
2133
  };
1936
2134
  });
1937
2135
  const body = {
@@ -1944,7 +2142,7 @@ class PdfGeneratorApi {
1944
2142
  url: callbackOptions.url,
1945
2143
  };
1946
2144
  if (callbackOptions.headers) {
1947
- body.callback.headers = JSON.parse(callbackOptions.headers);
2145
+ body.callback.headers = parseJSON(callbackOptions.headers, 'callbackOptions.headers');
1948
2146
  }
1949
2147
  }
1950
2148
  if (additionalFields.outputName)
@@ -1963,18 +2161,18 @@ class PdfGeneratorApi {
1963
2161
  }
1964
2162
  else if (resource === 'template') {
1965
2163
  if (operation === 'list') {
1966
- const listOptions = this.getNodeParameter('listOptions', i, {});
2164
+ const templateListOptions = this.getNodeParameter('templateListOptions', i, {});
1967
2165
  const qs = {};
1968
- if (listOptions.name)
1969
- qs.name = listOptions.name;
1970
- if (listOptions.tags)
1971
- qs.tags = listOptions.tags;
1972
- if (listOptions.access)
1973
- qs.access = listOptions.access;
1974
- if (listOptions.page)
1975
- qs.page = listOptions.page;
1976
- if (listOptions.per_page)
1977
- qs.per_page = listOptions.per_page;
2166
+ if (templateListOptions.name)
2167
+ qs.name = templateListOptions.name;
2168
+ if (templateListOptions.tags)
2169
+ qs.tags = templateListOptions.tags;
2170
+ if (templateListOptions.access)
2171
+ qs.access = templateListOptions.access;
2172
+ if (templateListOptions.page)
2173
+ qs.page = templateListOptions.page;
2174
+ if (templateListOptions.per_page)
2175
+ qs.per_page = templateListOptions.per_page;
1978
2176
  const options = {
1979
2177
  method: 'GET',
1980
2178
  baseURL,
@@ -1997,7 +2195,7 @@ class PdfGeneratorApi {
1997
2195
  }
1998
2196
  else if (operation === 'create') {
1999
2197
  const templateConfiguration = this.getNodeParameter('templateConfiguration', i);
2000
- const body = JSON.parse(templateConfiguration);
2198
+ const body = parseJSON(templateConfiguration, 'templateConfiguration');
2001
2199
  const options = {
2002
2200
  method: 'POST',
2003
2201
  baseURL,
@@ -2011,7 +2209,7 @@ class PdfGeneratorApi {
2011
2209
  const templateIdParam = this.getNodeParameter('templateId', i);
2012
2210
  const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
2013
2211
  const templateConfiguration = this.getNodeParameter('templateConfiguration', i);
2014
- const body = JSON.parse(templateConfiguration);
2212
+ const body = parseJSON(templateConfiguration, 'templateConfiguration');
2015
2213
  const options = {
2016
2214
  method: 'PUT',
2017
2215
  baseURL,
@@ -2039,7 +2237,7 @@ class PdfGeneratorApi {
2039
2237
  }
2040
2238
  else if (operation === 'validate') {
2041
2239
  const templateConfig = this.getNodeParameter('templateConfig', i);
2042
- const body = typeof templateConfig === 'string' ? JSON.parse(templateConfig) : templateConfig;
2240
+ const body = parseJSON(templateConfig, 'templateConfig');
2043
2241
  if (!body || typeof body !== 'object') {
2044
2242
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Template configuration must be a valid JSON object', { itemIndex: i });
2045
2243
  }
@@ -2063,6 +2261,15 @@ class PdfGeneratorApi {
2063
2261
  };
2064
2262
  responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2065
2263
  }
2264
+ else if (operation === 'getTemplateSchema') {
2265
+ const options = {
2266
+ method: 'GET',
2267
+ baseURL,
2268
+ url: '/templates/schema',
2269
+ json: true,
2270
+ };
2271
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2272
+ }
2066
2273
  else if (operation === 'copy') {
2067
2274
  const templateIdParam = this.getNodeParameter('templateId', i);
2068
2275
  const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
@@ -2085,7 +2292,7 @@ class PdfGeneratorApi {
2085
2292
  const editorOptions = this.getNodeParameter('editorOptions', i, {});
2086
2293
  const body = {};
2087
2294
  if (editorOptions.data)
2088
- body.data = JSON.parse(editorOptions.data);
2295
+ body.data = parseJSON(editorOptions.data, 'editorOptions.data');
2089
2296
  if (editorOptions.language)
2090
2297
  body.language = editorOptions.language;
2091
2298
  const options = {
@@ -2101,6 +2308,7 @@ class PdfGeneratorApi {
2101
2308
  else if (resource === 'pdfServices') {
2102
2309
  const pdfSource = this.getNodeParameter('pdfSource', i);
2103
2310
  const outputFormat = this.getNodeParameter('outputFormat', i, 'base64');
2311
+ let optimizationStats = null;
2104
2312
  const body = {};
2105
2313
  if (pdfSource === 'url') {
2106
2314
  body.file_url = this.getNodeParameter('fileUrl', i);
@@ -2205,13 +2413,7 @@ class PdfGeneratorApi {
2205
2413
  }
2206
2414
  else if (operation === 'fillFormFields') {
2207
2415
  const formFieldsData = this.getNodeParameter('formFieldsData', i);
2208
- let parsedData;
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
- }
2416
+ const parsedData = parseJSON(formFieldsData, 'Form Fields Data');
2215
2417
  body.data = parsedData;
2216
2418
  const options = {
2217
2419
  method: 'POST',
@@ -2238,7 +2440,7 @@ class PdfGeneratorApi {
2238
2440
  const headers = fullResponse.headers || {};
2239
2441
  const originalSize = headers['x-original-size'] ? parseInt(headers['x-original-size'], 10) : null;
2240
2442
  const optimizedSize = headers['x-optimized-size'] ? parseInt(headers['x-optimized-size'], 10) : null;
2241
- responseData.__optimizationStats = {
2443
+ optimizationStats = {
2242
2444
  originalSize,
2243
2445
  optimizedSize,
2244
2446
  compressionRatio: originalSize && optimizedSize ? ((originalSize - optimizedSize) / originalSize * 100) : null
@@ -2257,22 +2459,20 @@ class PdfGeneratorApi {
2257
2459
  else if (outputFormat === 'file') {
2258
2460
  const binaryData = {};
2259
2461
  const fileName = `processed-document.pdf`;
2260
- const binaryBuffer = Buffer.isBuffer(responseData) ? responseData : Buffer.from(responseData);
2261
- binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, 'application/pdf');
2462
+ binaryData[fileName] = await this.helpers.prepareBinaryData(responseData, fileName, 'application/pdf');
2262
2463
  const jsonResponse = {
2263
2464
  success: true,
2264
2465
  operation,
2265
2466
  filename: fileName,
2266
2467
  format: outputFormat,
2267
- fileSize: binaryBuffer.length,
2468
+ fileSize: responseData.length,
2268
2469
  };
2269
- if (operation === 'optimize' && responseData.__optimizationStats) {
2270
- const stats = responseData.__optimizationStats;
2470
+ if (operation === 'optimize' && optimizationStats) {
2271
2471
  jsonResponse.optimizationStats = {
2272
- originalSize: stats.originalSize,
2273
- optimizedSize: stats.optimizedSize,
2274
- savedBytes: stats.originalSize && stats.optimizedSize ? stats.originalSize - stats.optimizedSize : null,
2275
- compressionRatio: stats.compressionRatio ? `${stats.compressionRatio.toFixed(2)}%` : null
2472
+ originalSize: optimizationStats.originalSize,
2473
+ optimizedSize: optimizationStats.optimizedSize,
2474
+ savedBytes: optimizationStats.originalSize && optimizationStats.optimizedSize ? optimizationStats.originalSize - optimizationStats.optimizedSize : null,
2475
+ compressionRatio: optimizationStats.compressionRatio ? `${optimizationStats.compressionRatio.toFixed(2)}%` : null
2276
2476
  };
2277
2477
  }
2278
2478
  returnData.push({
@@ -2287,15 +2487,13 @@ class PdfGeneratorApi {
2287
2487
  format: outputFormat,
2288
2488
  ...responseData,
2289
2489
  };
2290
- if (operation === 'optimize' && responseData.__optimizationStats) {
2291
- const stats = responseData.__optimizationStats;
2490
+ if (operation === 'optimize' && optimizationStats) {
2292
2491
  jsonResponse.optimizationStats = {
2293
- originalSize: stats.originalSize,
2294
- optimizedSize: stats.optimizedSize,
2295
- savedBytes: stats.originalSize && stats.optimizedSize ? stats.originalSize - stats.optimizedSize : null,
2296
- compressionRatio: stats.compressionRatio ? `${stats.compressionRatio.toFixed(2)}%` : null
2492
+ originalSize: optimizationStats.originalSize,
2493
+ optimizedSize: optimizationStats.optimizedSize,
2494
+ savedBytes: optimizationStats.originalSize && optimizationStats.optimizedSize ? optimizationStats.originalSize - optimizationStats.optimizedSize : null,
2495
+ compressionRatio: optimizationStats.compressionRatio ? `${optimizationStats.compressionRatio.toFixed(2)}%` : null
2297
2496
  };
2298
- delete jsonResponse.__optimizationStats;
2299
2497
  }
2300
2498
  returnData.push({
2301
2499
  json: jsonResponse,
@@ -2306,12 +2504,12 @@ class PdfGeneratorApi {
2306
2504
  }
2307
2505
  else if (resource === 'workspace') {
2308
2506
  if (operation === 'list') {
2309
- const listOptions = this.getNodeParameter('listOptions', i, {});
2507
+ const workspaceListOptions = this.getNodeParameter('workspaceListOptions', i, {});
2310
2508
  const qs = {};
2311
- if (listOptions.page)
2312
- qs.page = listOptions.page;
2313
- if (listOptions.per_page)
2314
- qs.per_page = listOptions.per_page;
2509
+ if (workspaceListOptions.page)
2510
+ qs.page = workspaceListOptions.page;
2511
+ if (workspaceListOptions.per_page)
2512
+ qs.per_page = workspaceListOptions.per_page;
2315
2513
  const options = {
2316
2514
  method: 'GET',
2317
2515
  baseURL,