mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
small fix
This commit is contained in:
commit
364fd5276b
|
@ -0,0 +1,50 @@
|
||||||
|
import {
|
||||||
|
ICredentialType,
|
||||||
|
NodePropertyTypes,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
|
||||||
|
export class WebflowOAuth2Api implements ICredentialType {
|
||||||
|
name = 'webflowOAuth2Api';
|
||||||
|
extends = [
|
||||||
|
'oAuth2Api',
|
||||||
|
];
|
||||||
|
displayName = 'Webflow OAuth2 API';
|
||||||
|
properties = [
|
||||||
|
{
|
||||||
|
displayName: 'Authorization URL',
|
||||||
|
name: 'authUrl',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'https://webflow.com/oauth/authorize',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Access Token URL',
|
||||||
|
name: 'accessTokenUrl',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'https://api.webflow.com/oauth/access_token',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Scope',
|
||||||
|
name: 'scope',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Auth URI Query Parameters',
|
||||||
|
name: 'authQueryParameters',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
description: 'For some services additional query parameters have to be set which can be defined here.',
|
||||||
|
placeholder: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'body',
|
||||||
|
description: '',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
|
@ -376,7 +376,7 @@ export const taskFields = [
|
||||||
'Flag indicating whether hidden tasks are returned in the result'
|
'Flag indicating whether hidden tasks are returned in the result'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'updated Min',
|
displayName: 'Updated Min',
|
||||||
name: 'updatedMin',
|
name: 'updatedMin',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
import { OptionsWithUri } from 'request';
|
import {
|
||||||
|
OptionsWithUri,
|
||||||
|
} from 'request';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
IExecuteSingleFunctions,
|
IExecuteSingleFunctions,
|
||||||
|
@ -6,17 +9,16 @@ import {
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
IWebhookFunctions,
|
IWebhookFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
import { IDataObject } from 'n8n-workflow';
|
|
||||||
|
import {
|
||||||
|
IDataObject,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export async function webflowApiRequest(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 webflowApiRequest(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('webflowApi');
|
const authenticationMethod = this.getNodeParameter('authentication', 0);
|
||||||
if (credentials === undefined) {
|
|
||||||
throw new Error('No credentials got returned!');
|
|
||||||
}
|
|
||||||
|
|
||||||
let options: OptionsWithUri = {
|
let options: OptionsWithUri = {
|
||||||
headers: {
|
headers: {
|
||||||
authorization: `Bearer ${credentials.accessToken}`,
|
|
||||||
'accept-version': '1.0.0',
|
'accept-version': '1.0.0',
|
||||||
},
|
},
|
||||||
method,
|
method,
|
||||||
|
@ -31,14 +33,22 @@ export async function webflowApiRequest(this: IHookFunctions | IExecuteFunctions
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
if (authenticationMethod === 'accessToken') {
|
||||||
} catch (error) {
|
const credentials = this.getCredentials('webflowApi');
|
||||||
|
if (credentials === undefined) {
|
||||||
|
throw new Error('No credentials got returned!');
|
||||||
|
}
|
||||||
|
|
||||||
let errorMessage = error.message;
|
options.headers!['authorization'] = `Bearer ${credentials.accessToken}`;
|
||||||
if (error.response.body && error.response.body.err) {
|
|
||||||
errorMessage = error.response.body.err;
|
return await this.helpers.request!(options);
|
||||||
|
} else {
|
||||||
|
return await this.helpers.requestOAuth2!.call(this, 'webflowOAuth2Api', options);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
throw new Error('Webflow Error: ' + errorMessage);
|
if (error.response.body.err) {
|
||||||
|
throw new Error(`Webflow Error: [${error.statusCode}]: ${error.response.body.err}`);
|
||||||
|
}
|
||||||
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,25 @@ export class WebflowTrigger implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'webflowApi',
|
name: 'webflowApi',
|
||||||
required: true,
|
required: true,
|
||||||
}
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'accessToken',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'webflowOAuth2Api',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'oAuth2',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
webhooks: [
|
webhooks: [
|
||||||
{
|
{
|
||||||
|
@ -45,6 +63,23 @@ export class WebflowTrigger implements INodeType {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Access Token',
|
||||||
|
value: 'accessToken',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'OAuth2',
|
||||||
|
value: 'oAuth2',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'accessToken',
|
||||||
|
description: 'Method of authentication.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Site',
|
displayName: 'Site',
|
||||||
name: 'site',
|
name: 'site',
|
||||||
|
|
|
@ -132,6 +132,7 @@
|
||||||
"dist/credentials/UpleadApi.credentials.js",
|
"dist/credentials/UpleadApi.credentials.js",
|
||||||
"dist/credentials/VeroApi.credentials.js",
|
"dist/credentials/VeroApi.credentials.js",
|
||||||
"dist/credentials/WebflowApi.credentials.js",
|
"dist/credentials/WebflowApi.credentials.js",
|
||||||
|
"dist/credentials/WebflowOAuth2Api.credentials.js",
|
||||||
"dist/credentials/WooCommerceApi.credentials.js",
|
"dist/credentials/WooCommerceApi.credentials.js",
|
||||||
"dist/credentials/WordpressApi.credentials.js",
|
"dist/credentials/WordpressApi.credentials.js",
|
||||||
"dist/credentials/ZendeskApi.credentials.js",
|
"dist/credentials/ZendeskApi.credentials.js",
|
||||||
|
|
Loading…
Reference in a new issue