mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
✨ Add Kitemaker node (#1676)
* ⚡ Add Kitemaker node * ⚡ Require status ID for workItem:create * ✏️ Reword button text * ⚡ Add credentials file * ⚡ Implement pagination * ⚡ Improvements * ⚡ Remove not needed parameter Co-authored-by: ricardo <ricardoespinoza105@gmail.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
85
packages/nodes-base/nodes/Kitemaker/GenericFunctions.ts
Normal file
85
packages/nodes-base/nodes/Kitemaker/GenericFunctions.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
IHookFunctions,
|
||||
NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function kitemakerRequest(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions,
|
||||
body: IDataObject = {},
|
||||
) {
|
||||
const { personalAccessToken } = this.getCredentials('kitemakerApi') as { personalAccessToken: string };
|
||||
|
||||
const options = {
|
||||
headers: {
|
||||
Authorization: `Bearer ${personalAccessToken}`,
|
||||
},
|
||||
method: 'POST',
|
||||
body,
|
||||
uri: 'https://toil.kitemaker.co/developers/graphql',
|
||||
json: true,
|
||||
};
|
||||
|
||||
const responseData = await this.helpers.request!.call(this, options);
|
||||
|
||||
if (responseData.errors) {
|
||||
throw new NodeApiError(this.getNode(), responseData);
|
||||
}
|
||||
|
||||
return responseData;
|
||||
}
|
||||
|
||||
export async function kitemakerRequestAllItems(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
||||
body: { query: string; variables: { [key: string]: string } },
|
||||
) {
|
||||
const resource = this.getNodeParameter('resource', 0) as 'space' | 'user' | 'workItem';
|
||||
const [group, items] = getGroupAndItems(resource);
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', 0, false) as boolean;
|
||||
const limit = this.getNodeParameter('limit', 0, 0) as number;
|
||||
|
||||
const returnData: IDataObject[] = [];
|
||||
let responseData;
|
||||
|
||||
do {
|
||||
responseData = await kitemakerRequest.call(this, body);
|
||||
body.variables.cursor = responseData.data[group].cursor;
|
||||
returnData.push(...responseData.data[group][items]);
|
||||
|
||||
if (!returnAll && returnData.length > limit) {
|
||||
return returnData.slice(0, limit);
|
||||
}
|
||||
|
||||
} while (responseData.data[group].hasMore);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
function getGroupAndItems(resource: 'space' | 'user' | 'workItem') {
|
||||
const map: { [key: string]: { [key: string]: string } } = {
|
||||
space: { group: 'organization', items: 'spaces' },
|
||||
user: { group: 'organization', items: 'users' },
|
||||
workItem: { group: 'workItems', items: 'workItems' },
|
||||
};
|
||||
|
||||
return [
|
||||
map[resource]['group'],
|
||||
map[resource]['items'],
|
||||
];
|
||||
}
|
||||
|
||||
export function createLoadOptions(
|
||||
resources: Array<{ name?: string; username?: string; title?: string; id: string }>,
|
||||
): Array<{ name: string; value: string }> {
|
||||
return resources.map(option => {
|
||||
if (option.username) return ({ name: option.username, value: option.id });
|
||||
if (option.title) return ({ name: option.title, value: option.id });
|
||||
return ({ name: option.name ?? 'Unnamed', value: option.id });
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user