n8n-nodes-kapacity 0.1.0 → 0.1.2
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/README.md
CHANGED
|
@@ -56,7 +56,12 @@ Starts a workflow when something happens in Kapacity:
|
|
|
56
56
|
|
|
57
57
|
Contact Created, Contact Updated, Row Created, Row Updated, Appointment Booked, Appointment Rescheduled, Appointment Canceled, Form Submitted, Contract Sent, Contract Signed, Payment Received.
|
|
58
58
|
|
|
59
|
-
The trigger registers its webhook in Kapacity when the workflow is activated, and deletes it when the workflow is deactivated.
|
|
59
|
+
The trigger registers its webhook in Kapacity when the workflow is activated, and deletes it when the workflow is deactivated. You see it in Kapacity, page **Intégrations**, card **Webhooks**, as "n8n · your workflow name".
|
|
60
|
+
|
|
61
|
+
Only Kapacity can start the workflow. Every call is checked twice, and refused (401) if either check fails:
|
|
62
|
+
|
|
63
|
+
- **A secret header**, `X-Kapacity-Key`, unique to each webhook and generated by the trigger.
|
|
64
|
+
- **The signature** of the call ([Standard Webhooks](https://www.standardwebhooks.com/)), made with a secret that Kapacity gives only once, when the webhook is created. It also refuses a changed body and a call replayed more than 5 minutes later.
|
|
60
65
|
|
|
61
66
|
**Ignore Changes Made by the API** is on by default. Keep it on when the same workflow writes to Kapacity, otherwise it would start itself again, endlessly.
|
|
62
67
|
|
|
@@ -96,6 +101,14 @@ The API has a monthly quota per workspace. Each call counts, so prefer the trigg
|
|
|
96
101
|
|
|
97
102
|
## Version history
|
|
98
103
|
|
|
104
|
+
### 0.1.2
|
|
105
|
+
|
|
106
|
+
Kapacity Trigger: replacing an outdated webhook no longer hides a failed deletion. Only a 404 is ignored, so an event can never fire the workflow twice.
|
|
107
|
+
|
|
108
|
+
### 0.1.1
|
|
109
|
+
|
|
110
|
+
Kapacity Trigger: each webhook gets its own secret header, checked on every call on top of the signature. A webhook created by 0.1.0 is recreated with it the next time the workflow is activated. The event names are shown under the node.
|
|
111
|
+
|
|
99
112
|
### 0.1.0
|
|
100
113
|
|
|
101
114
|
First release: Kapacity node (13 resources) and Kapacity Trigger (11 events).
|
|
@@ -18,7 +18,15 @@ const EVENTS = [
|
|
|
18
18
|
{ name: 'Payment Received', value: 'paiement.recu', description: 'A payment is received' },
|
|
19
19
|
];
|
|
20
20
|
const TIMESTAMP_TOLERANCE_SEC = 300;
|
|
21
|
+
const KEY_HEADER = 'X-Kapacity-Key';
|
|
21
22
|
const sameEvents = (a, b) => a.length === b.length && a.every((e) => b.includes(e));
|
|
23
|
+
const EVENT_NAMES = Object.fromEntries(EVENTS.map((e) => [e.value, e.name]));
|
|
24
|
+
const SUBTITLE = `={{$parameter["events"].map(e => (${JSON.stringify(EVENT_NAMES)})[e] || e).join(", ")}}`;
|
|
25
|
+
function sameSecret(given, expected) {
|
|
26
|
+
const a = Buffer.from(given);
|
|
27
|
+
const b = Buffer.from(expected);
|
|
28
|
+
return a.length === b.length && (0, crypto_1.timingSafeEqual)(a, b);
|
|
29
|
+
}
|
|
22
30
|
class KapacityTrigger {
|
|
23
31
|
constructor() {
|
|
24
32
|
this.description = {
|
|
@@ -27,7 +35,7 @@ class KapacityTrigger {
|
|
|
27
35
|
icon: { light: 'file:../../icons/kapacity.svg', dark: 'file:../../icons/kapacity.dark.svg' },
|
|
28
36
|
group: ['trigger'],
|
|
29
37
|
version: 1,
|
|
30
|
-
subtitle:
|
|
38
|
+
subtitle: SUBTITLE,
|
|
31
39
|
description: 'Starts the workflow when something happens in Kapacity',
|
|
32
40
|
defaults: { name: 'Kapacity Trigger' },
|
|
33
41
|
inputs: [],
|
|
@@ -73,13 +81,24 @@ class KapacityTrigger {
|
|
|
73
81
|
const hooks = (_a = response.webhooks) !== null && _a !== void 0 ? _a : [];
|
|
74
82
|
const hook = hooks.find((h) => h.id === data.webhookId);
|
|
75
83
|
const events = this.getNodeParameter('events');
|
|
76
|
-
if (hook &&
|
|
84
|
+
if (hook &&
|
|
85
|
+
hook.url === this.getNodeWebhookUrl('default') &&
|
|
86
|
+
sameEvents(hook.evenements, events) &&
|
|
87
|
+
hook.entete_nom === KEY_HEADER &&
|
|
88
|
+
!!data.headerKey) {
|
|
77
89
|
return true;
|
|
78
90
|
}
|
|
79
|
-
if (hook)
|
|
80
|
-
await transport_1.kapacityApiRequest
|
|
91
|
+
if (hook) {
|
|
92
|
+
await transport_1.kapacityApiRequest
|
|
93
|
+
.call(this, 'DELETE', `/webhooks/${data.webhookId}`)
|
|
94
|
+
.catch((error) => {
|
|
95
|
+
if (error.httpCode !== '404')
|
|
96
|
+
throw error;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
81
99
|
delete data.webhookId;
|
|
82
100
|
delete data.secret;
|
|
101
|
+
delete data.headerKey;
|
|
83
102
|
return false;
|
|
84
103
|
},
|
|
85
104
|
async create() {
|
|
@@ -89,11 +108,13 @@ class KapacityTrigger {
|
|
|
89
108
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Choose at least one event');
|
|
90
109
|
const options = this.getNodeParameter('options', {});
|
|
91
110
|
const workflowName = (_a = this.getWorkflow().name) !== null && _a !== void 0 ? _a : '';
|
|
111
|
+
const headerKey = (0, crypto_1.randomBytes)(32).toString('base64url');
|
|
92
112
|
const body = {
|
|
93
113
|
nom: `n8n · ${workflowName || 'workflow'}`.slice(0, 80),
|
|
94
114
|
url: this.getNodeWebhookUrl('default'),
|
|
95
115
|
evenements: events,
|
|
96
116
|
ignorer_api: options.ignoreApiWrites !== false,
|
|
117
|
+
entete: { nom: KEY_HEADER, valeur: headerKey },
|
|
97
118
|
description: 'Created by the n8n Kapacity Trigger. Deactivating the workflow deletes it.',
|
|
98
119
|
};
|
|
99
120
|
let response;
|
|
@@ -112,6 +133,7 @@ class KapacityTrigger {
|
|
|
112
133
|
const data = this.getWorkflowStaticData('node');
|
|
113
134
|
data.webhookId = String(response.webhook.id);
|
|
114
135
|
data.secret = String(response.secret);
|
|
136
|
+
data.headerKey = headerKey;
|
|
115
137
|
return true;
|
|
116
138
|
},
|
|
117
139
|
async delete() {
|
|
@@ -128,6 +150,7 @@ class KapacityTrigger {
|
|
|
128
150
|
}
|
|
129
151
|
delete data.webhookId;
|
|
130
152
|
delete data.secret;
|
|
153
|
+
delete data.headerKey;
|
|
131
154
|
return true;
|
|
132
155
|
},
|
|
133
156
|
},
|
|
@@ -138,6 +161,15 @@ class KapacityTrigger {
|
|
|
138
161
|
const data = this.getWorkflowStaticData('node');
|
|
139
162
|
const request = this.getRequestObject();
|
|
140
163
|
const body = this.getBodyData();
|
|
164
|
+
const refuse = (error) => {
|
|
165
|
+
this.getResponseObject().status(401).json({ error });
|
|
166
|
+
return { noWebhookResponse: true };
|
|
167
|
+
};
|
|
168
|
+
if (data.headerKey) {
|
|
169
|
+
const given = this.getHeaderData()[KEY_HEADER.toLowerCase()];
|
|
170
|
+
if (typeof given !== 'string' || !sameSecret(given, data.headerKey))
|
|
171
|
+
return refuse('Invalid key');
|
|
172
|
+
}
|
|
141
173
|
if (data.secret) {
|
|
142
174
|
const headers = this.getHeaderData();
|
|
143
175
|
const id = String((_a = headers['webhook-id']) !== null && _a !== void 0 ? _a : '');
|
|
@@ -145,11 +177,8 @@ class KapacityTrigger {
|
|
|
145
177
|
const signatures = String((_c = headers['webhook-signature']) !== null && _c !== void 0 ? _c : '');
|
|
146
178
|
const rawBody = request.rawBody;
|
|
147
179
|
const payload = rawBody ? rawBody.toString('utf8') : JSON.stringify(body);
|
|
148
|
-
if (!verifySignature(data.secret, id, timestamp, payload, signatures))
|
|
149
|
-
|
|
150
|
-
response.status(401).json({ error: 'Invalid signature' });
|
|
151
|
-
return { noWebhookResponse: true };
|
|
152
|
-
}
|
|
180
|
+
if (!verifySignature(data.secret, id, timestamp, payload, signatures))
|
|
181
|
+
return refuse('Invalid signature');
|
|
153
182
|
}
|
|
154
183
|
const headers = this.getHeaderData();
|
|
155
184
|
return {
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-kapacity",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "n8n nodes for Kapacity, the all-in-one sales CRM: contacts, CRM tables, contracts with e-signature, appointments, forms, payments and real-time webhooks.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/kapacity-saas/n8n-nodes-kapacity#readme",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-kapacity",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "n8n nodes for Kapacity, the all-in-one sales CRM: contacts, CRM tables, contracts with e-signature, appointments, forms, payments and real-time webhooks.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/kapacity-saas/n8n-nodes-kapacity#readme",
|