n8n-nodes-morphopdf 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/nodes/MorphoPdf/MorphoPdfTool.node.d.ts +15 -0
- package/dist/nodes/MorphoPdf/MorphoPdfTool.node.d.ts.map +1 -0
- package/dist/nodes/MorphoPdf/MorphoPdfTool.node.js +207 -0
- package/dist/nodes/MorphoPdf/MorphoPdfTool.node.js.map +1 -0
- package/dist/nodes/MorphoPdf/shared/errors.d.ts.map +1 -1
- package/dist/nodes/MorphoPdf/shared/errors.js +46 -6
- package/dist/nodes/MorphoPdf/shared/errors.js.map +1 -1
- package/dist/nodes/MorphoPdf/shared/toolSchema.d.ts +91 -0
- package/dist/nodes/MorphoPdf/shared/toolSchema.d.ts.map +1 -0
- package/dist/nodes/MorphoPdf/shared/toolSchema.js +200 -0
- package/dist/nodes/MorphoPdf/shared/toolSchema.js.map +1 -0
- package/package.json +7 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { INodeType, INodeTypeDescription, ISupplyDataFunctions, SupplyData } from 'n8n-workflow';
|
|
2
|
+
/**
|
|
3
|
+
* MorphoPDF AI Tool Node
|
|
4
|
+
*
|
|
5
|
+
* This node provides PDF processing capabilities for AI agents.
|
|
6
|
+
* It uses DynamicStructuredTool to expose operations to LangChain-compatible agents.
|
|
7
|
+
*
|
|
8
|
+
* Unlike the regular MorphoPdf node which uses execute(), this node uses supplyData()
|
|
9
|
+
* to provide a tool that agents can call dynamically.
|
|
10
|
+
*/
|
|
11
|
+
export declare class MorphoPdfTool implements INodeType {
|
|
12
|
+
description: INodeTypeDescription;
|
|
13
|
+
supplyData(this: ISupplyDataFunctions, _itemIndex: number): Promise<SupplyData>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=MorphoPdfTool.node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MorphoPdfTool.node.d.ts","sourceRoot":"","sources":["../../../nodes/MorphoPdf/MorphoPdfTool.node.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EACT,oBAAoB,EACpB,oBAAoB,EACpB,UAAU,EAEX,MAAM,cAAc,CAAC;AAwFtB;;;;;;;;GAQG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC7C,WAAW,EAAE,oBAAoB,CA0C/B;IAGI,UAAU,CAAC,IAAI,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;CAoHtF"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MorphoPdfTool = void 0;
|
|
4
|
+
// eslint-disable-next-line @n8n/community-nodes/no-restricted-imports
|
|
5
|
+
const tools_1 = require("@langchain/core/tools");
|
|
6
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
7
|
+
const toolSchema_1 = require("./shared/toolSchema");
|
|
8
|
+
const API_BASE_URL = 'https://api.morphopdf.com/v1';
|
|
9
|
+
/**
|
|
10
|
+
* Build request body from tool input based on operation type
|
|
11
|
+
*/
|
|
12
|
+
function buildRequestBody(input) {
|
|
13
|
+
const { operation } = input;
|
|
14
|
+
switch (operation) {
|
|
15
|
+
case 'compress':
|
|
16
|
+
return {
|
|
17
|
+
url: input.inputUrl,
|
|
18
|
+
quality: input.quality || 'low',
|
|
19
|
+
};
|
|
20
|
+
case 'merge':
|
|
21
|
+
return {
|
|
22
|
+
urls: [input.inputUrl, ...(input.additionalUrls || [])],
|
|
23
|
+
};
|
|
24
|
+
case 'split':
|
|
25
|
+
return {
|
|
26
|
+
url: input.inputUrl,
|
|
27
|
+
mode: input.splitMode || 'ranges',
|
|
28
|
+
ranges: input.pageRanges || ['1-1'],
|
|
29
|
+
};
|
|
30
|
+
case 'rotate':
|
|
31
|
+
return {
|
|
32
|
+
url: input.inputUrl,
|
|
33
|
+
angle: parseInt(input.rotationAngle || '90', 10),
|
|
34
|
+
};
|
|
35
|
+
case 'watermark':
|
|
36
|
+
return {
|
|
37
|
+
url: input.inputUrl,
|
|
38
|
+
text: input.watermarkText,
|
|
39
|
+
position: input.watermarkPosition || 'center',
|
|
40
|
+
opacity: input.watermarkOpacity ?? 0.3,
|
|
41
|
+
};
|
|
42
|
+
case 'pdfToWord':
|
|
43
|
+
return {
|
|
44
|
+
url: input.inputUrl,
|
|
45
|
+
};
|
|
46
|
+
case 'pdfToExcel':
|
|
47
|
+
return {
|
|
48
|
+
url: input.inputUrl,
|
|
49
|
+
};
|
|
50
|
+
case 'pdfToImage':
|
|
51
|
+
return {
|
|
52
|
+
url: input.inputUrl,
|
|
53
|
+
format: input.imageFormat || 'png',
|
|
54
|
+
dpi: parseInt(input.dpi || '150', 10),
|
|
55
|
+
};
|
|
56
|
+
case 'wordToPdf':
|
|
57
|
+
return {
|
|
58
|
+
url: input.inputUrl,
|
|
59
|
+
};
|
|
60
|
+
case 'htmlToPdf':
|
|
61
|
+
// Use htmlContent if provided, otherwise use inputUrl
|
|
62
|
+
if (input.htmlContent) {
|
|
63
|
+
return {
|
|
64
|
+
html: input.htmlContent,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
url: input.inputUrl,
|
|
69
|
+
};
|
|
70
|
+
default:
|
|
71
|
+
return { url: input.inputUrl };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* MorphoPDF AI Tool Node
|
|
76
|
+
*
|
|
77
|
+
* This node provides PDF processing capabilities for AI agents.
|
|
78
|
+
* It uses DynamicStructuredTool to expose operations to LangChain-compatible agents.
|
|
79
|
+
*
|
|
80
|
+
* Unlike the regular MorphoPdf node which uses execute(), this node uses supplyData()
|
|
81
|
+
* to provide a tool that agents can call dynamically.
|
|
82
|
+
*/
|
|
83
|
+
class MorphoPdfTool {
|
|
84
|
+
description = {
|
|
85
|
+
displayName: 'MorphoPDF Tool',
|
|
86
|
+
name: 'morphoPdfTool',
|
|
87
|
+
icon: 'file:morphopdf.svg',
|
|
88
|
+
iconColor: 'blue',
|
|
89
|
+
group: ['transform'],
|
|
90
|
+
version: 1,
|
|
91
|
+
description: 'PDF processing for AI agents - merge, split, convert, compress, watermark',
|
|
92
|
+
defaults: {
|
|
93
|
+
name: 'MorphoPDF Tool',
|
|
94
|
+
},
|
|
95
|
+
usableAsTool: true,
|
|
96
|
+
codex: {
|
|
97
|
+
categories: ['AI'],
|
|
98
|
+
subcategories: {
|
|
99
|
+
AI: ['Tools'],
|
|
100
|
+
Tools: ['Recommended Tools'],
|
|
101
|
+
},
|
|
102
|
+
resources: {
|
|
103
|
+
primaryDocumentation: [{ url: 'https://docs.morphopdf.com/api' }],
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
inputs: [],
|
|
107
|
+
outputs: [n8n_workflow_1.NodeConnectionTypes.AiTool],
|
|
108
|
+
outputNames: ['Tool'],
|
|
109
|
+
credentials: [
|
|
110
|
+
{
|
|
111
|
+
name: 'morphoPdfApi',
|
|
112
|
+
required: true,
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
properties: [
|
|
116
|
+
{
|
|
117
|
+
displayName: 'This tool exposes MorphoPDF operations to AI agents. ' +
|
|
118
|
+
'Connect this to an AI Agent node. The agent will automatically ' +
|
|
119
|
+
'choose the appropriate operation based on the task.',
|
|
120
|
+
name: 'notice',
|
|
121
|
+
type: 'notice',
|
|
122
|
+
default: '',
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
127
|
+
async supplyData(_itemIndex) {
|
|
128
|
+
const credentials = await this.getCredentials('morphoPdfApi');
|
|
129
|
+
const apiKey = credentials.apiKey;
|
|
130
|
+
// Get reference to context for use in tool function
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
132
|
+
const context = this;
|
|
133
|
+
const tool = new tools_1.DynamicStructuredTool({
|
|
134
|
+
name: 'morphopdf_tool',
|
|
135
|
+
description: 'Process PDF files - merge, split, compress, rotate, watermark, and convert formats. ' +
|
|
136
|
+
'Supports: compress (reduce file size), merge (combine PDFs), split (divide into parts), ' +
|
|
137
|
+
'rotate (turn pages), watermark (add text overlay), pdfToWord, pdfToExcel, pdfToImage, ' +
|
|
138
|
+
'wordToPdf, htmlToPdf. Requires public URLs for input files.',
|
|
139
|
+
schema: toolSchema_1.morphoPdfToolSchema,
|
|
140
|
+
func: async (input) => {
|
|
141
|
+
// Log input for n8n execution panel
|
|
142
|
+
const { index } = context.addInputData(n8n_workflow_1.NodeConnectionTypes.AiTool, [
|
|
143
|
+
[{ json: input }],
|
|
144
|
+
]);
|
|
145
|
+
try {
|
|
146
|
+
// Validate required inputUrl for operations that need it
|
|
147
|
+
if (input.operation !== 'htmlToPdf' && !input.inputUrl) {
|
|
148
|
+
throw new n8n_workflow_1.NodeOperationError(context.getNode(), `inputUrl is required for ${input.operation} operation`);
|
|
149
|
+
}
|
|
150
|
+
// For htmlToPdf, require either inputUrl or htmlContent
|
|
151
|
+
if (input.operation === 'htmlToPdf' && !input.inputUrl && !input.htmlContent) {
|
|
152
|
+
throw new n8n_workflow_1.NodeOperationError(context.getNode(), 'htmlToPdf requires either inputUrl or htmlContent');
|
|
153
|
+
}
|
|
154
|
+
// For merge, require at least one additional URL
|
|
155
|
+
if (input.operation === 'merge' &&
|
|
156
|
+
(!input.additionalUrls || input.additionalUrls.length === 0)) {
|
|
157
|
+
throw new n8n_workflow_1.NodeOperationError(context.getNode(), 'merge operation requires at least one URL in additionalUrls');
|
|
158
|
+
}
|
|
159
|
+
// For watermark, require watermarkText
|
|
160
|
+
if (input.operation === 'watermark' && !input.watermarkText) {
|
|
161
|
+
throw new n8n_workflow_1.NodeOperationError(context.getNode(), 'watermark operation requires watermarkText');
|
|
162
|
+
}
|
|
163
|
+
// Build API request
|
|
164
|
+
const endpoint = toolSchema_1.operationEndpoints[input.operation];
|
|
165
|
+
const body = buildRequestBody(input);
|
|
166
|
+
// Make API request using httpRequest helper
|
|
167
|
+
const response = await context.helpers.httpRequest({
|
|
168
|
+
method: 'POST',
|
|
169
|
+
url: `${API_BASE_URL}${endpoint}`,
|
|
170
|
+
headers: {
|
|
171
|
+
Authorization: `Bearer ${apiKey}`,
|
|
172
|
+
'Content-Type': 'application/json',
|
|
173
|
+
},
|
|
174
|
+
body,
|
|
175
|
+
json: true,
|
|
176
|
+
});
|
|
177
|
+
// Format response for LLM
|
|
178
|
+
const result = (0, toolSchema_1.formatToolResponse)(input.operation, response);
|
|
179
|
+
// Log output
|
|
180
|
+
context.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiTool, index, [
|
|
181
|
+
[{ json: result }],
|
|
182
|
+
]);
|
|
183
|
+
return JSON.stringify(result, null, 2);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
// Handle errors gracefully - return error string instead of throwing
|
|
187
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
188
|
+
const errorResult = {
|
|
189
|
+
success: false,
|
|
190
|
+
operation: input.operation,
|
|
191
|
+
operationName: input.operation,
|
|
192
|
+
message: `Operation failed: ${errorMessage}`,
|
|
193
|
+
error: errorMessage,
|
|
194
|
+
};
|
|
195
|
+
// Log error output
|
|
196
|
+
context.addOutputData(n8n_workflow_1.NodeConnectionTypes.AiTool, index, [
|
|
197
|
+
[{ json: errorResult }],
|
|
198
|
+
]);
|
|
199
|
+
return JSON.stringify(errorResult, null, 2);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
return { response: tool };
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.MorphoPdfTool = MorphoPdfTool;
|
|
207
|
+
//# sourceMappingURL=MorphoPdfTool.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MorphoPdfTool.node.js","sourceRoot":"","sources":["../../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AAEF,qBAAa,cAAe,SAAQ,KAAK;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;gBAEP,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAO3C;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../nodes/MorphoPdf/shared/errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAYzF,CAAC;AAEF,qBAAa,cAAe,SAAQ,KAAK;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;gBAEP,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAO3C;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CA4EpD"}
|
|
@@ -31,14 +31,54 @@ function handleApiError(error) {
|
|
|
31
31
|
if (error instanceof MorphoPdfError) {
|
|
32
32
|
throw error;
|
|
33
33
|
}
|
|
34
|
+
// n8n's httpRequest can put error data in various locations depending on the error type
|
|
35
|
+
// Try to extract the API's structured error response: { error: { code, message, hint } }
|
|
34
36
|
const err = error;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
// Try multiple locations where n8n might put the response body
|
|
38
|
+
const possibleBodies = [
|
|
39
|
+
err.response?.body,
|
|
40
|
+
err.response?.data,
|
|
41
|
+
err.body,
|
|
42
|
+
];
|
|
43
|
+
for (const body of possibleBodies) {
|
|
44
|
+
if (body && typeof body === 'object') {
|
|
45
|
+
const parsed = body;
|
|
46
|
+
// Check for API's structured error format
|
|
47
|
+
if (parsed.error?.code || parsed.error?.message) {
|
|
48
|
+
const code = parsed.error.code || 'UNKNOWN_ERROR';
|
|
49
|
+
const message = parsed.error.message || 'Unknown error occurred';
|
|
50
|
+
const hint = parsed.error.hint;
|
|
51
|
+
// Build a helpful error message including the hint if available
|
|
52
|
+
const fullMessage = hint
|
|
53
|
+
? `${message}. Hint: ${hint}`
|
|
54
|
+
: message;
|
|
55
|
+
// Check if it's a known error code
|
|
56
|
+
if (exports.MORPHOPDF_ERROR_CODES[code]) {
|
|
57
|
+
throw new MorphoPdfError(code, fullMessage);
|
|
58
|
+
}
|
|
59
|
+
// Unknown error code but still has structured error
|
|
60
|
+
throw new Error(`MorphoPDF API Error: ${fullMessage}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Try parsing string body as JSON
|
|
64
|
+
if (body && typeof body === 'string') {
|
|
65
|
+
try {
|
|
66
|
+
const parsed = JSON.parse(body);
|
|
67
|
+
if (parsed.error?.message) {
|
|
68
|
+
const hint = parsed.error.hint;
|
|
69
|
+
const fullMessage = hint
|
|
70
|
+
? `${parsed.error.message}. Hint: ${hint}`
|
|
71
|
+
: parsed.error.message;
|
|
72
|
+
throw new Error(`MorphoPDF API Error: ${fullMessage}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Not valid JSON, continue to next
|
|
77
|
+
}
|
|
40
78
|
}
|
|
41
79
|
}
|
|
42
|
-
|
|
80
|
+
// Fall back to the error message itself
|
|
81
|
+
const fallbackMessage = err.message || err.cause?.message || 'Unknown error';
|
|
82
|
+
throw new Error(`MorphoPDF API Error: ${fallbackMessage}`);
|
|
43
83
|
}
|
|
44
84
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../nodes/MorphoPdf/shared/errors.ts"],"names":[],"mappings":";;;AA2BA,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../nodes/MorphoPdf/shared/errors.ts"],"names":[],"mappings":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CAAC;QAED,kCAAkC;QAClC,IAAI,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACrC,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAChC,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC;oBAC1B,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;oBAC/B,MAAM,WAAW,GAAG,IAAI;wBACtB,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,WAAW,IAAI,EAAE;wBAC1C,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;oBACzB,MAAM,IAAI,KAAK,CAAC,wBAAwB,WAAW,EAAE,CAAC,CAAC;gBACzD,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,mCAAmC;YACrC,CAAC;QACH,CAAC;IACH,CAAC;IAED,wCAAwC;IACxC,MAAM,eAAe,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,KAAK,EAAE,OAAO,IAAI,eAAe,CAAC;IAC7E,MAAM,IAAI,KAAK,CAAC,wBAAwB,eAAe,EAAE,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for MorphoPDF AI Tool input
|
|
4
|
+
* Used by AI agents to process PDF files via the MorphoPDF API
|
|
5
|
+
*
|
|
6
|
+
* Design: Flat schema (no discriminated unions) for LLM compatibility.
|
|
7
|
+
* Each operation-specific parameter is optional with clear .describe() text
|
|
8
|
+
* explaining when it applies.
|
|
9
|
+
*/
|
|
10
|
+
export declare const morphoPdfToolSchema: z.ZodObject<{
|
|
11
|
+
operation: z.ZodEnum<["compress", "merge", "split", "rotate", "watermark", "pdfToWord", "pdfToExcel", "pdfToImage", "wordToPdf", "htmlToPdf"]>;
|
|
12
|
+
inputUrl: z.ZodOptional<z.ZodString>;
|
|
13
|
+
quality: z.ZodOptional<z.ZodEnum<["low", "medium", "high"]>>;
|
|
14
|
+
additionalUrls: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
15
|
+
splitMode: z.ZodOptional<z.ZodEnum<["ranges", "individual"]>>;
|
|
16
|
+
pageRanges: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
17
|
+
rotationAngle: z.ZodOptional<z.ZodEnum<["90", "180", "270"]>>;
|
|
18
|
+
watermarkText: z.ZodOptional<z.ZodString>;
|
|
19
|
+
watermarkPosition: z.ZodOptional<z.ZodEnum<["center", "top-left", "top-center", "top-right", "bottom-left", "bottom-center", "bottom-right"]>>;
|
|
20
|
+
watermarkOpacity: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
imageFormat: z.ZodOptional<z.ZodEnum<["png", "jpg"]>>;
|
|
22
|
+
dpi: z.ZodOptional<z.ZodEnum<["72", "96", "150", "300", "600"]>>;
|
|
23
|
+
htmlContent: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
operation: "compress" | "merge" | "rotate" | "split" | "watermark" | "pdfToExcel" | "pdfToImage" | "pdfToWord" | "htmlToPdf" | "wordToPdf";
|
|
26
|
+
quality?: "low" | "medium" | "high" | undefined;
|
|
27
|
+
splitMode?: "ranges" | "individual" | undefined;
|
|
28
|
+
watermarkText?: string | undefined;
|
|
29
|
+
watermarkPosition?: "bottom-center" | "bottom-left" | "bottom-right" | "center" | "top-center" | "top-left" | "top-right" | undefined;
|
|
30
|
+
watermarkOpacity?: number | undefined;
|
|
31
|
+
imageFormat?: "png" | "jpg" | undefined;
|
|
32
|
+
dpi?: "72" | "96" | "150" | "300" | "600" | undefined;
|
|
33
|
+
htmlContent?: string | undefined;
|
|
34
|
+
inputUrl?: string | undefined;
|
|
35
|
+
additionalUrls?: string[] | undefined;
|
|
36
|
+
pageRanges?: string[] | undefined;
|
|
37
|
+
rotationAngle?: "90" | "180" | "270" | undefined;
|
|
38
|
+
}, {
|
|
39
|
+
operation: "compress" | "merge" | "rotate" | "split" | "watermark" | "pdfToExcel" | "pdfToImage" | "pdfToWord" | "htmlToPdf" | "wordToPdf";
|
|
40
|
+
quality?: "low" | "medium" | "high" | undefined;
|
|
41
|
+
splitMode?: "ranges" | "individual" | undefined;
|
|
42
|
+
watermarkText?: string | undefined;
|
|
43
|
+
watermarkPosition?: "bottom-center" | "bottom-left" | "bottom-right" | "center" | "top-center" | "top-left" | "top-right" | undefined;
|
|
44
|
+
watermarkOpacity?: number | undefined;
|
|
45
|
+
imageFormat?: "png" | "jpg" | undefined;
|
|
46
|
+
dpi?: "72" | "96" | "150" | "300" | "600" | undefined;
|
|
47
|
+
htmlContent?: string | undefined;
|
|
48
|
+
inputUrl?: string | undefined;
|
|
49
|
+
additionalUrls?: string[] | undefined;
|
|
50
|
+
pageRanges?: string[] | undefined;
|
|
51
|
+
rotationAngle?: "90" | "180" | "270" | undefined;
|
|
52
|
+
}>;
|
|
53
|
+
/**
|
|
54
|
+
* TypeScript type inferred from the Zod schema
|
|
55
|
+
*/
|
|
56
|
+
export type MorphoPdfToolInput = z.infer<typeof morphoPdfToolSchema>;
|
|
57
|
+
/**
|
|
58
|
+
* API endpoint mapping for each operation
|
|
59
|
+
* Used to route requests to the correct MorphoPDF API endpoint
|
|
60
|
+
*/
|
|
61
|
+
export declare const operationEndpoints: Record<string, string>;
|
|
62
|
+
/**
|
|
63
|
+
* Format API response for LLM consumption
|
|
64
|
+
* Transforms raw API response into a structured, readable format
|
|
65
|
+
*
|
|
66
|
+
* @param operation - The operation that was performed
|
|
67
|
+
* @param response - Raw API response from MorphoPDF
|
|
68
|
+
* @returns Formatted response object suitable for LLM output
|
|
69
|
+
*/
|
|
70
|
+
export declare function formatToolResponse(operation: string, response: {
|
|
71
|
+
success?: boolean;
|
|
72
|
+
downloadUrl?: string;
|
|
73
|
+
fileName?: string;
|
|
74
|
+
error?: {
|
|
75
|
+
code?: string;
|
|
76
|
+
message?: string;
|
|
77
|
+
};
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
}): {
|
|
80
|
+
success: boolean;
|
|
81
|
+
operation: string;
|
|
82
|
+
operationName: string;
|
|
83
|
+
message: string;
|
|
84
|
+
downloadUrl?: string;
|
|
85
|
+
fileName?: string;
|
|
86
|
+
error?: {
|
|
87
|
+
code?: string;
|
|
88
|
+
message?: string;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=toolSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolSchema.d.ts","sourceRoot":"","sources":["../../../../nodes/MorphoPdf/shared/toolSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsK7B,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAErE;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAWrD,CAAC;AAkBF;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE;IACR,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,GACA;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C,CAqBA"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.operationEndpoints = exports.morphoPdfToolSchema = void 0;
|
|
4
|
+
exports.formatToolResponse = formatToolResponse;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
/**
|
|
7
|
+
* Zod schema for MorphoPDF AI Tool input
|
|
8
|
+
* Used by AI agents to process PDF files via the MorphoPDF API
|
|
9
|
+
*
|
|
10
|
+
* Design: Flat schema (no discriminated unions) for LLM compatibility.
|
|
11
|
+
* Each operation-specific parameter is optional with clear .describe() text
|
|
12
|
+
* explaining when it applies.
|
|
13
|
+
*/
|
|
14
|
+
exports.morphoPdfToolSchema = zod_1.z
|
|
15
|
+
.object({
|
|
16
|
+
operation: zod_1.z
|
|
17
|
+
.enum([
|
|
18
|
+
'compress',
|
|
19
|
+
'merge',
|
|
20
|
+
'split',
|
|
21
|
+
'rotate',
|
|
22
|
+
'watermark',
|
|
23
|
+
'pdfToWord',
|
|
24
|
+
'pdfToExcel',
|
|
25
|
+
'pdfToImage',
|
|
26
|
+
'wordToPdf',
|
|
27
|
+
'htmlToPdf',
|
|
28
|
+
])
|
|
29
|
+
.describe('The PDF operation to perform. ' +
|
|
30
|
+
'compress=reduce file size, ' +
|
|
31
|
+
'merge=combine multiple PDFs into one, ' +
|
|
32
|
+
'split=divide PDF into parts, ' +
|
|
33
|
+
'rotate=turn pages by angle, ' +
|
|
34
|
+
'watermark=add text overlay, ' +
|
|
35
|
+
'pdfToWord=convert PDF to DOCX, ' +
|
|
36
|
+
'pdfToExcel=extract tables to XLSX, ' +
|
|
37
|
+
'pdfToImage=convert pages to PNG/JPG, ' +
|
|
38
|
+
'wordToPdf=convert DOCX to PDF, ' +
|
|
39
|
+
'htmlToPdf=render HTML/URL to PDF'),
|
|
40
|
+
inputUrl: zod_1.z
|
|
41
|
+
.string()
|
|
42
|
+
.url()
|
|
43
|
+
.optional()
|
|
44
|
+
.describe('Public URL of the input file. Required for all operations EXCEPT htmlToPdf when using htmlContent. ' +
|
|
45
|
+
'For compress/split/rotate/watermark: must be a PDF URL. ' +
|
|
46
|
+
'For merge: the first PDF to merge (additional URLs go in additionalUrls). ' +
|
|
47
|
+
'For pdfToWord/pdfToExcel/pdfToImage: must be a PDF URL. ' +
|
|
48
|
+
'For wordToPdf: must be a DOCX URL. ' +
|
|
49
|
+
'For htmlToPdf: must be a webpage URL (or omit if using htmlContent).'),
|
|
50
|
+
// === COMPRESS OPERATION ===
|
|
51
|
+
quality: zod_1.z
|
|
52
|
+
.enum(['low', 'medium', 'high'])
|
|
53
|
+
.optional()
|
|
54
|
+
.describe('FOR COMPRESS ONLY. Compression quality level. ' +
|
|
55
|
+
'low=smallest file size (max compression, ~50 DPI), ' +
|
|
56
|
+
'medium=balanced quality and size (~100 DPI), ' +
|
|
57
|
+
'high=best quality, larger file (~150 DPI). ' +
|
|
58
|
+
'Default: low'),
|
|
59
|
+
// === MERGE OPERATION ===
|
|
60
|
+
additionalUrls: zod_1.z
|
|
61
|
+
.array(zod_1.z.string().url())
|
|
62
|
+
.optional()
|
|
63
|
+
.describe('FOR MERGE ONLY. Array of additional PDF URLs to combine with inputUrl. ' +
|
|
64
|
+
'Minimum 1 URL required. PDFs are merged in order: inputUrl first, then these URLs. ' +
|
|
65
|
+
'Example: ["https://example.com/doc2.pdf", "https://example.com/doc3.pdf"]'),
|
|
66
|
+
// === SPLIT OPERATION ===
|
|
67
|
+
splitMode: zod_1.z
|
|
68
|
+
.enum(['ranges', 'individual'])
|
|
69
|
+
.optional()
|
|
70
|
+
.describe('FOR SPLIT ONLY. How to split the PDF. ' +
|
|
71
|
+
'ranges=split by page ranges (use pageRanges param), ' +
|
|
72
|
+
'individual=extract each specified page as separate PDF. ' +
|
|
73
|
+
'Default: ranges'),
|
|
74
|
+
pageRanges: zod_1.z
|
|
75
|
+
.array(zod_1.z.string())
|
|
76
|
+
.optional()
|
|
77
|
+
.describe('FOR SPLIT ONLY (when splitMode=ranges). Array of page range strings. ' +
|
|
78
|
+
'Each range becomes a separate PDF file. ' +
|
|
79
|
+
'Example: ["1-3", "4-6", "7-10"] creates 3 PDFs. ' +
|
|
80
|
+
'Format: "start-end" (1-based page numbers).'),
|
|
81
|
+
// === ROTATE OPERATION ===
|
|
82
|
+
rotationAngle: zod_1.z
|
|
83
|
+
.enum(['90', '180', '270'])
|
|
84
|
+
.optional()
|
|
85
|
+
.describe('FOR ROTATE ONLY. Clockwise rotation angle in degrees. ' +
|
|
86
|
+
'90=quarter turn right, 180=upside down, 270=quarter turn left. ' +
|
|
87
|
+
'Applied to all pages. Default: 90'),
|
|
88
|
+
// === WATERMARK OPERATION ===
|
|
89
|
+
watermarkText: zod_1.z
|
|
90
|
+
.string()
|
|
91
|
+
.optional()
|
|
92
|
+
.describe('FOR WATERMARK ONLY. Text to overlay on pages. ' +
|
|
93
|
+
'Example: "CONFIDENTIAL", "DRAFT", "SAMPLE". ' +
|
|
94
|
+
'Required when using watermark operation.'),
|
|
95
|
+
watermarkPosition: zod_1.z
|
|
96
|
+
.enum([
|
|
97
|
+
'center',
|
|
98
|
+
'top-left',
|
|
99
|
+
'top-center',
|
|
100
|
+
'top-right',
|
|
101
|
+
'bottom-left',
|
|
102
|
+
'bottom-center',
|
|
103
|
+
'bottom-right',
|
|
104
|
+
])
|
|
105
|
+
.optional()
|
|
106
|
+
.describe('FOR WATERMARK ONLY. Where to place the watermark on each page. ' + 'Default: center'),
|
|
107
|
+
watermarkOpacity: zod_1.z
|
|
108
|
+
.number()
|
|
109
|
+
.min(0)
|
|
110
|
+
.max(1)
|
|
111
|
+
.optional()
|
|
112
|
+
.describe('FOR WATERMARK ONLY. Transparency of watermark (0=invisible, 1=fully opaque). ' +
|
|
113
|
+
'Typical values: 0.1-0.3 for subtle watermarks. Default: 0.3'),
|
|
114
|
+
// === PDF TO IMAGE OPERATION ===
|
|
115
|
+
imageFormat: zod_1.z
|
|
116
|
+
.enum(['png', 'jpg'])
|
|
117
|
+
.optional()
|
|
118
|
+
.describe('FOR PDF_TO_IMAGE ONLY. Output image format. ' +
|
|
119
|
+
'png=lossless, larger files, supports transparency. ' +
|
|
120
|
+
'jpg=lossy compression, smaller files. ' +
|
|
121
|
+
'Default: png'),
|
|
122
|
+
dpi: zod_1.z
|
|
123
|
+
.enum(['72', '96', '150', '300', '600'])
|
|
124
|
+
.optional()
|
|
125
|
+
.describe('FOR PDF_TO_IMAGE ONLY. Resolution in dots per inch. ' +
|
|
126
|
+
'72=screen/web preview, 96=standard web, 150=good quality, ' +
|
|
127
|
+
'300=print quality, 600=high-quality print. ' +
|
|
128
|
+
'Higher DPI = larger files. Default: 150'),
|
|
129
|
+
// === HTML TO PDF OPERATION ===
|
|
130
|
+
htmlContent: zod_1.z
|
|
131
|
+
.string()
|
|
132
|
+
.optional()
|
|
133
|
+
.describe('FOR HTML_TO_PDF ONLY. Raw HTML content to convert to PDF. ' +
|
|
134
|
+
'Use this instead of inputUrl when you have HTML as a string. ' +
|
|
135
|
+
'Example: "<html><body><h1>Hello World</h1></body></html>". ' +
|
|
136
|
+
'Either inputUrl OR htmlContent is required for htmlToPdf.'),
|
|
137
|
+
})
|
|
138
|
+
.describe('MorphoPDF AI Tool - Process PDF files with various operations. ' +
|
|
139
|
+
'Supports compression, merging, splitting, rotation, watermarking, ' +
|
|
140
|
+
'and format conversions (PDF to Word/Excel/Image, Word/HTML to PDF).');
|
|
141
|
+
/**
|
|
142
|
+
* API endpoint mapping for each operation
|
|
143
|
+
* Used to route requests to the correct MorphoPDF API endpoint
|
|
144
|
+
*/
|
|
145
|
+
exports.operationEndpoints = {
|
|
146
|
+
compress: '/pdf/compress',
|
|
147
|
+
merge: '/pdf/merge',
|
|
148
|
+
split: '/pdf/split',
|
|
149
|
+
rotate: '/pdf/rotate',
|
|
150
|
+
watermark: '/pdf/watermark',
|
|
151
|
+
pdfToWord: '/convert/pdf-to-word',
|
|
152
|
+
pdfToExcel: '/convert/pdf-to-excel',
|
|
153
|
+
pdfToImage: '/convert/pdf-to-image',
|
|
154
|
+
wordToPdf: '/convert/word-to-pdf',
|
|
155
|
+
htmlToPdf: '/convert/html-to-pdf',
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Human-readable operation names for response formatting
|
|
159
|
+
*/
|
|
160
|
+
const operationNames = {
|
|
161
|
+
compress: 'PDF Compression',
|
|
162
|
+
merge: 'PDF Merge',
|
|
163
|
+
split: 'PDF Split',
|
|
164
|
+
rotate: 'PDF Rotation',
|
|
165
|
+
watermark: 'PDF Watermarking',
|
|
166
|
+
pdfToWord: 'PDF to Word Conversion',
|
|
167
|
+
pdfToExcel: 'PDF to Excel Conversion',
|
|
168
|
+
pdfToImage: 'PDF to Image Conversion',
|
|
169
|
+
wordToPdf: 'Word to PDF Conversion',
|
|
170
|
+
htmlToPdf: 'HTML to PDF Conversion',
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Format API response for LLM consumption
|
|
174
|
+
* Transforms raw API response into a structured, readable format
|
|
175
|
+
*
|
|
176
|
+
* @param operation - The operation that was performed
|
|
177
|
+
* @param response - Raw API response from MorphoPDF
|
|
178
|
+
* @returns Formatted response object suitable for LLM output
|
|
179
|
+
*/
|
|
180
|
+
function formatToolResponse(operation, response) {
|
|
181
|
+
const operationName = operationNames[operation] || operation;
|
|
182
|
+
if (response.success === false || response.error) {
|
|
183
|
+
return {
|
|
184
|
+
success: false,
|
|
185
|
+
operation,
|
|
186
|
+
operationName,
|
|
187
|
+
message: `${operationName} failed: ${response.error?.message || 'Unknown error'}`,
|
|
188
|
+
error: response.error,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
success: true,
|
|
193
|
+
operation,
|
|
194
|
+
operationName,
|
|
195
|
+
message: `${operationName} completed successfully.`,
|
|
196
|
+
downloadUrl: response.downloadUrl,
|
|
197
|
+
fileName: response.fileName,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=toolSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolSchema.js","sourceRoot":"","sources":["../../../../nodes/MorphoPdf/shared/toolSchema.ts"],"names":[],"mappings":";;;AAgOA,gDAsCC;AAtQD,6BAAwB;AAExB;;;;;;;GAOG;AACU,QAAA,mBAAmB,GAAG,OAAC;KACjC,MAAM,CAAC;IACN,SAAS,EAAE,OAAC;SACT,IAAI,CAAC;QACJ,UAAU;QACV,OAAO;QACP,OAAO;QACP,QAAQ;QACR,WAAW;QACX,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,WAAW;QACX,WAAW;KACZ,CAAC;SACD,QAAQ,CACP,gCAAgC;QAC9B,6BAA6B;QAC7B,wCAAwC;QACxC,+BAA+B;QAC/B,8BAA8B;QAC9B,8BAA8B;QAC9B,iCAAiC;QACjC,qCAAqC;QACrC,uCAAuC;QACvC,iCAAiC;QACjC,kCAAkC,CACrC;IAEH,QAAQ,EAAE,OAAC;SACR,MAAM,EAAE;SACR,GAAG,EAAE;SACL,QAAQ,EAAE;SACV,QAAQ,CACP,qGAAqG;QACnG,0DAA0D;QAC1D,4EAA4E;QAC5E,0DAA0D;QAC1D,qCAAqC;QACrC,sEAAsE,CACzE;IAEH,6BAA6B;IAC7B,OAAO,EAAE,OAAC;SACP,IAAI,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;SAC/B,QAAQ,EAAE;SACV,QAAQ,CACP,gDAAgD;QAC9C,qDAAqD;QACrD,+CAA+C;QAC/C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BAAwB;IACnC,SAAS,EAAE,wBAAwB;CACpC,CAAC;AAEF;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,SAAiB,EACjB,QAMC;IAUD,MAAM,aAAa,GAAG,cAAc,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC;IAE7D,IAAI,QAAQ,CAAC,OAAO,KAAK,KAAK,IAAI,QAAQ,CAAC,KAAK,EAAE,CAAC;QACjD,OAAO;YACL,OAAO,EAAE,KAAK;YACd,SAAS;YACT,aAAa;YACb,OAAO,EAAE,GAAG,aAAa,YAAY,QAAQ,CAAC,KAAK,EAAE,OAAO,IAAI,eAAe,EAAE;YACjF,KAAK,EAAE,QAAQ,CAAC,KAAK;SACtB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,SAAS;QACT,aAAa;QACb,OAAO,EAAE,GAAG,aAAa,0BAA0B;QACnD,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,QAAQ,EAAE,QAAQ,CAAC,QAAQ;KAC5B,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-morphopdf",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "n8n community node for MorphoPDF - Professional PDF processing and conversion",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"n8n-community-node-package",
|
|
@@ -44,9 +44,14 @@
|
|
|
44
44
|
"dist/credentials/MorphoPdfApi.credentials.js"
|
|
45
45
|
],
|
|
46
46
|
"nodes": [
|
|
47
|
-
"dist/nodes/MorphoPdf/MorphoPdf.node.js"
|
|
47
|
+
"dist/nodes/MorphoPdf/MorphoPdf.node.js",
|
|
48
|
+
"dist/nodes/MorphoPdf/MorphoPdfTool.node.js"
|
|
48
49
|
]
|
|
49
50
|
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@langchain/core": "^0.3.0",
|
|
53
|
+
"zod": "^3.23.0"
|
|
54
|
+
},
|
|
50
55
|
"devDependencies": {
|
|
51
56
|
"@n8n/node-cli": "*",
|
|
52
57
|
"@types/node": "^25.1.0",
|