n8n-nodes-kapacity 0.1.0 → 0.1.1
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,10 @@ 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.1
|
|
105
|
+
|
|
106
|
+
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.
|
|
107
|
+
|
|
99
108
|
### 0.1.0
|
|
100
109
|
|
|
101
110
|
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,18 @@ 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
91
|
if (hook)
|
|
80
92
|
await transport_1.kapacityApiRequest.call(this, 'DELETE', `/webhooks/${data.webhookId}`).catch(() => undefined);
|
|
81
93
|
delete data.webhookId;
|
|
82
94
|
delete data.secret;
|
|
95
|
+
delete data.headerKey;
|
|
83
96
|
return false;
|
|
84
97
|
},
|
|
85
98
|
async create() {
|
|
@@ -89,11 +102,13 @@ class KapacityTrigger {
|
|
|
89
102
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Choose at least one event');
|
|
90
103
|
const options = this.getNodeParameter('options', {});
|
|
91
104
|
const workflowName = (_a = this.getWorkflow().name) !== null && _a !== void 0 ? _a : '';
|
|
105
|
+
const headerKey = (0, crypto_1.randomBytes)(32).toString('base64url');
|
|
92
106
|
const body = {
|
|
93
107
|
nom: `n8n · ${workflowName || 'workflow'}`.slice(0, 80),
|
|
94
108
|
url: this.getNodeWebhookUrl('default'),
|
|
95
109
|
evenements: events,
|
|
96
110
|
ignorer_api: options.ignoreApiWrites !== false,
|
|
111
|
+
entete: { nom: KEY_HEADER, valeur: headerKey },
|
|
97
112
|
description: 'Created by the n8n Kapacity Trigger. Deactivating the workflow deletes it.',
|
|
98
113
|
};
|
|
99
114
|
let response;
|
|
@@ -112,6 +127,7 @@ class KapacityTrigger {
|
|
|
112
127
|
const data = this.getWorkflowStaticData('node');
|
|
113
128
|
data.webhookId = String(response.webhook.id);
|
|
114
129
|
data.secret = String(response.secret);
|
|
130
|
+
data.headerKey = headerKey;
|
|
115
131
|
return true;
|
|
116
132
|
},
|
|
117
133
|
async delete() {
|
|
@@ -128,6 +144,7 @@ class KapacityTrigger {
|
|
|
128
144
|
}
|
|
129
145
|
delete data.webhookId;
|
|
130
146
|
delete data.secret;
|
|
147
|
+
delete data.headerKey;
|
|
131
148
|
return true;
|
|
132
149
|
},
|
|
133
150
|
},
|
|
@@ -138,6 +155,15 @@ class KapacityTrigger {
|
|
|
138
155
|
const data = this.getWorkflowStaticData('node');
|
|
139
156
|
const request = this.getRequestObject();
|
|
140
157
|
const body = this.getBodyData();
|
|
158
|
+
const refuse = (error) => {
|
|
159
|
+
this.getResponseObject().status(401).json({ error });
|
|
160
|
+
return { noWebhookResponse: true };
|
|
161
|
+
};
|
|
162
|
+
if (data.headerKey) {
|
|
163
|
+
const given = this.getHeaderData()[KEY_HEADER.toLowerCase()];
|
|
164
|
+
if (typeof given !== 'string' || !sameSecret(given, data.headerKey))
|
|
165
|
+
return refuse('Invalid key');
|
|
166
|
+
}
|
|
141
167
|
if (data.secret) {
|
|
142
168
|
const headers = this.getHeaderData();
|
|
143
169
|
const id = String((_a = headers['webhook-id']) !== null && _a !== void 0 ? _a : '');
|
|
@@ -145,11 +171,8 @@ class KapacityTrigger {
|
|
|
145
171
|
const signatures = String((_c = headers['webhook-signature']) !== null && _c !== void 0 ? _c : '');
|
|
146
172
|
const rawBody = request.rawBody;
|
|
147
173
|
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
|
-
}
|
|
174
|
+
if (!verifySignature(data.secret, id, timestamp, payload, signatures))
|
|
175
|
+
return refuse('Invalid signature');
|
|
153
176
|
}
|
|
154
177
|
const headers = this.getHeaderData();
|
|
155
178
|
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.1",
|
|
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.1",
|
|
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",
|