n8n-nodes-qwease 0.3.9
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/LICENSE +21 -0
- package/README.md +74 -0
- package/dist/credentials/QweaseApi.credentials.d.ts +10 -0
- package/dist/credentials/QweaseApi.credentials.js +37 -0
- package/dist/credentials/qwease.png +0 -0
- package/dist/credentials/qwease.svg +4 -0
- package/dist/nodes/Qwease/FormFieldsHelper.d.ts +21 -0
- package/dist/nodes/Qwease/FormFieldsHelper.js +187 -0
- package/dist/nodes/Qwease/GenericFunctions.d.ts +4 -0
- package/dist/nodes/Qwease/GenericFunctions.js +30 -0
- package/dist/nodes/Qwease/KnowledgeTaskDescription.d.ts +5 -0
- package/dist/nodes/Qwease/KnowledgeTaskDescription.js +306 -0
- package/dist/nodes/Qwease/OtherResourcesDescription.d.ts +12 -0
- package/dist/nodes/Qwease/OtherResourcesDescription.js +444 -0
- package/dist/nodes/Qwease/Qwease.node.d.ts +32 -0
- package/dist/nodes/Qwease/Qwease.node.js +187 -0
- package/dist/nodes/Qwease/QweaseDescription.d.ts +3 -0
- package/dist/nodes/Qwease/QweaseDescription.js +390 -0
- package/dist/nodes/Qwease/QweaseMethods.d.ts +22 -0
- package/dist/nodes/Qwease/QweaseMethods.js +335 -0
- package/dist/nodes/Qwease/QweaseTrigger.node.d.ts +12 -0
- package/dist/nodes/Qwease/QweaseTrigger.node.js +152 -0
- package/dist/nodes/Qwease/TicketBody.d.ts +3 -0
- package/dist/nodes/Qwease/TicketBody.js +104 -0
- package/dist/nodes/Qwease/executeHelpers.d.ts +14 -0
- package/dist/nodes/Qwease/executeHelpers.js +66 -0
- package/dist/nodes/Qwease/executeKnowledgeTask.d.ts +3 -0
- package/dist/nodes/Qwease/executeKnowledgeTask.js +127 -0
- package/dist/nodes/Qwease/executeOtherResources.d.ts +7 -0
- package/dist/nodes/Qwease/executeOtherResources.js +256 -0
- package/dist/nodes/Qwease/qwease.png +0 -0
- package/dist/nodes/Qwease/qwease.svg +4 -0
- package/dist/nodes/Qwease/shared.d.ts +13 -0
- package/dist/nodes/Qwease/shared.js +155 -0
- package/package.json +54 -0
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getForms = getForms;
|
|
4
|
+
exports.getUsers = getUsers;
|
|
5
|
+
exports.getTeams = getTeams;
|
|
6
|
+
exports.getTickets = getTickets;
|
|
7
|
+
exports.getFormStatuses = getFormStatuses;
|
|
8
|
+
exports.getFormCustomFields = getFormCustomFields;
|
|
9
|
+
exports.getUserCustomFields = getUserCustomFields;
|
|
10
|
+
exports.getClientCustomFields = getClientCustomFields;
|
|
11
|
+
exports.getDeviceCustomFields = getDeviceCustomFields;
|
|
12
|
+
exports.getCustomFieldOptions = getCustomFieldOptions;
|
|
13
|
+
exports.getClients = getClients;
|
|
14
|
+
exports.getDevices = getDevices;
|
|
15
|
+
exports.getPages = getPages;
|
|
16
|
+
exports.getTasks = getTasks;
|
|
17
|
+
exports.getUsersLoad = getUsersLoad;
|
|
18
|
+
exports.getClientsLoad = getClientsLoad;
|
|
19
|
+
exports.getTeamsLoad = getTeamsLoad;
|
|
20
|
+
exports.getDevicesLoad = getDevicesLoad;
|
|
21
|
+
exports.getTicketsLoad = getTicketsLoad;
|
|
22
|
+
exports.getPagesLoad = getPagesLoad;
|
|
23
|
+
const GenericFunctions_1 = require("./GenericFunctions");
|
|
24
|
+
const FormFieldsHelper_1 = require("./FormFieldsHelper");
|
|
25
|
+
function matchesFilter(label, filter) {
|
|
26
|
+
if (!filter) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return label.toLowerCase().includes(filter.toLowerCase());
|
|
30
|
+
}
|
|
31
|
+
async function getForms(filter) {
|
|
32
|
+
const ticketType = this.getCurrentNodeParameter('type');
|
|
33
|
+
const response = await GenericFunctions_1.qweaseApiRequest.call(this, 'GET', '/forms/');
|
|
34
|
+
const forms = (0, GenericFunctions_1.qweaseListFromResponse)(response);
|
|
35
|
+
const filtered = ticketType
|
|
36
|
+
? forms.filter((form) => form.form_type === ticketType)
|
|
37
|
+
: forms;
|
|
38
|
+
const results = [];
|
|
39
|
+
for (const form of filtered) {
|
|
40
|
+
const id = form.id;
|
|
41
|
+
const label = form.name || form.title || `Form ${id}`;
|
|
42
|
+
const kind = form.form_type || ticketType || '';
|
|
43
|
+
const name = kind ? `${label} (${kind})` : label;
|
|
44
|
+
if (!matchesFilter(name, filter)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
results.push({ name, value: String(id) });
|
|
48
|
+
}
|
|
49
|
+
if (results.length === 0) {
|
|
50
|
+
return {
|
|
51
|
+
results: [
|
|
52
|
+
{
|
|
53
|
+
name: 'No Forms Found — Check Type or API Access',
|
|
54
|
+
value: '',
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return { results };
|
|
60
|
+
}
|
|
61
|
+
async function getUsers(filter) {
|
|
62
|
+
const response = await GenericFunctions_1.qweaseApiRequest.call(this, 'GET', '/users/');
|
|
63
|
+
const users = (0, GenericFunctions_1.qweaseListFromResponse)(response);
|
|
64
|
+
const results = [];
|
|
65
|
+
for (const user of users) {
|
|
66
|
+
const id = user.id;
|
|
67
|
+
const email = user.email || '';
|
|
68
|
+
const fullName = [user.first_name, user.last_name].filter(Boolean).join(' ').trim();
|
|
69
|
+
const name = fullName && email ? `${fullName} · ${email}` : email || fullName || `User ${id}`;
|
|
70
|
+
if (!matchesFilter(name, filter)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
results.push({ name, value: String(id) });
|
|
74
|
+
}
|
|
75
|
+
if (results.length === 0) {
|
|
76
|
+
return { results: [{ name: 'No Users Found', value: '' }] };
|
|
77
|
+
}
|
|
78
|
+
return { results };
|
|
79
|
+
}
|
|
80
|
+
async function getTeams(filter) {
|
|
81
|
+
const response = await GenericFunctions_1.qweaseApiRequest.call(this, 'GET', '/teams/');
|
|
82
|
+
const teams = (0, GenericFunctions_1.qweaseListFromResponse)(response);
|
|
83
|
+
const results = [];
|
|
84
|
+
for (const team of teams) {
|
|
85
|
+
const id = team.id;
|
|
86
|
+
const name = team.display_name || team.name || `Team ${id}`;
|
|
87
|
+
if (!matchesFilter(name, filter)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
results.push({ name, value: String(id) });
|
|
91
|
+
}
|
|
92
|
+
if (results.length === 0) {
|
|
93
|
+
return { results: [{ name: 'No Teams Found', value: '' }] };
|
|
94
|
+
}
|
|
95
|
+
return { results };
|
|
96
|
+
}
|
|
97
|
+
async function getTickets(filter) {
|
|
98
|
+
const response = await GenericFunctions_1.qweaseApiRequest.call(this, 'GET', '/ticket/');
|
|
99
|
+
const tickets = (0, GenericFunctions_1.qweaseListFromResponse)(response);
|
|
100
|
+
const results = [];
|
|
101
|
+
for (const ticket of tickets) {
|
|
102
|
+
const id = ticket.id;
|
|
103
|
+
const resume = ticket.resume || '';
|
|
104
|
+
const displayName = ticket.display_name || '';
|
|
105
|
+
const name = displayName || (resume ? `#${id} · ${resume}` : `Ticket ${id}`);
|
|
106
|
+
if (!matchesFilter(name, filter) && !matchesFilter(String(id), filter)) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
results.push({ name, value: String(id) });
|
|
110
|
+
}
|
|
111
|
+
if (results.length === 0) {
|
|
112
|
+
return { results: [{ name: 'No Tickets Found', value: '' }] };
|
|
113
|
+
}
|
|
114
|
+
return { results };
|
|
115
|
+
}
|
|
116
|
+
async function getFormStatuses(filter) {
|
|
117
|
+
const formId = await (0, FormFieldsHelper_1.resolveFormIdForLists)(this);
|
|
118
|
+
if (!formId) {
|
|
119
|
+
return {
|
|
120
|
+
results: [
|
|
121
|
+
{
|
|
122
|
+
name: 'Select a Form (Create) or Ticket (Update) First',
|
|
123
|
+
value: '',
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const statuses = await (0, FormFieldsHelper_1.fetchFormStatusItems)(this, formId);
|
|
129
|
+
const results = [];
|
|
130
|
+
for (const status of statuses) {
|
|
131
|
+
const id = status.id;
|
|
132
|
+
const name = status.display_name || status.name || `Status ${id}`;
|
|
133
|
+
if (!matchesFilter(name, filter) && !matchesFilter(String(id), filter)) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
results.push({ name, value: String(id) });
|
|
137
|
+
}
|
|
138
|
+
if (results.length === 0) {
|
|
139
|
+
return { results: [{ name: 'No Statuses for This Form', value: '' }] };
|
|
140
|
+
}
|
|
141
|
+
return { results };
|
|
142
|
+
}
|
|
143
|
+
async function getFormCustomFields(filter) {
|
|
144
|
+
const formId = await (0, FormFieldsHelper_1.resolveFormIdForLists)(this);
|
|
145
|
+
if (!formId) {
|
|
146
|
+
return {
|
|
147
|
+
results: [
|
|
148
|
+
{
|
|
149
|
+
name: 'Select a Form (Create) or Ticket (Update) First',
|
|
150
|
+
value: '',
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const fields = await (0, FormFieldsHelper_1.fetchFormFields)(this, formId);
|
|
156
|
+
const results = [];
|
|
157
|
+
for (const field of fields) {
|
|
158
|
+
const name = `${field.name} (${field.technical_name})`;
|
|
159
|
+
if (!matchesFilter(name, filter) &&
|
|
160
|
+
!matchesFilter(field.technical_name, filter) &&
|
|
161
|
+
!matchesFilter(field.name, filter)) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
results.push({ name, value: field.technical_name });
|
|
165
|
+
}
|
|
166
|
+
if (results.length === 0) {
|
|
167
|
+
return { results: [{ name: 'No Custom Fields on This Form', value: '' }] };
|
|
168
|
+
}
|
|
169
|
+
return { results };
|
|
170
|
+
}
|
|
171
|
+
async function listEntityCustomFields(context, fieldType, filter, emptyLabel) {
|
|
172
|
+
const fields = await (0, FormFieldsHelper_1.fetchEntityFields)(context, fieldType);
|
|
173
|
+
const results = [];
|
|
174
|
+
for (const field of fields) {
|
|
175
|
+
const name = `${field.name} (${field.technical_name})`;
|
|
176
|
+
if (!matchesFilter(name, filter) &&
|
|
177
|
+
!matchesFilter(field.technical_name, filter) &&
|
|
178
|
+
!matchesFilter(field.name, filter)) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
results.push({ name, value: field.technical_name });
|
|
182
|
+
}
|
|
183
|
+
if (results.length === 0) {
|
|
184
|
+
return { results: [{ name: emptyLabel, value: '' }] };
|
|
185
|
+
}
|
|
186
|
+
return { results };
|
|
187
|
+
}
|
|
188
|
+
async function getUserCustomFields(filter) {
|
|
189
|
+
return listEntityCustomFields(this, 'user', filter, 'No user custom fields found');
|
|
190
|
+
}
|
|
191
|
+
async function getClientCustomFields(filter) {
|
|
192
|
+
return listEntityCustomFields(this, 'client', filter, 'No organization custom fields found');
|
|
193
|
+
}
|
|
194
|
+
async function getDeviceCustomFields(filter) {
|
|
195
|
+
return listEntityCustomFields(this, 'device', filter, 'No device custom fields found');
|
|
196
|
+
}
|
|
197
|
+
async function getCustomFieldOptions(filter) {
|
|
198
|
+
let keyParam;
|
|
199
|
+
try {
|
|
200
|
+
keyParam = this.getCurrentNodeParameter('&key');
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
keyParam = undefined;
|
|
204
|
+
}
|
|
205
|
+
const technicalName = (0, FormFieldsHelper_1.extractLocatorValue)(keyParam);
|
|
206
|
+
if (!technicalName) {
|
|
207
|
+
return {
|
|
208
|
+
results: [{ name: 'Select a Field First', value: '' }],
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
const options = await (0, FormFieldsHelper_1.resolveCustomFieldOptions)(this, technicalName);
|
|
212
|
+
const results = [];
|
|
213
|
+
for (const option of options) {
|
|
214
|
+
const id = option.id;
|
|
215
|
+
if (id === undefined || id === null || id === '') {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const name = String(option.name || option.display_name || id);
|
|
219
|
+
const value = String(id);
|
|
220
|
+
if (!matchesFilter(name, filter) && !matchesFilter(value, filter)) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
results.push({ name, value });
|
|
224
|
+
}
|
|
225
|
+
if (results.length === 0) {
|
|
226
|
+
return {
|
|
227
|
+
results: [
|
|
228
|
+
{
|
|
229
|
+
name: 'No List Options — Switch Field Value to By Value',
|
|
230
|
+
value: '',
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
return { results };
|
|
236
|
+
}
|
|
237
|
+
async function getClients(filter) {
|
|
238
|
+
const response = await GenericFunctions_1.qweaseApiRequest.call(this, 'GET', '/client/');
|
|
239
|
+
const clients = (0, GenericFunctions_1.qweaseListFromResponse)(response);
|
|
240
|
+
const results = [];
|
|
241
|
+
for (const client of clients) {
|
|
242
|
+
const id = client.id;
|
|
243
|
+
const name = client.display_name || client.name || `Organization ${id}`;
|
|
244
|
+
if (!matchesFilter(name, filter) && !matchesFilter(String(id), filter)) {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
results.push({ name, value: String(id) });
|
|
248
|
+
}
|
|
249
|
+
if (results.length === 0) {
|
|
250
|
+
return { results: [{ name: 'No Organizations Found', value: '' }] };
|
|
251
|
+
}
|
|
252
|
+
return { results };
|
|
253
|
+
}
|
|
254
|
+
async function getDevices(filter) {
|
|
255
|
+
const response = await GenericFunctions_1.qweaseApiRequest.call(this, 'GET', '/device/');
|
|
256
|
+
const devices = (0, GenericFunctions_1.qweaseListFromResponse)(response);
|
|
257
|
+
const results = [];
|
|
258
|
+
for (const device of devices) {
|
|
259
|
+
const id = device.id;
|
|
260
|
+
const label = device.name || `Device ${id}`;
|
|
261
|
+
const serial = device.serial_number || '';
|
|
262
|
+
const name = serial ? `${label} · ${serial}` : label;
|
|
263
|
+
if (!matchesFilter(name, filter) && !matchesFilter(String(id), filter)) {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
results.push({ name, value: String(id) });
|
|
267
|
+
}
|
|
268
|
+
if (results.length === 0) {
|
|
269
|
+
return { results: [{ name: 'No Devices Found', value: '' }] };
|
|
270
|
+
}
|
|
271
|
+
return { results };
|
|
272
|
+
}
|
|
273
|
+
async function getPages(filter) {
|
|
274
|
+
const response = await GenericFunctions_1.qweaseApiRequest.call(this, 'GET', '/pages/');
|
|
275
|
+
const pages = (0, GenericFunctions_1.qweaseListFromResponse)(response);
|
|
276
|
+
const results = [];
|
|
277
|
+
for (const page of pages) {
|
|
278
|
+
const id = page.id;
|
|
279
|
+
const title = page.title || `Page ${id}`;
|
|
280
|
+
const kind = page.type || '';
|
|
281
|
+
const name = kind ? `${title} (${kind})` : title;
|
|
282
|
+
if (!matchesFilter(name, filter) && !matchesFilter(String(id), filter)) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
results.push({ name, value: String(id) });
|
|
286
|
+
}
|
|
287
|
+
if (results.length === 0) {
|
|
288
|
+
return { results: [{ name: 'No Pages Found', value: '' }] };
|
|
289
|
+
}
|
|
290
|
+
return { results };
|
|
291
|
+
}
|
|
292
|
+
async function getTasks(filter) {
|
|
293
|
+
const response = await GenericFunctions_1.qweaseApiRequest.call(this, 'GET', '/tasks/');
|
|
294
|
+
const tasks = (0, GenericFunctions_1.qweaseListFromResponse)(response);
|
|
295
|
+
const results = [];
|
|
296
|
+
for (const task of tasks) {
|
|
297
|
+
const id = task.id;
|
|
298
|
+
const title = task.task_title || `Task ${id}`;
|
|
299
|
+
const status = task.task_status || '';
|
|
300
|
+
const name = status ? `${title} · ${status}` : title;
|
|
301
|
+
if (!matchesFilter(name, filter) && !matchesFilter(String(id), filter)) {
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
results.push({ name, value: String(id) });
|
|
305
|
+
}
|
|
306
|
+
if (results.length === 0) {
|
|
307
|
+
return { results: [{ name: 'No Tasks Found', value: '' }] };
|
|
308
|
+
}
|
|
309
|
+
return { results };
|
|
310
|
+
}
|
|
311
|
+
async function toLoadOptions(searchFn) {
|
|
312
|
+
const { results } = await searchFn.call(this);
|
|
313
|
+
return results
|
|
314
|
+
.filter((entry) => entry.value !== '')
|
|
315
|
+
.map((entry) => ({ name: entry.name, value: entry.value }));
|
|
316
|
+
}
|
|
317
|
+
/** multiOptions loaders (pick several related objects) */
|
|
318
|
+
async function getUsersLoad() {
|
|
319
|
+
return toLoadOptions.call(this, getUsers);
|
|
320
|
+
}
|
|
321
|
+
async function getClientsLoad() {
|
|
322
|
+
return toLoadOptions.call(this, getClients);
|
|
323
|
+
}
|
|
324
|
+
async function getTeamsLoad() {
|
|
325
|
+
return toLoadOptions.call(this, getTeams);
|
|
326
|
+
}
|
|
327
|
+
async function getDevicesLoad() {
|
|
328
|
+
return toLoadOptions.call(this, getDevices);
|
|
329
|
+
}
|
|
330
|
+
async function getTicketsLoad() {
|
|
331
|
+
return toLoadOptions.call(this, getTickets);
|
|
332
|
+
}
|
|
333
|
+
async function getPagesLoad() {
|
|
334
|
+
return toLoadOptions.call(this, getPages);
|
|
335
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IHookFunctions, INodeType, INodeTypeDescription, IWebhookFunctions, IWebhookResponseData } from 'n8n-workflow';
|
|
2
|
+
export declare class QweaseTrigger 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,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QweaseTrigger = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
6
|
+
const EVENT_OPTIONS = [
|
|
7
|
+
{ name: 'Ticket Created', value: 'ticket_created' },
|
|
8
|
+
{ name: 'Ticket Updated', value: 'ticket_updated' },
|
|
9
|
+
{ name: 'Ticket Closed', value: 'ticket_closed' },
|
|
10
|
+
{ name: 'Ticket Comment Created', value: 'ticket_comment_created' },
|
|
11
|
+
{ name: 'Task Opened', value: 'task_opened' },
|
|
12
|
+
{ name: 'Task Completed', value: 'task_completed' },
|
|
13
|
+
{ name: 'Task Refused', value: 'task_refused' },
|
|
14
|
+
{ name: 'Webhook Test', value: 'webhook.test' },
|
|
15
|
+
];
|
|
16
|
+
function getRawBody(req) {
|
|
17
|
+
var _a;
|
|
18
|
+
if (req.rawBody) {
|
|
19
|
+
return typeof req.rawBody === 'string' ? Buffer.from(req.rawBody, 'utf8') : req.rawBody;
|
|
20
|
+
}
|
|
21
|
+
// Fallback when raw body is unavailable (may fail HMAC on some n8n hosts)
|
|
22
|
+
const serialized = JSON.stringify((_a = req.body) !== null && _a !== void 0 ? _a : {}, null, 0);
|
|
23
|
+
return Buffer.from(serialized, 'utf8');
|
|
24
|
+
}
|
|
25
|
+
function verifyQweaseSignature(secret, rawBody, signatureHeader) {
|
|
26
|
+
const expected = (0, crypto_1.createHmac)('sha256', secret).update(rawBody).digest('hex');
|
|
27
|
+
const received = signatureHeader.trim();
|
|
28
|
+
const expectedBuf = Buffer.from(expected, 'utf8');
|
|
29
|
+
const receivedBuf = Buffer.from(received, 'utf8');
|
|
30
|
+
if (expectedBuf.length !== receivedBuf.length) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return (0, crypto_1.timingSafeEqual)(expectedBuf, receivedBuf);
|
|
34
|
+
}
|
|
35
|
+
class QweaseTrigger {
|
|
36
|
+
constructor() {
|
|
37
|
+
this.description = {
|
|
38
|
+
displayName: 'Qwease Trigger',
|
|
39
|
+
name: 'qweaseTrigger',
|
|
40
|
+
icon: 'file:qwease.svg',
|
|
41
|
+
group: ['trigger'],
|
|
42
|
+
version: 1,
|
|
43
|
+
description: 'Starts the workflow when Qwease sends a signed webhook event',
|
|
44
|
+
defaults: {
|
|
45
|
+
name: 'Qwease Trigger',
|
|
46
|
+
},
|
|
47
|
+
inputs: [],
|
|
48
|
+
outputs: ['main'],
|
|
49
|
+
webhooks: [
|
|
50
|
+
{
|
|
51
|
+
name: 'default',
|
|
52
|
+
httpMethod: 'POST',
|
|
53
|
+
responseMode: 'onReceived',
|
|
54
|
+
path: '={{$parameter["path"]}}',
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
properties: [
|
|
58
|
+
{
|
|
59
|
+
displayName: 'Path',
|
|
60
|
+
name: 'path',
|
|
61
|
+
type: 'string',
|
|
62
|
+
default: 'qwease',
|
|
63
|
+
required: true,
|
|
64
|
+
description: 'Webhook path suffix (production URL ends with /webhook/<path>)',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
displayName: 'Webhook Secret',
|
|
68
|
+
name: 'webhookSecret',
|
|
69
|
+
type: 'string',
|
|
70
|
+
typeOptions: { password: true },
|
|
71
|
+
default: '',
|
|
72
|
+
required: true,
|
|
73
|
+
description: 'Secret shown once when creating the webhook in Qwease Admin → Integrations → Webhooks',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
displayName: 'Events',
|
|
77
|
+
name: 'events',
|
|
78
|
+
type: 'multiOptions',
|
|
79
|
+
options: EVENT_OPTIONS,
|
|
80
|
+
default: [],
|
|
81
|
+
description: 'Leave empty to accept all event types (including webhook.test)',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
displayName: 'Ignore Invalid Signature',
|
|
85
|
+
name: 'ignoreInvalidSignature',
|
|
86
|
+
type: 'boolean',
|
|
87
|
+
default: false,
|
|
88
|
+
description: 'Whether to still emit the item when HMAC verification fails (not recommended in production)',
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
usableAsTool: true,
|
|
92
|
+
};
|
|
93
|
+
this.webhookMethods = {
|
|
94
|
+
default: {
|
|
95
|
+
async checkExists() {
|
|
96
|
+
return true;
|
|
97
|
+
},
|
|
98
|
+
async create() {
|
|
99
|
+
return true;
|
|
100
|
+
},
|
|
101
|
+
async delete() {
|
|
102
|
+
return true;
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async webhook() {
|
|
108
|
+
const req = this.getRequestObject();
|
|
109
|
+
const headerData = this.getHeaderData();
|
|
110
|
+
const secret = this.getNodeParameter('webhookSecret');
|
|
111
|
+
const events = this.getNodeParameter('events', []);
|
|
112
|
+
const ignoreInvalidSignature = this.getNodeParameter('ignoreInvalidSignature', false);
|
|
113
|
+
const signature = headerData['x-qwease-signature-256'] ||
|
|
114
|
+
headerData['X-Qwease-Signature-256'] ||
|
|
115
|
+
'';
|
|
116
|
+
if (!signature) {
|
|
117
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Missing X-Qwease-Signature-256 header');
|
|
118
|
+
}
|
|
119
|
+
const rawBody = getRawBody(req);
|
|
120
|
+
const valid = verifyQweaseSignature(secret, rawBody, signature);
|
|
121
|
+
if (!valid && !ignoreInvalidSignature) {
|
|
122
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Invalid Qwease webhook signature');
|
|
123
|
+
}
|
|
124
|
+
const body = (this.getBodyData() || {});
|
|
125
|
+
const eventType = body.event_type ||
|
|
126
|
+
(body.event === 'webhook.test' ? 'webhook.test' : '') ||
|
|
127
|
+
'';
|
|
128
|
+
if (events.length > 0) {
|
|
129
|
+
const allowed = events.includes(eventType) ||
|
|
130
|
+
(eventType === '' && body.event === 'webhook.test' && events.includes('webhook.test'));
|
|
131
|
+
if (!allowed) {
|
|
132
|
+
return {
|
|
133
|
+
webhookResponse: { status: 200, body: { ignored: true, event_type: eventType } },
|
|
134
|
+
noWebhookResponse: false,
|
|
135
|
+
workflowData: [[]],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const item = {
|
|
140
|
+
...body,
|
|
141
|
+
_qwease: {
|
|
142
|
+
signature_valid: valid,
|
|
143
|
+
event_type: eventType || body.event,
|
|
144
|
+
received_at: new Date().toISOString(),
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
workflowData: [[{ json: item }]],
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.QweaseTrigger = QweaseTrigger;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { IDataObject, IExecuteFunctions } from 'n8n-workflow';
|
|
2
|
+
export declare function buildTicketBodyFromParameters(this: IExecuteFunctions, itemIndex: number, includeRequired: boolean): IDataObject;
|
|
3
|
+
export declare function getTicketIdParameter(this: IExecuteFunctions, itemIndex: number): string;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildTicketBodyFromParameters = buildTicketBodyFromParameters;
|
|
4
|
+
exports.getTicketIdParameter = getTicketIdParameter;
|
|
5
|
+
const FormFieldsHelper_1 = require("./FormFieldsHelper");
|
|
6
|
+
function parseOptionalInt(value) {
|
|
7
|
+
if (value === undefined || value === null || value === '') {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
if (typeof value === 'object' && value !== null && 'value' in value) {
|
|
11
|
+
return parseOptionalInt(value.value);
|
|
12
|
+
}
|
|
13
|
+
const n = typeof value === 'number' ? value : parseInt(String(value), 10);
|
|
14
|
+
return Number.isNaN(n) ? undefined : n;
|
|
15
|
+
}
|
|
16
|
+
function getResourceId(context, parameterName, itemIndex, fallback = '') {
|
|
17
|
+
const value = context.getNodeParameter(parameterName, itemIndex, fallback, {
|
|
18
|
+
extractValue: true,
|
|
19
|
+
});
|
|
20
|
+
if (value === undefined || value === null || value === '') {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
return String(value);
|
|
24
|
+
}
|
|
25
|
+
function resolveLocatorValue(value) {
|
|
26
|
+
return parseOptionalInt(value);
|
|
27
|
+
}
|
|
28
|
+
function buildCustomFieldsFromUi(customFieldsUi) {
|
|
29
|
+
const fields = customFieldsUi === null || customFieldsUi === void 0 ? void 0 : customFieldsUi.field;
|
|
30
|
+
if (!(fields === null || fields === void 0 ? void 0 : fields.length)) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const result = {};
|
|
34
|
+
for (const entry of fields) {
|
|
35
|
+
const key = (0, FormFieldsHelper_1.extractLocatorValue)(entry.key);
|
|
36
|
+
if (key) {
|
|
37
|
+
result[key] = (0, FormFieldsHelper_1.extractLocatorValue)(entry.value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return Object.keys(result).length ? result : undefined;
|
|
41
|
+
}
|
|
42
|
+
function applyOptionalFields(body, fields) {
|
|
43
|
+
if (fields.resume) {
|
|
44
|
+
body.resume = fields.resume;
|
|
45
|
+
}
|
|
46
|
+
if (fields.description) {
|
|
47
|
+
body.description = fields.description;
|
|
48
|
+
}
|
|
49
|
+
if (fields.priority) {
|
|
50
|
+
body.priority = fields.priority;
|
|
51
|
+
}
|
|
52
|
+
const askedBy = resolveLocatorValue(fields.askedBy);
|
|
53
|
+
if (askedBy !== undefined) {
|
|
54
|
+
body.asked_by = askedBy;
|
|
55
|
+
}
|
|
56
|
+
const assignedTo = resolveLocatorValue(fields.assignedTo);
|
|
57
|
+
if (assignedTo !== undefined) {
|
|
58
|
+
body.assigned_to = assignedTo;
|
|
59
|
+
}
|
|
60
|
+
const assignedGroup = resolveLocatorValue(fields.assignedGroup);
|
|
61
|
+
if (assignedGroup !== undefined) {
|
|
62
|
+
body.assigned_group = assignedGroup;
|
|
63
|
+
}
|
|
64
|
+
const statut = parseOptionalInt(fields.statusId);
|
|
65
|
+
if (statut !== undefined) {
|
|
66
|
+
body.statut = statut;
|
|
67
|
+
}
|
|
68
|
+
if (fields.desiredResolutionDate) {
|
|
69
|
+
body.desired_resolution_date = fields.desiredResolutionDate;
|
|
70
|
+
}
|
|
71
|
+
const customFields = buildCustomFieldsFromUi(fields.customFieldsUi);
|
|
72
|
+
if (customFields) {
|
|
73
|
+
body.custom_fields = customFields;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function buildTicketBodyFromParameters(itemIndex, includeRequired) {
|
|
77
|
+
const body = {};
|
|
78
|
+
if (includeRequired) {
|
|
79
|
+
const form = parseOptionalInt(getResourceId(this, 'form', itemIndex));
|
|
80
|
+
const forUser = parseOptionalInt(getResourceId(this, 'forUser', itemIndex));
|
|
81
|
+
if (!form || !forUser) {
|
|
82
|
+
throw new Error('Select a Form and For User (list or ID).');
|
|
83
|
+
}
|
|
84
|
+
body.type = this.getNodeParameter('type', itemIndex);
|
|
85
|
+
body.form = form;
|
|
86
|
+
body.for_user = forUser;
|
|
87
|
+
body.resume = this.getNodeParameter('resume', itemIndex);
|
|
88
|
+
body.description = this.getNodeParameter('description', itemIndex);
|
|
89
|
+
const additionalFields = this.getNodeParameter('additionalFields', itemIndex, {});
|
|
90
|
+
applyOptionalFields(body, additionalFields);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const updateFields = this.getNodeParameter('updateFields', itemIndex, {});
|
|
94
|
+
applyOptionalFields(body, updateFields);
|
|
95
|
+
}
|
|
96
|
+
return body;
|
|
97
|
+
}
|
|
98
|
+
function getTicketIdParameter(itemIndex) {
|
|
99
|
+
const ticketId = getResourceId(this, 'ticketId', itemIndex);
|
|
100
|
+
if (!ticketId) {
|
|
101
|
+
throw new Error('Select a Ticket (list or ID).');
|
|
102
|
+
}
|
|
103
|
+
return ticketId;
|
|
104
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { IDataObject, IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
|
|
2
|
+
type CustomFieldsUi = {
|
|
3
|
+
field?: Array<{
|
|
4
|
+
key: unknown;
|
|
5
|
+
value: unknown;
|
|
6
|
+
}>;
|
|
7
|
+
};
|
|
8
|
+
export declare function parseOptionalInt(value: unknown): number | undefined;
|
|
9
|
+
export declare function getResourceId(context: IExecuteFunctions, parameterName: string, itemIndex: number, fallback?: string): string;
|
|
10
|
+
export declare function buildCustomFieldsFromUi(customFieldsUi: CustomFieldsUi | undefined): IDataObject | undefined;
|
|
11
|
+
export declare function executeGetAll(context: IExecuteFunctions, itemIndex: number, endpoint: string): Promise<INodeExecutionData[]>;
|
|
12
|
+
export declare function executeGetById(context: IExecuteFunctions, itemIndex: number, endpointPrefix: string, parameterName: string, label: string): Promise<INodeExecutionData>;
|
|
13
|
+
export declare function requireResourceId(context: IExecuteFunctions, parameterName: string, itemIndex: number, label: string): string;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseOptionalInt = parseOptionalInt;
|
|
4
|
+
exports.getResourceId = getResourceId;
|
|
5
|
+
exports.buildCustomFieldsFromUi = buildCustomFieldsFromUi;
|
|
6
|
+
exports.executeGetAll = executeGetAll;
|
|
7
|
+
exports.executeGetById = executeGetById;
|
|
8
|
+
exports.requireResourceId = requireResourceId;
|
|
9
|
+
const GenericFunctions_1 = require("./GenericFunctions");
|
|
10
|
+
const FormFieldsHelper_1 = require("./FormFieldsHelper");
|
|
11
|
+
function parseOptionalInt(value) {
|
|
12
|
+
if (value === undefined || value === null || value === '') {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
if (typeof value === 'object' && value !== null && 'value' in value) {
|
|
16
|
+
return parseOptionalInt(value.value);
|
|
17
|
+
}
|
|
18
|
+
const n = typeof value === 'number' ? value : parseInt(String(value), 10);
|
|
19
|
+
return Number.isNaN(n) ? undefined : n;
|
|
20
|
+
}
|
|
21
|
+
function getResourceId(context, parameterName, itemIndex, fallback = '') {
|
|
22
|
+
const value = context.getNodeParameter(parameterName, itemIndex, fallback, {
|
|
23
|
+
extractValue: true,
|
|
24
|
+
});
|
|
25
|
+
if (value === undefined || value === null || value === '') {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
return String(value);
|
|
29
|
+
}
|
|
30
|
+
function buildCustomFieldsFromUi(customFieldsUi) {
|
|
31
|
+
const fields = customFieldsUi === null || customFieldsUi === void 0 ? void 0 : customFieldsUi.field;
|
|
32
|
+
if (!(fields === null || fields === void 0 ? void 0 : fields.length)) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const result = {};
|
|
36
|
+
for (const entry of fields) {
|
|
37
|
+
const key = (0, FormFieldsHelper_1.extractLocatorValue)(entry.key);
|
|
38
|
+
if (key) {
|
|
39
|
+
result[key] = (0, FormFieldsHelper_1.extractLocatorValue)(entry.value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return Object.keys(result).length ? result : undefined;
|
|
43
|
+
}
|
|
44
|
+
async function executeGetAll(context, itemIndex, endpoint) {
|
|
45
|
+
const returnAll = context.getNodeParameter('returnAll', itemIndex);
|
|
46
|
+
const limit = context.getNodeParameter('limit', itemIndex);
|
|
47
|
+
const response = await GenericFunctions_1.qweaseApiRequest.call(context, 'GET', endpoint);
|
|
48
|
+
const list = (0, GenericFunctions_1.qweaseListFromResponse)(response);
|
|
49
|
+
const sliced = returnAll ? list : list.slice(0, limit);
|
|
50
|
+
return sliced.map((entry) => ({ json: entry, pairedItem: { item: itemIndex } }));
|
|
51
|
+
}
|
|
52
|
+
async function executeGetById(context, itemIndex, endpointPrefix, parameterName, label) {
|
|
53
|
+
const id = getResourceId(context, parameterName, itemIndex);
|
|
54
|
+
if (!id) {
|
|
55
|
+
throw new Error(`Select a ${label} (list or ID).`);
|
|
56
|
+
}
|
|
57
|
+
const response = await GenericFunctions_1.qweaseApiRequest.call(context, 'GET', `${endpointPrefix}${id}/`);
|
|
58
|
+
return { json: response, pairedItem: { item: itemIndex } };
|
|
59
|
+
}
|
|
60
|
+
function requireResourceId(context, parameterName, itemIndex, label) {
|
|
61
|
+
const id = getResourceId(context, parameterName, itemIndex);
|
|
62
|
+
if (!id) {
|
|
63
|
+
throw new Error(`Select a ${label} (list or ID).`);
|
|
64
|
+
}
|
|
65
|
+
return id;
|
|
66
|
+
}
|