n8n-nodes-pdfkraft 0.1.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.
@@ -0,0 +1,7 @@
1
+ import type { ICredentialType, INodeProperties } from 'n8n-workflow';
2
+ export declare class PDFKraftApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ documentationUrl: string;
6
+ properties: INodeProperties[];
7
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PDFKraftApi = void 0;
4
+ class PDFKraftApi {
5
+ constructor() {
6
+ this.name = 'pdfKraftApi';
7
+ this.displayName = 'PDFKraft API';
8
+ this.documentationUrl = 'https://api.pdfkraft.com/api/docs';
9
+ this.properties = [
10
+ {
11
+ displayName: 'API Key',
12
+ name: 'apiKey',
13
+ type: 'string',
14
+ typeOptions: { password: true },
15
+ default: '',
16
+ required: true,
17
+ },
18
+ {
19
+ displayName: 'Base URL',
20
+ name: 'baseUrl',
21
+ type: 'string',
22
+ default: 'https://api.pdfkraft.com/api/v1',
23
+ },
24
+ ];
25
+ }
26
+ }
27
+ exports.PDFKraftApi = PDFKraftApi;
@@ -0,0 +1,3 @@
1
+ export { PDFKraftApi } from './credentials/PDFKraftApi.credentials';
2
+ export { PDFKraft } from './nodes/PDFKraft/PDFKraft.node';
3
+ export { PDFKraftTrigger } from './nodes/PDFKraftTrigger/PDFKraftTrigger.node';
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PDFKraftTrigger = exports.PDFKraft = exports.PDFKraftApi = void 0;
4
+ var PDFKraftApi_credentials_1 = require("./credentials/PDFKraftApi.credentials");
5
+ Object.defineProperty(exports, "PDFKraftApi", { enumerable: true, get: function () { return PDFKraftApi_credentials_1.PDFKraftApi; } });
6
+ var PDFKraft_node_1 = require("./nodes/PDFKraft/PDFKraft.node");
7
+ Object.defineProperty(exports, "PDFKraft", { enumerable: true, get: function () { return PDFKraft_node_1.PDFKraft; } });
8
+ var PDFKraftTrigger_node_1 = require("./nodes/PDFKraftTrigger/PDFKraftTrigger.node");
9
+ Object.defineProperty(exports, "PDFKraftTrigger", { enumerable: true, get: function () { return PDFKraftTrigger_node_1.PDFKraftTrigger; } });
@@ -0,0 +1,5 @@
1
+ import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow';
2
+ export declare class PDFKraft implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PDFKraft = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ class PDFKraft {
6
+ constructor() {
7
+ this.description = {
8
+ displayName: 'PDFKraft',
9
+ name: 'pdfKraft',
10
+ icon: 'file:pdfkraft.svg',
11
+ group: ['output'],
12
+ version: 1,
13
+ subtitle: '={{$parameter["operation"]}}',
14
+ description: 'Generate PDFs and images with PDFKraft',
15
+ defaults: { name: 'PDFKraft' },
16
+ inputs: [n8n_workflow_1.NodeConnectionTypes.Main],
17
+ outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
18
+ credentials: [{ name: 'pdfKraftApi', required: true }],
19
+ properties: [
20
+ {
21
+ displayName: 'Operation',
22
+ name: 'operation',
23
+ type: 'options',
24
+ noDataExpression: true,
25
+ options: [
26
+ { name: 'Generate Document', value: 'generateDocument', description: 'Generate a PDF or image from a template' },
27
+ { name: 'Generate Document (Sync)', value: 'generateDocumentSync', description: 'Generate and wait for the result' },
28
+ { name: 'Get Document', value: 'getDocument', description: 'Get document status and download URL' },
29
+ { name: 'List Templates', value: 'listTemplates', description: 'List all available templates' },
30
+ { name: 'Download Document', value: 'downloadDocument', description: 'Download document as binary data' },
31
+ ],
32
+ default: 'generateDocument',
33
+ },
34
+ // generateDocument / generateDocumentSync fields
35
+ {
36
+ displayName: 'Template ID',
37
+ name: 'templateId',
38
+ type: 'string',
39
+ default: '',
40
+ required: true,
41
+ displayOptions: { show: { operation: ['generateDocument', 'generateDocumentSync'] } },
42
+ description: 'The UUID of the template to use',
43
+ },
44
+ {
45
+ displayName: 'Payload',
46
+ name: 'payload',
47
+ type: 'json',
48
+ default: '{}',
49
+ displayOptions: { show: { operation: ['generateDocument', 'generateDocumentSync'] } },
50
+ description: 'JSON data to merge into the template',
51
+ },
52
+ {
53
+ displayName: 'Filename',
54
+ name: 'filename',
55
+ type: 'string',
56
+ default: '',
57
+ displayOptions: { show: { operation: ['generateDocument', 'generateDocumentSync'] } },
58
+ description: 'Output filename. Supports {{variable}} from payload.',
59
+ },
60
+ {
61
+ displayName: 'Meta',
62
+ name: 'meta',
63
+ type: 'json',
64
+ default: '{}',
65
+ displayOptions: { show: { operation: ['generateDocument', 'generateDocumentSync'] } },
66
+ },
67
+ // getDocument / downloadDocument fields
68
+ {
69
+ displayName: 'Document ID',
70
+ name: 'documentId',
71
+ type: 'string',
72
+ default: '',
73
+ required: true,
74
+ displayOptions: { show: { operation: ['getDocument', 'downloadDocument'] } },
75
+ },
76
+ ],
77
+ };
78
+ }
79
+ async execute() {
80
+ const items = this.getInputData();
81
+ const results = [];
82
+ const credentials = await this.getCredentials('pdfKraftApi');
83
+ const baseUrl = credentials.baseUrl.replace(/\/$/, '');
84
+ const apiKey = credentials.apiKey;
85
+ const headers = {
86
+ Authorization: `Bearer ${apiKey}`,
87
+ 'Content-Type': 'application/json',
88
+ };
89
+ for (let i = 0; i < items.length; i++) {
90
+ const operation = this.getNodeParameter('operation', i);
91
+ if (operation === 'generateDocument' || operation === 'generateDocumentSync') {
92
+ const templateId = this.getNodeParameter('templateId', i);
93
+ const payloadRaw = this.getNodeParameter('payload', i);
94
+ const filename = this.getNodeParameter('filename', i);
95
+ const metaRaw = this.getNodeParameter('meta', i);
96
+ const payload = typeof payloadRaw === 'string' ? JSON.parse(payloadRaw) : payloadRaw;
97
+ const meta = typeof metaRaw === 'string' ? JSON.parse(metaRaw) : metaRaw;
98
+ const body = { document_template_id: templateId, payload, meta };
99
+ if (filename)
100
+ body.filename = filename;
101
+ const endpoint = operation === 'generateDocumentSync' ? '/documents/sync' : '/documents';
102
+ const response = await this.helpers.request({
103
+ method: 'POST',
104
+ url: `${baseUrl}${endpoint}`,
105
+ headers,
106
+ body: JSON.stringify(body),
107
+ json: true,
108
+ });
109
+ results.push({ json: response });
110
+ }
111
+ if (operation === 'getDocument') {
112
+ const documentId = this.getNodeParameter('documentId', i);
113
+ const response = await this.helpers.request({
114
+ method: 'GET',
115
+ url: `${baseUrl}/document_cards/${documentId}`,
116
+ headers,
117
+ json: true,
118
+ });
119
+ results.push({ json: response });
120
+ }
121
+ if (operation === 'listTemplates') {
122
+ const response = await this.helpers.request({
123
+ method: 'GET',
124
+ url: `${baseUrl}/document_template_cards`,
125
+ headers,
126
+ json: true,
127
+ });
128
+ const res = response;
129
+ for (const t of res.data ?? []) {
130
+ results.push({ json: t });
131
+ }
132
+ }
133
+ if (operation === 'downloadDocument') {
134
+ const documentId = this.getNodeParameter('documentId', i);
135
+ const buffer = await this.helpers.request({
136
+ method: 'GET',
137
+ url: `${baseUrl}/documents/${documentId}/download`,
138
+ headers: { Authorization: `Bearer ${apiKey}` },
139
+ encoding: null,
140
+ resolveWithFullResponse: false,
141
+ });
142
+ const binaryData = await this.helpers.prepareBinaryData(buffer, 'document.pdf', 'application/pdf');
143
+ results.push({ json: { documentId }, binary: { data: binaryData } });
144
+ }
145
+ }
146
+ return [results];
147
+ }
148
+ }
149
+ exports.PDFKraft = PDFKraft;
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>
@@ -0,0 +1,12 @@
1
+ import type { IHookFunctions, IWebhookFunctions, INodeType, INodeTypeDescription, IWebhookResponseData } from 'n8n-workflow';
2
+ export declare class PDFKraftTrigger implements INodeType {
3
+ description: INodeTypeDescription;
4
+ webhookMethods: {
5
+ default: {
6
+ checkExists(this: IHookFunctions): Promise<boolean>;
7
+ create(this: IHookFunctions): Promise<boolean>;
8
+ delete(this: IHookFunctions): Promise<boolean>;
9
+ };
10
+ };
11
+ webhook(this: IWebhookFunctions): Promise<IWebhookResponseData>;
12
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PDFKraftTrigger = void 0;
7
+ const n8n_workflow_1 = require("n8n-workflow");
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ class PDFKraftTrigger {
10
+ constructor() {
11
+ this.description = {
12
+ displayName: 'PDFKraft Trigger',
13
+ name: 'pdfKraftTrigger',
14
+ icon: 'file:pdfkraft.svg',
15
+ group: ['trigger'],
16
+ version: 1,
17
+ description: 'Receive PDFKraft webhook events when documents are generated',
18
+ defaults: { name: 'PDFKraft Trigger' },
19
+ inputs: [],
20
+ outputs: [n8n_workflow_1.NodeConnectionTypes.Main],
21
+ credentials: [{ name: 'pdfKraftApi', required: true }],
22
+ webhooks: [{ name: 'default', httpMethod: 'POST', responseMode: 'onReceived', path: 'webhook' }],
23
+ properties: [
24
+ {
25
+ displayName: 'Webhook Secret',
26
+ name: 'webhookSecret',
27
+ type: 'string',
28
+ typeOptions: { password: true },
29
+ default: '',
30
+ description: 'The secret shown when you created the webhook endpoint in PDFKraft',
31
+ },
32
+ {
33
+ displayName: 'Verify Signature',
34
+ name: 'verifySignature',
35
+ type: 'boolean',
36
+ default: true,
37
+ },
38
+ ],
39
+ };
40
+ this.webhookMethods = {
41
+ default: {
42
+ async checkExists() { return false; },
43
+ async create() { return true; },
44
+ async delete() { return true; },
45
+ },
46
+ };
47
+ }
48
+ async webhook() {
49
+ const req = this.getRequestObject();
50
+ const verifySignature = this.getNodeParameter('verifySignature');
51
+ const secret = this.getNodeParameter('webhookSecret');
52
+ if (verifySignature && secret) {
53
+ const signature = req.headers['x-pdfkraft-signature'];
54
+ const timestamp = req.headers['x-pdfkraft-timestamp'];
55
+ const rawBody = JSON.stringify(req.body);
56
+ const expected = crypto_1.default
57
+ .createHmac('sha256', secret)
58
+ .update(`${timestamp}.${rawBody}`)
59
+ .digest('hex');
60
+ if (!crypto_1.default.timingSafeEqual(Buffer.from(signature ?? '', 'hex'), Buffer.from(expected, 'hex'))) {
61
+ return { webhookResponse: { statusCode: 401 } };
62
+ }
63
+ }
64
+ return {
65
+ workflowData: [[{ json: req.body }]],
66
+ };
67
+ }
68
+ }
69
+ exports.PDFKraftTrigger = PDFKraftTrigger;
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/><polyline points="10 9 9 9 8 9"/></svg>
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "n8n-nodes-pdfkraft",
3
+ "version": "0.1.0",
4
+ "description": "n8n community node for PDFKraft — generate PDFs and images via the PDFKraft API",
5
+ "keywords": ["n8n-community-node-package"],
6
+ "main": "dist/index.js",
7
+ "scripts": {
8
+ "build": "tsc && cp src/nodes/PDFKraft/pdfkraft.svg dist/nodes/PDFKraft/ && cp src/nodes/PDFKraftTrigger/pdfkraft.svg dist/nodes/PDFKraftTrigger/",
9
+ "type-check": "tsc --noEmit",
10
+ "clean": "rm -rf dist"
11
+ },
12
+ "devDependencies": {
13
+ "typescript": "^5.8.3",
14
+ "n8n-workflow": "*"
15
+ },
16
+ "n8n": {
17
+ "n8nNodesApiVersion": 1,
18
+ "credentials": ["dist/credentials/PDFKraftApi.credentials.js"],
19
+ "nodes": ["dist/nodes/PDFKraft/PDFKraft.node.js", "dist/nodes/PDFKraftTrigger/PDFKraftTrigger.node.js"]
20
+ },
21
+ "files": ["dist"]
22
+ }