mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
✨ Sentry.io integration (#728)
* 🚧 setup - Added everything, need to test and add icon * Add icon * 🚧 Node colour change * 🚧 Fixed Descriptions * ✔️ Tested, fixed up properties * ✅ Fixed issue of issue * ✅ Added create option for team & organization * ⚡ Improvements * ⚡ Fixed OAuth2 credentials scope * ⚡ Adjusted descriptions, added loadOptions for organizations/projects, small fixes * ⚡ Added Create Release, interfaces * ⚡ Improvements to SentryIO-Node Co-authored-by: ricardo <ricardoespinoza105@gmail.com> Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
This commit is contained in:
108
packages/nodes-base/nodes/SentryIo/GenericFunctions.ts
Normal file
108
packages/nodes-base/nodes/SentryIo/GenericFunctions.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
import {
|
||||
OptionsWithUri
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
IHookFunctions,
|
||||
ILoadOptionsFunctions,
|
||||
IWebhookFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function sentryIoApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
const authentication = this.getNodeParameter('authentication', 0);
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers: {},
|
||||
method,
|
||||
qs,
|
||||
body,
|
||||
uri: uri ||`https://sentry.io${resource}`,
|
||||
json: true
|
||||
};
|
||||
if (!Object.keys(body).length) {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
if (Object.keys(option).length !== 0) {
|
||||
Object.assign(options, option);
|
||||
}
|
||||
|
||||
if (options.qs.limit) {
|
||||
delete options.qs.limit;
|
||||
}
|
||||
|
||||
try {
|
||||
if (authentication === 'accessToken') {
|
||||
|
||||
const credentials = this.getCredentials('sentryIoApi');
|
||||
|
||||
options.headers = {
|
||||
Authorization: `Bearer ${credentials?.token}`,
|
||||
};
|
||||
|
||||
console.log('options');
|
||||
console.log(options);
|
||||
|
||||
|
||||
//@ts-ignore
|
||||
return this.helpers.request(options);
|
||||
|
||||
} else {
|
||||
return await this.helpers.requestOAuth2!.call(this, 'sentryIoOAuth2Api', options);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
throw new Error(`Sentry.io Error: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function sentryApiRequestAllItems(this: IHookFunctions | IExecuteFunctions| ILoadOptionsFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
const returnData: IDataObject[] = [];
|
||||
|
||||
let responseData;
|
||||
|
||||
let link;
|
||||
|
||||
let uri: string | undefined;
|
||||
|
||||
do {
|
||||
responseData = await sentryIoApiRequest.call(this, method, resource, body, query, uri, { resolveWithFullResponse: true });
|
||||
link = responseData.headers.link;
|
||||
uri = getNext(link);
|
||||
returnData.push.apply(returnData, responseData.body);
|
||||
if (query.limit && (query.limit >= returnData.length)) {
|
||||
return;
|
||||
}
|
||||
} while (
|
||||
hasMore(link)
|
||||
);
|
||||
|
||||
return returnData;
|
||||
}
|
||||
|
||||
function getNext(link: string) {
|
||||
if (link === undefined) {
|
||||
return;
|
||||
}
|
||||
const next = link.split(',')[1];
|
||||
if (next.includes('rel="next"')) {
|
||||
return next.split(';')[0].replace('<', '').replace('>','').trim();
|
||||
}
|
||||
}
|
||||
|
||||
function hasMore(link: string) {
|
||||
if (link === undefined) {
|
||||
return;
|
||||
}
|
||||
const next = link.split(',')[1];
|
||||
if (next.includes('rel="next"')) {
|
||||
return next.includes('results="true"');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user