@custom-js/n8n-nodes-pdf-toolkit 1.48.0 → 1.50.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.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: `
83
- const { PDFTOTEXT } = requir` + `e('./utils');
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: `
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 = requir" + "e('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 = {
@@ -117,60 +118,85 @@ class Scraper {
117
118
  const items = this.getInputData();
118
119
  const returnData = [];
119
120
  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 } = requir` + `e('./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
121
+ try {
122
+ const credentials = await this.getCredentials("customJsApi");
123
+ const url = this.getNodeParameter("url", i);
124
+ if (!url.startsWith("https://")) {
125
+ throw new Error("Website URL must start with https://");
126
+ }
127
+ const commandsRaw = this.getNodeParameter("commands", i, []);
128
+ const returnValueType = this.getNodeParameter("returnValueType", i);
129
+ const debug = this.getNodeParameter("debug", i);
130
+ // Flatten commands array
131
+ const commands = Array.isArray(commandsRaw.command) ? commandsRaw.command : [];
132
+ const payload = {
133
+ url,
134
+ commands,
135
+ };
136
+ const options = {
137
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
138
+ method: 'POST',
139
+ headers: {
140
+ "customjs-origin": "n8n/scraper",
141
+ },
142
+ body: {
143
+ input: JSON.stringify(payload),
144
+ code: `const { SCRAPER } = require('./utils'); ` +
145
+ `const payload = input; ` +
146
+ `return SCRAPER(payload.url, payload.commands || [], "${returnValueType === "binary" ? "image" : "html"}", ${debug ? "true" : "false"});`,
147
+ returnBinary: returnValueType === "binary" ? "true" : "false",
148
+ },
149
+ encoding: returnValueType === "binary" ? null : undefined,
150
+ json: true,
151
+ };
152
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
153
+ if (returnValueType === "binary") {
154
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
155
+ // No binary data returned; emit only JSON without a binary property
156
+ returnData.push({
157
+ json: items[i].json,
158
+ pairedItem: {
159
+ item: i,
160
+ },
161
+ });
162
+ continue;
163
+ }
164
+ const binaryData = await this.helpers.prepareBinaryData(response, "output.png");
155
165
  returnData.push({
156
166
  json: items[i].json,
167
+ binary: {
168
+ data: binaryData,
169
+ },
170
+ pairedItem: {
171
+ item: i,
172
+ },
173
+ });
174
+ }
175
+ else {
176
+ returnData.push({
177
+ json: {
178
+ output: response.toString(),
179
+ },
180
+ pairedItem: {
181
+ item: i,
182
+ },
157
183
  });
158
- continue;
159
184
  }
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
185
  }
168
- else {
169
- returnData.push({
170
- json: {
171
- output: response.toString(),
172
- },
173
- });
186
+ catch (error) {
187
+ const errorMessage = error instanceof Error ? error.message : String(error);
188
+ if (this.continueOnFail()) {
189
+ returnData.push({
190
+ json: {
191
+ error: errorMessage,
192
+ },
193
+ pairedItem: {
194
+ item: i,
195
+ },
196
+ });
197
+ continue;
198
+ }
199
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
174
200
  }
175
201
  }
176
202
  return [returnData];
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebsiteScreenshot = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  class WebsiteScreenshot {
5
6
  constructor() {
6
7
  this.description = {
@@ -37,38 +38,60 @@ class WebsiteScreenshot {
37
38
  const items = this.getInputData();
38
39
  const returnData = [];
39
40
  for (let i = 0; i < items.length; i++) {
40
- const credentials = await this.getCredentials("customJsApi");
41
- const urlInput = this.getNodeParameter("urlInput", i);
42
- const options = {
43
- url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
44
- method: 'POST',
45
- headers: {
46
- "customjs-origin": "n8n/screenshot",
47
- "x-api-key": credentials.apiKey,
48
- },
49
- body: {
50
- input: urlInput,
51
- code: "const { SCREENSHOT } = requir" + "e('./utils'); return SCREENSHOT(input);",
52
- returnBinary: "true",
53
- },
54
- encoding: 'arraybuffer',
55
- json: true,
56
- };
57
- const response = await this.helpers.httpRequest(options);
58
- if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
59
- // No binary data returned; emit only JSON without a binary property
41
+ try {
42
+ const credentials = await this.getCredentials("customJsApi");
43
+ const urlInput = this.getNodeParameter("urlInput", i);
44
+ const options = {
45
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
46
+ method: 'POST',
47
+ headers: {
48
+ "customjs-origin": "n8n/screenshot",
49
+ },
50
+ body: {
51
+ input: urlInput,
52
+ code: "const { SCREENSHOT } = require('./utils'); return SCREENSHOT(input);",
53
+ returnBinary: "true",
54
+ },
55
+ encoding: null,
56
+ json: true,
57
+ };
58
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
59
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
60
+ // No binary data returned; emit only JSON without a binary property
61
+ returnData.push({
62
+ json: items[i].json,
63
+ pairedItem: {
64
+ item: i,
65
+ },
66
+ });
67
+ continue;
68
+ }
69
+ const binaryData = await this.helpers.prepareBinaryData(response, "output.png");
60
70
  returnData.push({
61
71
  json: items[i].json,
72
+ binary: {
73
+ data: binaryData,
74
+ },
75
+ pairedItem: {
76
+ item: i,
77
+ },
62
78
  });
63
- continue;
64
79
  }
65
- const binaryData = await this.helpers.prepareBinaryData(response, "output.png");
66
- returnData.push({
67
- json: items[i].json,
68
- binary: {
69
- data: binaryData,
70
- },
71
- });
80
+ catch (error) {
81
+ const errorMessage = error instanceof Error ? error.message : String(error);
82
+ if (this.continueOnFail()) {
83
+ returnData.push({
84
+ json: {
85
+ error: errorMessage,
86
+ },
87
+ pairedItem: {
88
+ item: i,
89
+ },
90
+ });
91
+ continue;
92
+ }
93
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
94
+ }
72
95
  }
73
96
  return [returnData];
74
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@custom-js/n8n-nodes-pdf-toolkit",
3
- "version": "1.48.0",
3
+ "version": "1.50.0",
4
4
  "description": "This is official node for interacting with APIs from customjs.space",
5
5
  "keywords": [
6
6
  "customjs",
@@ -44,14 +44,14 @@
44
44
  "dist/nodes/InvoiceGenerator/InvoiceGenerator.node.js"
45
45
  ]
46
46
  },
47
- "dependencies": {
48
- "n8n-workflow": "^0.141.0"
49
- },
50
47
  "devDependencies": {
51
48
  "typescript": "~4.8.4",
52
49
  "gulp": "^4.0.2",
53
50
  "@types/node": "^16.11.7"
54
51
  },
52
+ "peerDependencies": {
53
+ "n8n-workflow": "*"
54
+ },
55
55
  "type": "commonjs",
56
56
  "main": "index.js",
57
57
  "scripts": {