@taistudio/n8n-nodes-planka 26.1.8 → 26.1.12
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,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GenericFunctions = exports.plankaApiRequestAllItems = exports.plankaApiRequest = exports.getPlankaToken = void 0;
|
|
4
|
+
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
|
+
async function getPlankaToken(credentials) {
|
|
6
|
+
const options = {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
uri: `${credentials.apiUrl}/access-tokens`,
|
|
9
|
+
body: {
|
|
10
|
+
emailOrUsername: credentials.email,
|
|
11
|
+
password: credentials.password,
|
|
12
|
+
},
|
|
13
|
+
json: true,
|
|
14
|
+
};
|
|
15
|
+
try {
|
|
16
|
+
const response = await this.helpers.request.call(this, options);
|
|
17
|
+
if (response.item) {
|
|
18
|
+
return response.item;
|
|
19
|
+
}
|
|
20
|
+
throw new n8n_workflow_1.NodeApiError(this.getNode(), response, {
|
|
21
|
+
message: 'Unable to obtain access token',
|
|
22
|
+
description: 'The API response does not contain the expected token',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw new n8n_workflow_1.NodeApiError(this.getNode(), error, {
|
|
27
|
+
message: 'Authentication error',
|
|
28
|
+
description: 'We were unable to authenticate with the provided credentials.',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.getPlankaToken = getPlankaToken;
|
|
33
|
+
async function plankaApiRequest(method, endpoint, body = {}, query = {}) {
|
|
34
|
+
const credentials = await this.getCredentials('plankaApi');
|
|
35
|
+
const token = await getPlankaToken.call(this, credentials);
|
|
36
|
+
const options = {
|
|
37
|
+
method,
|
|
38
|
+
uri: `${credentials.apiUrl}${endpoint}`,
|
|
39
|
+
body,
|
|
40
|
+
qs: query,
|
|
41
|
+
headers: {
|
|
42
|
+
Authorization: `Bearer ${token}`,
|
|
43
|
+
},
|
|
44
|
+
json: true,
|
|
45
|
+
};
|
|
46
|
+
if (Object.keys(body).length === 0) {
|
|
47
|
+
delete options.body;
|
|
48
|
+
}
|
|
49
|
+
if (Object.keys(query).length === 0) {
|
|
50
|
+
delete options.qs;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return await this.helpers.request.call(this, options);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
throw new n8n_workflow_1.NodeApiError(this.getNode(), error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.plankaApiRequest = plankaApiRequest;
|
|
60
|
+
async function plankaApiRequestAllItems(method, endpoint, body = {}, query = {}) {
|
|
61
|
+
const returnData = [];
|
|
62
|
+
const responseData = await plankaApiRequest.call(this, method, endpoint, body, query);
|
|
63
|
+
if (Array.isArray(responseData)) {
|
|
64
|
+
returnData.push(...responseData);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
returnData.push(responseData);
|
|
68
|
+
}
|
|
69
|
+
return returnData;
|
|
70
|
+
}
|
|
71
|
+
exports.plankaApiRequestAllItems = plankaApiRequestAllItems;
|
|
72
|
+
class GenericFunctions {
|
|
73
|
+
constructor(executeFunctions) {
|
|
74
|
+
this.executeFunctions = executeFunctions;
|
|
75
|
+
}
|
|
76
|
+
async request(options) {
|
|
77
|
+
try {
|
|
78
|
+
if (!this.executeFunctions.helpers) {
|
|
79
|
+
throw new Error('Helpers is not defined');
|
|
80
|
+
}
|
|
81
|
+
const response = await this.executeFunctions.helpers.request.call(this.executeFunctions, options);
|
|
82
|
+
return response;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (error instanceof Error) {
|
|
86
|
+
throw new n8n_workflow_1.NodeApiError(this.executeFunctions.getNode(), { error: error.message });
|
|
87
|
+
}
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async handleRequest(options) {
|
|
92
|
+
try {
|
|
93
|
+
if (!this.executeFunctions.helpers) {
|
|
94
|
+
throw new Error('Helpers is not defined');
|
|
95
|
+
}
|
|
96
|
+
return await this.executeFunctions.helpers.request.call(this.executeFunctions, options);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
if (error instanceof Error) {
|
|
100
|
+
throw new n8n_workflow_1.NodeApiError(this.executeFunctions.getNode(), { error: error.message });
|
|
101
|
+
}
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.GenericFunctions = GenericFunctions;
|
|
107
|
+
//# sourceMappingURL=GenericFunctions.js.map
|