From 6d64e84f5e19d5f6d83ccc0a55cdcbd256e5804f Mon Sep 17 00:00:00 2001 From: agobrech <45268029+agobrech@users.noreply.github.com> Date: Sun, 19 Jun 2022 05:10:08 +0200 Subject: [PATCH] feat(Twake Node): Update icon, add cred test and custom operation support (#3431) * Update icon, add cred injection and test, update url for integration * :zap: Fix error display for some edge cases Co-authored-by: Jan Oberhauser --- .../credentials/TwakeCloudApi.credentials.ts | 16 ++++++++++++++++ .../nodes/Twake/GenericFunctions.ts | 9 +++------ packages/nodes-base/nodes/Twake/twake.png | Bin 1996 -> 3673 bytes 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/nodes-base/credentials/TwakeCloudApi.credentials.ts b/packages/nodes-base/credentials/TwakeCloudApi.credentials.ts index 798bb9efe3..93abdec472 100644 --- a/packages/nodes-base/credentials/TwakeCloudApi.credentials.ts +++ b/packages/nodes-base/credentials/TwakeCloudApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateBearer, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -15,4 +17,18 @@ export class TwakeCloudApi implements ICredentialType { default: '', }, ]; + authenticate = { + type: 'bearer', + properties: { + tokenPropertyName: 'workspaceKey', + }, + } as IAuthenticateBearer; + + test: ICredentialTestRequest = { + request: { + baseURL: 'https://plugins.twake.app/plugins/n8n', + url: '/channel', + method: 'POST', + }, + }; } diff --git a/packages/nodes-base/nodes/Twake/GenericFunctions.ts b/packages/nodes-base/nodes/Twake/GenericFunctions.ts index c02f3f0a05..66b182e6f6 100644 --- a/packages/nodes-base/nodes/Twake/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Twake/GenericFunctions.ts @@ -28,15 +28,12 @@ export async function twakeApiRequest(this: IHookFunctions | IExecuteFunctions | method, body, qs: query, - uri: uri || `https://connectors.albatros.twakeapp.com/n8n${resource}`, + uri: uri || `https://plugins.twake.app/plugins/n8n${resource}`, json: true, }; // if (authenticationMethod === 'cloud') { - const credentials = await this.getCredentials('twakeCloudApi'); - options.headers!.Authorization = `Bearer ${credentials.workspaceKey}`; - // } else { // const credentials = await this.getCredentials('twakeServerApi'); // options.auth = { user: credentials!.publicId as string, pass: credentials!.privateApiKey as string }; @@ -44,9 +41,9 @@ export async function twakeApiRequest(this: IHookFunctions | IExecuteFunctions | // } try { - return await this.helpers.request!(options); + return await this.helpers.requestWithAuthentication.call(this, 'twakeCloudApi', options); } catch (error) { - if (error.error.code === 'ECONNREFUSED') { + if (error.error?.code === 'ECONNREFUSED') { throw new NodeApiError(this.getNode(), error, { message: 'Twake host is not accessible!' }); } throw new NodeApiError(this.getNode(), error); diff --git a/packages/nodes-base/nodes/Twake/twake.png b/packages/nodes-base/nodes/Twake/twake.png index 6bc6953716f8ec3f36df7f8a323cc630e1d71de2..3afce345b12cec257a2f5aa2ef60535d5e3aa28b 100644 GIT binary patch literal 3673 zcmY*cc|4SB*nY>pE3#zDu4G>Z8H{L>eJ#uAWFNc1j9vCZp~Ml!7RHi2`xeTUJ!2h9 z99yGhhz3XM8|U<|AJzcmtC99tX10CfJ z{XXwcNi?onMp^(+_n7&+11)7Q=%j0I1OTCz03a$30REe=U71Xo2_0z{U1J+1#iUJQ4*uCt_>Ohm^n`a1Z3y%Qrv9ZZ&_ok zjSQhqC~p}DXOyFhOt81_sR~dJhEkxn3&ue(*xSno4Gq>1{)Yjj;M20Ku;4!wjHiaM zwUMddb(Fu0pt6jdjGQoxNl;Kw-QO7rHHYi`l2djX!fqIhFH}}GC@4rKNKppm?X&$;<0%KPM4a(LNT2nL ztx;GJXJA>OHVYY%LmwZLTd}ItZ$>)NB;HD9vg%e|{rKIF3m@xdmt9SCyv>!1>RwFr z8(uF{7Fo#MgX=48NT&CsgVOoaO=4j&dKX>PHpGSyL!nhe7gnT_M=d>yQgpMt4wr_6 z@I#&JGoQR#`QJhw2q?b1p8hVpy2e};7;f<>Y?%+cqbh=aJkCD7KVDT2C`PJrV-yo0 z*2FCPt3HC@?mT!4;j9>^VY@QvBV@ve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