mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
⚡ Improvements to Eventbrite-Trigger
This commit is contained in:
parent
755079c360
commit
28befc1034
|
@ -8,7 +8,7 @@ export class EventbriteApi implements ICredentialType {
|
|||
displayName = 'Eventbrite API';
|
||||
properties = [
|
||||
{
|
||||
displayName: 'API Key',
|
||||
displayName: 'Private Key',
|
||||
name: 'apiKey',
|
||||
type: 'string' as NodePropertyTypes,
|
||||
default: '',
|
||||
|
|
|
@ -38,7 +38,7 @@ export class EventbriteTrigger implements INodeType {
|
|||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'accessToken',
|
||||
'privateKey',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -70,15 +70,15 @@ export class EventbriteTrigger implements INodeType {
|
|||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Access Token',
|
||||
value: 'accessToken',
|
||||
name: 'Private Key',
|
||||
value: 'privateKey',
|
||||
},
|
||||
{
|
||||
name: 'OAuth2',
|
||||
value: 'oAuth2',
|
||||
},
|
||||
],
|
||||
default: 'accessToken',
|
||||
default: 'privateKey',
|
||||
description: 'The resource to operate on.',
|
||||
},
|
||||
{
|
||||
|
@ -184,7 +184,6 @@ export class EventbriteTrigger implements INodeType {
|
|||
description: 'By default does the webhook-data only contain the URL to receive<br />the object data manually. If this option gets activated it<br />will resolve the data automatically.',
|
||||
},
|
||||
],
|
||||
|
||||
};
|
||||
|
||||
methods = {
|
||||
|
@ -227,18 +226,31 @@ export class EventbriteTrigger implements INodeType {
|
|||
default: {
|
||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
const organisation = this.getNodeParameter('organization') as string;
|
||||
const actions = this.getNodeParameter('actions') as string[];
|
||||
|
||||
if (webhookData.webhookId === undefined) {
|
||||
return false;
|
||||
}
|
||||
const endpoint = `/organizations/${organisation}/webhooks/`;
|
||||
try {
|
||||
await eventbriteApiRequest.call(this, 'GET', endpoint);
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
||||
const { webhooks } = await eventbriteApiRequest.call(this, 'GET', endpoint);
|
||||
|
||||
const check = (currentActions: string[], webhookActions: string[]) => {
|
||||
for (const currentAction of currentActions) {
|
||||
if (!webhookActions.includes(currentAction)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
for (const webhook of webhooks) {
|
||||
if (webhook.endpoint_url === webhookUrl && check(actions, webhook.actions)) {
|
||||
webhookData.webhookId = webhook.id;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
return false;
|
||||
},
|
||||
async create(this: IHookFunctions): Promise<boolean> {
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import { OptionsWithUri } from 'request';
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
IExecuteSingleFunctions,
|
||||
|
@ -6,7 +9,10 @@ import {
|
|||
ILoadOptionsFunctions,
|
||||
IWebhookFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IDataObject } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function eventbriteApiRequest(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
|
||||
let options: OptionsWithUri = {
|
||||
|
@ -25,7 +31,7 @@ export async function eventbriteApiRequest(this: IHookFunctions | IExecuteFuncti
|
|||
const authenticationMethod = this.getNodeParameter('authentication', 0);
|
||||
|
||||
try {
|
||||
if (authenticationMethod === 'accessToken') {
|
||||
if (authenticationMethod === 'privateKey') {
|
||||
const credentials = this.getCredentials('eventbriteApi');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
|
|
Loading…
Reference in a new issue