@custom-js/n8n-nodes-pdf-toolkit 1.49.0 → 1.51.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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PdfFormFill = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  class PdfFormFill {
5
6
  constructor() {
6
7
  this.description = {
@@ -74,6 +75,14 @@ class PdfFormFill {
74
75
  },
75
76
  ],
76
77
  },
78
+ {
79
+ displayName: "Output Filename",
80
+ name: "outputFilename",
81
+ type: "string",
82
+ default: "document.pdf",
83
+ description: "Name for the generated PDF file (include .pdf extension)",
84
+ required: false,
85
+ },
77
86
  ],
78
87
  };
79
88
  }
@@ -90,51 +99,74 @@ class PdfFormFill {
90
99
  return Buffer.from(file.data, "base64");
91
100
  };
92
101
  for (let i = 0; i < items.length; i++) {
93
- const credentials = await this.getCredentials("customJsApi");
94
- const field_name = this.getNodeParameter("field_name", i);
95
- const isBinary = this.getNodeParameter("resource", i) === "binary";
96
- const file = isBinary ? getFile(field_name, i) : "";
97
- if (!isBinary) {
98
- throw new Error(`Invalid binary data`);
99
- }
100
- const options = {
101
- url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
102
- method: 'POST',
103
- headers: {
104
- "customjs-origin": "n8n/pdfFormFill",
105
- "x-api-key": credentials.apiKey,
106
- },
107
- body: {
108
- input: {
109
- file: file,
110
- // n8n fixedCollection with multipleValues returns an object like { field: [{ name, value }, ...] }
111
- fields: ((_a = this.getNodeParameter("fields", i)) === null || _a === void 0 ? void 0 : _a.field) || []
102
+ try {
103
+ const credentials = await this.getCredentials("customJsApi");
104
+ const field_name = this.getNodeParameter("field_name", i);
105
+ const isBinary = this.getNodeParameter("resource", i) === "binary";
106
+ const file = isBinary ? getFile(field_name, i) : "";
107
+ if (!isBinary) {
108
+ throw new Error(`Invalid binary data`);
109
+ }
110
+ const options = {
111
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
112
+ method: 'POST',
113
+ headers: {
114
+ "customjs-origin": "n8n/pdfFormFill",
112
115
  },
113
- code: `
116
+ body: {
117
+ input: {
118
+ file: file,
119
+ // n8n fixedCollection with multipleValues returns an object like { field: [{ name, value }, ...] }
120
+ fields: ((_a = this.getNodeParameter("fields", i)) === null || _a === void 0 ? void 0 : _a.field) || []
121
+ },
122
+ code: `
114
123
  const { PDF_FILL_FORM } = require('./utils');
115
124
  const pdfInput = input.file;
116
125
  const fieldValues = Object.fromEntries((input.fields || []).map(x => [x.name, x.value]));
117
126
  return PDF_FILL_FORM(pdfInput, fieldValues);`,
118
- returnBinary: "true",
119
- },
120
- encoding: 'arraybuffer',
121
- json: true,
122
- };
123
- const response = await this.helpers.httpRequest(options);
124
- if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
125
- // No binary data returned; emit only JSON without a binary property
127
+ returnBinary: "true",
128
+ },
129
+ encoding: null,
130
+ json: true,
131
+ };
132
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
133
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
134
+ // No binary data returned; emit only JSON without a binary property
135
+ returnData.push({
136
+ json: items[i].json,
137
+ pairedItem: {
138
+ item: i,
139
+ },
140
+ });
141
+ continue;
142
+ }
143
+ const outputFilename = this.getNodeParameter("outputFilename", i, "document.pdf");
144
+ const binaryData = await this.helpers.prepareBinaryData(response, outputFilename);
126
145
  returnData.push({
127
146
  json: items[i].json,
147
+ binary: {
148
+ data: binaryData,
149
+ },
150
+ pairedItem: {
151
+ item: i,
152
+ },
128
153
  });
129
- continue;
130
154
  }
131
- const binaryData = await this.helpers.prepareBinaryData(response, "document.pdf");
132
- returnData.push({
133
- json: items[i].json,
134
- binary: {
135
- data: binaryData,
136
- },
137
- });
155
+ catch (error) {
156
+ const errorMessage = error instanceof Error ? error.message : String(error);
157
+ if (this.continueOnFail()) {
158
+ returnData.push({
159
+ json: {
160
+ error: errorMessage,
161
+ },
162
+ pairedItem: {
163
+ item: i,
164
+ },
165
+ });
166
+ continue;
167
+ }
168
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
169
+ }
138
170
  }
139
171
  return [returnData];
140
172
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PdfToPng = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  class PdfToPng {
5
6
  constructor() {
6
7
  this.description = {
@@ -46,6 +47,14 @@ class PdfToPng {
46
47
  description: "The field name for binary PDF file or url that indicates PDF file. Please make sure the size of PDf file doesn't exceed 6mb. If it's bigger, pass URL rather than binary file.",
47
48
  required: true,
48
49
  },
50
+ {
51
+ displayName: "Output Filename",
52
+ name: "outputFilename",
53
+ type: "string",
54
+ default: "output.png",
55
+ description: "Name for the generated PNG file (include .png extension)",
56
+ required: false,
57
+ },
49
58
  ],
50
59
  };
51
60
  }
@@ -61,48 +70,71 @@ class PdfToPng {
61
70
  return Buffer.from(file.data, "base64");
62
71
  };
63
72
  for (let i = 0; i < items.length; i++) {
64
- const credentials = await this.getCredentials("customJsApi");
65
- const field_name = this.getNodeParameter("field_name", i);
66
- const isBinary = this.getNodeParameter("resource", i) === "binary";
67
- const file = isBinary ? getFile(field_name, i) : "";
68
- if (!isBinary &&
69
- !field_name.startsWith("http://") &&
70
- !field_name.startsWith("https://")) {
71
- throw new Error(`Invalid URL: ${field_name}`);
72
- }
73
- const options = {
74
- url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
75
- method: 'POST',
76
- headers: {
77
- "customjs-origin": "n8n/pdfToPng",
78
- "x-api-key": credentials.apiKey,
79
- },
80
- body: {
81
- input: isBinary ? { file: file } : { urls: field_name },
82
- code: `
73
+ try {
74
+ const credentials = await this.getCredentials("customJsApi");
75
+ const field_name = this.getNodeParameter("field_name", i);
76
+ const isBinary = this.getNodeParameter("resource", i) === "binary";
77
+ const file = isBinary ? getFile(field_name, i) : "";
78
+ if (!isBinary &&
79
+ !field_name.startsWith("http://") &&
80
+ !field_name.startsWith("https://")) {
81
+ throw new Error(`Invalid URL: ${field_name}`);
82
+ }
83
+ const options = {
84
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
85
+ method: 'POST',
86
+ headers: {
87
+ "customjs-origin": "n8n/pdfToPng",
88
+ },
89
+ body: {
90
+ input: isBinary ? { file: file } : { urls: field_name },
91
+ code: `
83
92
  const { PDF2PNG } = require('./utils');
84
93
  input = input.file || input.urls;
85
94
  return PDF2PNG(input);`,
86
- returnBinary: "true",
87
- },
88
- encoding: 'arraybuffer',
89
- json: true,
90
- };
91
- const response = await this.helpers.httpRequest(options);
92
- if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
93
- // No binary data returned; emit only JSON without a binary property
95
+ returnBinary: "true",
96
+ },
97
+ encoding: null,
98
+ json: true,
99
+ };
100
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
101
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
102
+ // No binary data returned; emit only JSON without a binary property
103
+ returnData.push({
104
+ json: items[i].json,
105
+ pairedItem: {
106
+ item: i,
107
+ },
108
+ });
109
+ continue;
110
+ }
111
+ const outputFilename = this.getNodeParameter("outputFilename", i, "output.png");
112
+ const binaryData = await this.helpers.prepareBinaryData(response, outputFilename);
94
113
  returnData.push({
95
114
  json: items[i].json,
115
+ binary: {
116
+ data: binaryData,
117
+ },
118
+ pairedItem: {
119
+ item: i,
120
+ },
96
121
  });
97
- continue;
98
122
  }
99
- const binaryData = await this.helpers.prepareBinaryData(response, "output.png");
100
- returnData.push({
101
- json: items[i].json,
102
- binary: {
103
- data: binaryData,
104
- },
105
- });
123
+ catch (error) {
124
+ const errorMessage = error instanceof Error ? error.message : String(error);
125
+ if (this.continueOnFail()) {
126
+ returnData.push({
127
+ json: {
128
+ error: errorMessage,
129
+ },
130
+ pairedItem: {
131
+ item: i,
132
+ },
133
+ });
134
+ continue;
135
+ }
136
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
137
+ }
106
138
  }
107
139
  return [returnData];
108
140
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PdfToText = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  class PdfToText {
5
6
  constructor() {
6
7
  this.description = {
@@ -61,38 +62,57 @@ class PdfToText {
61
62
  return Buffer.from(file.data, "base64");
62
63
  };
63
64
  for (let i = 0; i < items.length; i++) {
64
- const credentials = await this.getCredentials("customJsApi");
65
- const field_name = this.getNodeParameter("field_name", i);
66
- const isBinary = this.getNodeParameter("resource", i) === "binary";
67
- const file = isBinary ? getFile(field_name, i) : "";
68
- if (!isBinary &&
69
- !field_name.startsWith("http://") &&
70
- !field_name.startsWith("https://")) {
71
- throw new Error(`Invalid URL: ${field_name}`);
72
- }
73
- const options = {
74
- url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
75
- method: 'POST',
76
- headers: {
77
- "customjs-origin": "n8n/pdfToText",
78
- "x-api-key": credentials.apiKey,
79
- },
80
- body: {
81
- input: isBinary ? { file: file } : { urls: field_name },
82
- code: `
65
+ try {
66
+ const credentials = await this.getCredentials("customJsApi");
67
+ const field_name = this.getNodeParameter("field_name", i);
68
+ const isBinary = this.getNodeParameter("resource", i) === "binary";
69
+ const file = isBinary ? getFile(field_name, i) : "";
70
+ if (!isBinary &&
71
+ !field_name.startsWith("http://") &&
72
+ !field_name.startsWith("https://")) {
73
+ throw new Error(`Invalid URL: ${field_name}`);
74
+ }
75
+ const options = {
76
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
77
+ method: 'POST',
78
+ headers: {
79
+ "customjs-origin": "n8n/pdfToText",
80
+ },
81
+ body: {
82
+ input: isBinary ? { file: file } : { urls: field_name },
83
+ code: `
83
84
  const { PDFTOTEXT } = require('./utils');
84
85
  input = input.file || input.urls;
85
86
  return PDFTOTEXT(input);`,
86
- returnBinary: "false",
87
- },
88
- json: true,
89
- };
90
- const response = await this.helpers.httpRequest(options);
91
- returnData.push({
92
- json: {
93
- output: response.toString(),
94
- },
95
- });
87
+ returnBinary: "false",
88
+ },
89
+ json: true,
90
+ };
91
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
92
+ returnData.push({
93
+ json: {
94
+ output: response.toString(),
95
+ },
96
+ pairedItem: {
97
+ item: i,
98
+ },
99
+ });
100
+ }
101
+ catch (error) {
102
+ const errorMessage = error instanceof Error ? error.message : String(error);
103
+ if (this.continueOnFail()) {
104
+ returnData.push({
105
+ json: {
106
+ error: errorMessage,
107
+ },
108
+ pairedItem: {
109
+ item: i,
110
+ },
111
+ });
112
+ continue;
113
+ }
114
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
115
+ }
96
116
  }
97
117
  return [returnData];
98
118
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SSLChecker = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  class SSLChecker {
5
6
  constructor() {
6
7
  this.description = {
@@ -45,27 +46,46 @@ class SSLChecker {
45
46
  const items = this.getInputData();
46
47
  const returnData = [];
47
48
  for (let i = 0; i < items.length; i++) {
48
- const credentials = await this.getCredentials("customJsApi");
49
- const domain = this.getNodeParameter("domain", i);
50
- const options = {
51
- url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
52
- method: 'POST',
53
- headers: {
54
- "customjs-origin": "n8n/sslchecker",
55
- "x-api-key": credentials.apiKey,
56
- },
57
- body: {
58
- input: domain,
59
- code: "const checkCertExpiration = require('check-cert-expiration'); return checkCertExpiration(input);",
60
- },
61
- json: true,
62
- };
63
- const response = await this.helpers.httpRequest(options);
64
- returnData.push({
65
- json: {
66
- output: response,
67
- },
68
- });
49
+ try {
50
+ const credentials = await this.getCredentials("customJsApi");
51
+ const domain = this.getNodeParameter("domain", i);
52
+ const options = {
53
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
54
+ method: 'POST',
55
+ headers: {
56
+ "customjs-origin": "n8n/sslchecker",
57
+ },
58
+ body: {
59
+ input: domain,
60
+ code: "const checkCertExpiration = require('check-cert-expiration'); return checkCertExpiration(input);",
61
+ },
62
+ json: true,
63
+ };
64
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
65
+ returnData.push({
66
+ json: {
67
+ output: response,
68
+ },
69
+ pairedItem: {
70
+ item: i,
71
+ },
72
+ });
73
+ }
74
+ catch (error) {
75
+ const errorMessage = error instanceof Error ? error.message : String(error);
76
+ if (this.continueOnFail()) {
77
+ returnData.push({
78
+ json: {
79
+ error: errorMessage,
80
+ },
81
+ pairedItem: {
82
+ item: i,
83
+ },
84
+ });
85
+ continue;
86
+ }
87
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
88
+ }
69
89
  }
70
90
  return [returnData];
71
91
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Scraper = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  class Scraper {
5
6
  constructor() {
6
7
  this.description = {
@@ -110,6 +111,19 @@ class Scraper {
110
111
  description: "Specify if the operation should be canceled when the element is not found.",
111
112
  required: true,
112
113
  },
114
+ {
115
+ displayName: "Output Filename",
116
+ name: "outputFilename",
117
+ type: "string",
118
+ default: "output.png",
119
+ description: "Name for the generated PNG file (include .png extension)",
120
+ required: false,
121
+ displayOptions: {
122
+ show: {
123
+ returnValueType: ["binary"],
124
+ },
125
+ },
126
+ },
113
127
  ],
114
128
  };
115
129
  }
@@ -117,60 +131,86 @@ class Scraper {
117
131
  const items = this.getInputData();
118
132
  const returnData = [];
119
133
  for (let i = 0; i < items.length; i++) {
120
- const credentials = await this.getCredentials("customJsApi");
121
- const url = this.getNodeParameter("url", i);
122
- if (!url.startsWith("https://")) {
123
- throw new Error("Website URL must start with https://");
124
- }
125
- const commandsRaw = this.getNodeParameter("commands", i, []);
126
- const returnValueType = this.getNodeParameter("returnValueType", i);
127
- const debug = this.getNodeParameter("debug", i);
128
- // Flatten commands array
129
- const commands = Array.isArray(commandsRaw.command) ? commandsRaw.command : [];
130
- const payload = {
131
- url,
132
- commands,
133
- };
134
- const options = {
135
- url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
136
- method: 'POST',
137
- headers: {
138
- "customjs-origin": "n8n/scraper",
139
- "x-api-key": credentials.apiKey,
140
- },
141
- body: {
142
- input: JSON.stringify(payload),
143
- code: `const { SCRAPER } = require('./utils'); ` +
144
- `const payload = input; ` +
145
- `return SCRAPER(payload.url, payload.commands || [], "${returnValueType === "binary" ? "image" : "html"}", ${debug ? "true" : "false"});`,
146
- returnBinary: returnValueType === "binary" ? "true" : "false",
147
- },
148
- encoding: (returnValueType === "binary" ? 'arraybuffer' : undefined),
149
- json: true,
150
- };
151
- const response = await this.helpers.httpRequest(options);
152
- if (returnValueType === "binary") {
153
- if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
154
- // No binary data returned; emit only JSON without a binary property
134
+ try {
135
+ const credentials = await this.getCredentials("customJsApi");
136
+ const url = this.getNodeParameter("url", i);
137
+ if (!url.startsWith("https://")) {
138
+ throw new Error("Website URL must start with https://");
139
+ }
140
+ const commandsRaw = this.getNodeParameter("commands", i, []);
141
+ const returnValueType = this.getNodeParameter("returnValueType", i);
142
+ const debug = this.getNodeParameter("debug", i);
143
+ // Flatten commands array
144
+ const commands = Array.isArray(commandsRaw.command) ? commandsRaw.command : [];
145
+ const payload = {
146
+ url,
147
+ commands,
148
+ };
149
+ const options = {
150
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
151
+ method: 'POST',
152
+ headers: {
153
+ "customjs-origin": "n8n/scraper",
154
+ },
155
+ body: {
156
+ input: JSON.stringify(payload),
157
+ code: `const { SCRAPER } = require('./utils'); ` +
158
+ `const payload = input; ` +
159
+ `return SCRAPER(payload.url, payload.commands || [], "${returnValueType === "binary" ? "image" : "html"}", ${debug ? "true" : "false"});`,
160
+ returnBinary: returnValueType === "binary" ? "true" : "false",
161
+ },
162
+ encoding: returnValueType === "binary" ? null : undefined,
163
+ json: true,
164
+ };
165
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
166
+ if (returnValueType === "binary") {
167
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
168
+ // No binary data returned; emit only JSON without a binary property
169
+ returnData.push({
170
+ json: items[i].json,
171
+ pairedItem: {
172
+ item: i,
173
+ },
174
+ });
175
+ continue;
176
+ }
177
+ const outputFilename = this.getNodeParameter("outputFilename", i, "output.png");
178
+ const binaryData = await this.helpers.prepareBinaryData(response, outputFilename);
155
179
  returnData.push({
156
180
  json: items[i].json,
181
+ binary: {
182
+ data: binaryData,
183
+ },
184
+ pairedItem: {
185
+ item: i,
186
+ },
187
+ });
188
+ }
189
+ else {
190
+ returnData.push({
191
+ json: {
192
+ output: response.toString(),
193
+ },
194
+ pairedItem: {
195
+ item: i,
196
+ },
157
197
  });
158
- continue;
159
198
  }
160
- const binaryData = await this.helpers.prepareBinaryData(response, "output.png");
161
- returnData.push({
162
- json: items[i].json,
163
- binary: {
164
- data: binaryData,
165
- },
166
- });
167
199
  }
168
- else {
169
- returnData.push({
170
- json: {
171
- output: response.toString(),
172
- },
173
- });
200
+ catch (error) {
201
+ const errorMessage = error instanceof Error ? error.message : String(error);
202
+ if (this.continueOnFail()) {
203
+ returnData.push({
204
+ json: {
205
+ error: errorMessage,
206
+ },
207
+ pairedItem: {
208
+ item: i,
209
+ },
210
+ });
211
+ continue;
212
+ }
213
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
174
214
  }
175
215
  }
176
216
  return [returnData];