mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 20:54:07 -08:00
🔀 Merge branch 'master' of github.com:n8n-io/n8n
This commit is contained in:
commit
2511597f53
|
@ -0,0 +1,47 @@
|
||||||
|
import {
|
||||||
|
ICredentialType,
|
||||||
|
NodePropertyTypes,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
|
||||||
|
export class DriftOAuth2Api implements ICredentialType {
|
||||||
|
name = 'driftOAuth2Api';
|
||||||
|
extends = [
|
||||||
|
'oAuth2Api',
|
||||||
|
];
|
||||||
|
displayName = 'Drift OAuth2 API';
|
||||||
|
properties = [
|
||||||
|
{
|
||||||
|
displayName: 'Authorization URL',
|
||||||
|
name: 'authUrl',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'https://dev.drift.com/authorize',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Access Token URL',
|
||||||
|
name: 'accessTokenUrl',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'https://driftapi.com/oauth2/token',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Auth URI Query Parameters',
|
||||||
|
name: 'authQueryParameters',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Scope',
|
||||||
|
name: 'scope',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'body',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ export class EventbriteApi implements ICredentialType {
|
||||||
displayName = 'Eventbrite API';
|
displayName = 'Eventbrite API';
|
||||||
properties = [
|
properties = [
|
||||||
{
|
{
|
||||||
displayName: 'API Key',
|
displayName: 'Private Key',
|
||||||
name: 'apiKey',
|
name: 'apiKey',
|
||||||
type: 'string' as NodePropertyTypes,
|
type: 'string' as NodePropertyTypes,
|
||||||
default: '',
|
default: '',
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
import {
|
||||||
|
ICredentialType,
|
||||||
|
NodePropertyTypes,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
|
||||||
|
export class EventbriteOAuth2Api implements ICredentialType {
|
||||||
|
name = 'eventbriteOAuth2Api';
|
||||||
|
extends = [
|
||||||
|
'oAuth2Api',
|
||||||
|
];
|
||||||
|
displayName = 'Eventbrite OAuth2 API';
|
||||||
|
properties = [
|
||||||
|
{
|
||||||
|
displayName: 'Authorization URL',
|
||||||
|
name: 'authUrl',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'https://www.eventbrite.com/oauth/authorize',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Access Token URL',
|
||||||
|
name: 'accessTokenUrl',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'https://www.eventbrite.com/oauth/token',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Scope',
|
||||||
|
name: 'scope',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Auth URI Query Parameters',
|
||||||
|
name: 'authQueryParameters',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'body'
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
|
@ -37,9 +37,44 @@ export class Drift implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'driftApi',
|
name: 'driftApi',
|
||||||
required: true,
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'accessToken',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'driftOAuth2Api',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'oAuth2',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Access Token',
|
||||||
|
value: 'accessToken',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'OAuth2',
|
||||||
|
value: 'oAuth2',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'accessToken',
|
||||||
|
description: 'The resource to operate on.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Resource',
|
displayName: 'Resource',
|
||||||
name: 'resource',
|
name: 'resource',
|
||||||
|
|
|
@ -12,25 +12,15 @@ import {
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export async function driftApiRequest(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
export async function driftApiRequest(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, query: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
|
||||||
const credentials = this.getCredentials('driftApi');
|
|
||||||
|
|
||||||
if (credentials === undefined) {
|
|
||||||
throw new Error('No credentials got returned!');
|
|
||||||
}
|
|
||||||
|
|
||||||
const endpoint = 'https://driftapi.com';
|
|
||||||
|
|
||||||
let options: OptionsWithUri = {
|
let options: OptionsWithUri = {
|
||||||
headers: {
|
headers: {},
|
||||||
Authorization: `Bearer ${credentials.accessToken}`,
|
|
||||||
},
|
|
||||||
method,
|
method,
|
||||||
body,
|
body,
|
||||||
qs: query,
|
qs: query,
|
||||||
uri: uri || `${endpoint}${resource}`,
|
uri: uri || `https://driftapi.com${resource}`,
|
||||||
json: true
|
json: true
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!Object.keys(body).length) {
|
if (!Object.keys(body).length) {
|
||||||
delete options.form;
|
delete options.form;
|
||||||
}
|
}
|
||||||
|
@ -38,11 +28,27 @@ export async function driftApiRequest(this: IExecuteFunctions | IWebhookFunction
|
||||||
delete options.qs;
|
delete options.qs;
|
||||||
}
|
}
|
||||||
options = Object.assign({}, options, option);
|
options = Object.assign({}, options, option);
|
||||||
|
|
||||||
|
const authenticationMethod = this.getNodeParameter('authentication', 0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
if (authenticationMethod === 'accessToken') {
|
||||||
|
const credentials = this.getCredentials('driftApi');
|
||||||
|
|
||||||
|
if (credentials === undefined) {
|
||||||
|
throw new Error('No credentials got returned!');
|
||||||
|
}
|
||||||
|
|
||||||
|
options.headers!['Authorization'] = `Bearer ${credentials.accessToken}`;
|
||||||
|
|
||||||
|
return await this.helpers.request!(options);
|
||||||
|
} else {
|
||||||
|
return await this.helpers.requestOAuth2!.call(this, 'driftOAuth2Api', options);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response) {
|
|
||||||
const errorMessage = error.message || (error.response.body && error.response.body.message );
|
if (error.response && error.response.body && error.response.body.error) {
|
||||||
|
const errorMessage = error.response.body.error.message;
|
||||||
throw new Error(`Drift error response [${error.statusCode}]: ${errorMessage}`);
|
throw new Error(`Drift error response [${error.statusCode}]: ${errorMessage}`);
|
||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
@ -35,7 +35,25 @@ export class EventbriteTrigger implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'eventbriteApi',
|
name: 'eventbriteApi',
|
||||||
required: true,
|
required: true,
|
||||||
}
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'privateKey',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'eventbriteOAuth2Api',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'oAuth2',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
webhooks: [
|
webhooks: [
|
||||||
{
|
{
|
||||||
|
@ -46,6 +64,23 @@ export class EventbriteTrigger implements INodeType {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Private Key',
|
||||||
|
value: 'privateKey',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'OAuth2',
|
||||||
|
value: 'oAuth2',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'privateKey',
|
||||||
|
description: 'The resource to operate on.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Organization',
|
displayName: 'Organization',
|
||||||
name: 'organization',
|
name: 'organization',
|
||||||
|
@ -149,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.',
|
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 = {
|
methods = {
|
||||||
|
@ -192,23 +226,39 @@ export class EventbriteTrigger implements INodeType {
|
||||||
default: {
|
default: {
|
||||||
async checkExists(this: IHookFunctions): Promise<boolean> {
|
async checkExists(this: IHookFunctions): Promise<boolean> {
|
||||||
const webhookData = this.getWorkflowStaticData('node');
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
if (webhookData.webhookId === undefined) {
|
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||||
return false;
|
const organisation = this.getNodeParameter('organization') as string;
|
||||||
|
const actions = this.getNodeParameter('actions') as string[];
|
||||||
|
|
||||||
|
const endpoint = `/organizations/${organisation}/webhooks/`;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const endpoint = `/webhooks/${webhookData.webhookId}/`;
|
|
||||||
try {
|
return false;
|
||||||
await eventbriteApiRequest.call(this, 'GET', endpoint);
|
|
||||||
} catch (e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
},
|
||||||
async create(this: IHookFunctions): Promise<boolean> {
|
async create(this: IHookFunctions): Promise<boolean> {
|
||||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||||
const webhookData = this.getWorkflowStaticData('node');
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
const organisation = this.getNodeParameter('organization') as string;
|
||||||
const event = this.getNodeParameter('event') as string;
|
const event = this.getNodeParameter('event') as string;
|
||||||
const actions = this.getNodeParameter('actions') as string[];
|
const actions = this.getNodeParameter('actions') as string[];
|
||||||
const endpoint = `/webhooks/`;
|
const endpoint = `/organizations/${organisation}/webhooks/`;
|
||||||
const body: IDataObject = {
|
const body: IDataObject = {
|
||||||
endpoint_url: webhookUrl,
|
endpoint_url: webhookUrl,
|
||||||
actions: actions.join(','),
|
actions: actions.join(','),
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
import { OptionsWithUri } from 'request';
|
import {
|
||||||
|
OptionsWithUri,
|
||||||
|
} from 'request';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
IExecuteSingleFunctions,
|
IExecuteSingleFunctions,
|
||||||
|
@ -6,16 +9,14 @@ import {
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
IWebhookFunctions,
|
IWebhookFunctions,
|
||||||
} from 'n8n-core';
|
} 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
|
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
|
||||||
const credentials = this.getCredentials('eventbriteApi');
|
|
||||||
if (credentials === undefined) {
|
|
||||||
throw new Error('No credentials got returned!');
|
|
||||||
}
|
|
||||||
|
|
||||||
let options: OptionsWithUri = {
|
let options: OptionsWithUri = {
|
||||||
headers: { 'Authorization': `Bearer ${credentials.apiKey}`},
|
headers: {},
|
||||||
method,
|
method,
|
||||||
qs,
|
qs,
|
||||||
body,
|
body,
|
||||||
|
@ -27,14 +28,26 @@ export async function eventbriteApiRequest(this: IHookFunctions | IExecuteFuncti
|
||||||
delete options.body;
|
delete options.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const authenticationMethod = this.getNodeParameter('authentication', 0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
if (authenticationMethod === 'privateKey') {
|
||||||
|
const credentials = this.getCredentials('eventbriteApi');
|
||||||
|
if (credentials === undefined) {
|
||||||
|
throw new Error('No credentials got returned!');
|
||||||
|
}
|
||||||
|
|
||||||
|
options.headers!['Authorization'] = `Bearer ${credentials.apiKey}`;
|
||||||
|
|
||||||
|
return await this.helpers.request!(options);
|
||||||
|
} else {
|
||||||
|
return await this.helpers.requestOAuth2!.call(this, 'eventbriteOAuth2Api', options);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
let errorMessage = error.message;
|
let errorMessage = error.message;
|
||||||
if (error.response.body && error.response.body.error_description) {
|
if (error.response.body && error.response.body.error_description) {
|
||||||
errorMessage = error.response.body.error_description;
|
errorMessage = error.response.body.error_description;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Eventbrite Error: ' + errorMessage);
|
throw new Error('Eventbrite Error: ' + errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,6 +137,13 @@ export class FacebookGraphApi implements INodeType {
|
||||||
placeholder: 'videos',
|
placeholder: 'videos',
|
||||||
required: false,
|
required: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Ignore SSL Issues',
|
||||||
|
name: 'allowUnauthorizedCerts',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'Still download the response even if SSL certificate validation is not possible. (Not recommended)',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Send Binary Data',
|
displayName: 'Send Binary Data',
|
||||||
name: 'sendBinaryData',
|
name: 'sendBinaryData',
|
||||||
|
@ -301,6 +308,7 @@ export class FacebookGraphApi implements INodeType {
|
||||||
qs: {
|
qs: {
|
||||||
access_token: graphApiCredentials!.accessToken,
|
access_token: graphApiCredentials!.accessToken,
|
||||||
},
|
},
|
||||||
|
rejectUnauthorized: !this.getNodeParameter('allowUnauthorizedCerts', itemIndex, false) as boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options !== undefined) {
|
if (options !== undefined) {
|
||||||
|
|
|
@ -47,8 +47,10 @@
|
||||||
"dist/credentials/CalendlyApi.credentials.js",
|
"dist/credentials/CalendlyApi.credentials.js",
|
||||||
"dist/credentials/DisqusApi.credentials.js",
|
"dist/credentials/DisqusApi.credentials.js",
|
||||||
"dist/credentials/DriftApi.credentials.js",
|
"dist/credentials/DriftApi.credentials.js",
|
||||||
|
"dist/credentials/DriftOAuth2Api.credentials.js",
|
||||||
"dist/credentials/DropboxApi.credentials.js",
|
"dist/credentials/DropboxApi.credentials.js",
|
||||||
"dist/credentials/EventbriteApi.credentials.js",
|
"dist/credentials/EventbriteApi.credentials.js",
|
||||||
|
"dist/credentials/EventbriteOAuth2Api.credentials.js",
|
||||||
"dist/credentials/FacebookGraphApi.credentials.js",
|
"dist/credentials/FacebookGraphApi.credentials.js",
|
||||||
"dist/credentials/FreshdeskApi.credentials.js",
|
"dist/credentials/FreshdeskApi.credentials.js",
|
||||||
"dist/credentials/FileMaker.credentials.js",
|
"dist/credentials/FileMaker.credentials.js",
|
||||||
|
|
Loading…
Reference in a new issue