From 1c9a78e6249539a4e5abe6429be08f59d32ed230 Mon Sep 17 00:00:00 2001 From: Ricardo Espinoza Date: Tue, 26 Nov 2019 15:38:38 -0500 Subject: [PATCH] :tada: node-setup --- .../credentials/JiraApi.credentials.ts | 18 ++++ .../nodes-base/nodes/Jira/GenericFunctions.ts | 82 ++++++++++++++++++ packages/nodes-base/nodes/Jira/Jira.node.ts | 60 +++++++++++++ packages/nodes-base/nodes/Jira/jira.png | Bin 0 -> 2343 bytes packages/nodes-base/package.json | 6 +- 5 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 packages/nodes-base/credentials/JiraApi.credentials.ts create mode 100644 packages/nodes-base/nodes/Jira/GenericFunctions.ts create mode 100644 packages/nodes-base/nodes/Jira/Jira.node.ts create mode 100644 packages/nodes-base/nodes/Jira/jira.png diff --git a/packages/nodes-base/credentials/JiraApi.credentials.ts b/packages/nodes-base/credentials/JiraApi.credentials.ts new file mode 100644 index 0000000000..ddb1996454 --- /dev/null +++ b/packages/nodes-base/credentials/JiraApi.credentials.ts @@ -0,0 +1,18 @@ +import { + ICredentialType, + NodePropertyTypes, +} from 'n8n-workflow'; + + +export class JiraApi implements ICredentialType { + name = 'jiraApi'; + displayName = 'Jira API'; + properties = [ + { + displayName: 'API Key', + name: 'apiKey', + type: 'string' as NodePropertyTypes, + default: '', + }, + ]; +} diff --git a/packages/nodes-base/nodes/Jira/GenericFunctions.ts b/packages/nodes-base/nodes/Jira/GenericFunctions.ts new file mode 100644 index 0000000000..f52062f8ae --- /dev/null +++ b/packages/nodes-base/nodes/Jira/GenericFunctions.ts @@ -0,0 +1,82 @@ +import { OptionsWithUri } from 'request'; + +import { + IExecuteFunctions, + IHookFunctions, + ILoadOptionsFunctions, + IExecuteSingleFunctions +} from 'n8n-core'; + +import { + IDataObject, +} from 'n8n-workflow'; + +export async function jiraApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, endpoint: string, method: string, body: any = {}, query?: IDataObject, uri?: string): Promise { // tslint:disable-line:no-any + const credentials = this.getCredentials('jiraApi'); + if (credentials === undefined) { + throw new Error('No credentials got returned!'); + } + + const headerWithAuthentication = Object.assign({}, + { Authorization: `Bearer ${credentials.apiKey}`, Accept: 'application/json' }); + + const options: OptionsWithUri = { + headers: headerWithAuthentication, + method, + qs: query, + uri: uri || `https://api.intercom.io${endpoint}`, + body, + json: true + }; + + try { + return await this.helpers.request!(options); + } catch (error) { + const errorMessage = error.response.body.message || error.response.body.Message; + + if (errorMessage !== undefined) { + throw errorMessage; + } + throw error.response.body; + } +} + + + +/** + * Make an API request to paginated intercom endpoint + * and return all results + */ +export async function jiraApiRequestAllItems(this: IHookFunctions | IExecuteFunctions, propertyName: string, endpoint: string, method: string, body: any = {}, query: IDataObject = {}): Promise { // tslint:disable-line:no-any + + const returnData: IDataObject[] = []; + + let responseData; + + query.per_page = 60; + + let uri: string | undefined; + + do { + responseData = await jiraApiRequest.call(this, endpoint, method, body, query, uri); + uri = responseData.pages.next; + returnData.push.apply(returnData, responseData[propertyName]); + } while ( + responseData.pages !== undefined && + responseData.pages.next !== undefined && + responseData.pages.next !== null + ); + + return returnData; +} + + +export function validateJSON(json: string | undefined): any { // tslint:disable-line:no-any + let result; + try { + result = JSON.parse(json!); + } catch (exception) { + result = ''; + } + return result; +} diff --git a/packages/nodes-base/nodes/Jira/Jira.node.ts b/packages/nodes-base/nodes/Jira/Jira.node.ts new file mode 100644 index 0000000000..df38733e83 --- /dev/null +++ b/packages/nodes-base/nodes/Jira/Jira.node.ts @@ -0,0 +1,60 @@ +import { + IExecuteFunctions, +} from 'n8n-core'; +import { + IDataObject, + INodeTypeDescription, + INodeExecutionData, + INodeType, + ILoadOptionsFunctions, + INodePropertyOptions, +} from 'n8n-workflow'; +import { + jiraApiRequest, + jiraApiRequestAllItems, + validateJSON, +} from './GenericFunctions'; + +export class Jira implements INodeType { + description: INodeTypeDescription = { + displayName: 'Jira', + name: 'Jira', + icon: 'file:jira.png', + group: ['output'], + version: 1, + subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}', + description: 'Consume Jira API', + defaults: { + name: 'Jira', + color: '#c02428', + }, + inputs: ['main'], + outputs: ['main'], + credentials: [ + { + name: 'jiraApi', + required: true, + } + ], + properties: [ + { + displayName: 'Resource', + name: 'resource', + type: 'options', + options: [ + { + name: 'Issue', + value: 'issue', + description: 'Creates an issue or, where the option to create subtasks is enabled in Jira, a subtask', + }, + ], + default: 'issue', + description: 'Resource to consume.', + }, + ], + }; + + async execute(this: IExecuteFunctions): Promise { + return [this.helpers.returnJsonArray({})]; + } +} diff --git a/packages/nodes-base/nodes/Jira/jira.png b/packages/nodes-base/nodes/Jira/jira.png new file mode 100644 index 0000000000000000000000000000000000000000..665ee5a217d7ee3dffcbec3bf4af49bdc3797f7c GIT binary patch literal 2343 zcmY*bdpy%^AO0;QbBNNT5tbgsQ#&AGwmB!tX{9zIGsDb`ZOo~12rY#UBJr{`5jiD^ zJV|9aM8*tLl!TBZDi8He_4dB+{rTL7?{#0_>-v80ziy7Jv%Ml%9Si_~qQgF0oMcB! zCT!hW$@(#3-2ura9bn~T1prm)^2d5;ix^p}> z|1Q%$@D@!6_hm@&nGTTJ5Pu1BMOg3YL+XranmaI5A{G~Z@S~->P@_Dz8_yL8AvFVj zrytiTQZF!!`IF@L?Q3+!n=rgSSB1i-_R0U^6+!nx?N%^X*vH1B)ccXL*`<0-R#hQ`Y zqHxenfXm1b@$y`wBXG|%WzvWNTeS0Obc;U^3jfrE=sDrmk-W}uxt{_GuYRIBSRPR_ zUBC0jw>?|4p2fNp`_Q;j8>}zDPwBlsroTSAp{DS}trLxc=b50+M~nF@zot zImnJ6y@MV^WR5i6-#cX;Tri+ijXaTsO?K%@FDNP7L>P!8_16oR>lAoj$NMXlv9A2p-8mCE!LUZ-iki?&8WX@+6!3(Nv4}qbVBWf=VX7} z9jWZwG@pU8xv)~4BVJJdK?LD#t<~im!%F9I=EP??+>)F0 z9{A!H3DQF=L$Y5Yp-IqfyV~`p4h!)i!w=u!gNowwn2(9=fnK_4j&`F+yP3-*p9Ygz z1${Rs4cBD&o=Uv;ViT+95l=rif6R^g37<_TpNt<*$z!-O~N!h|Jc~>BJ}gt(DjUSv_9*?y{cr z*Exr_GiOd$Wi&nz?H!S-KLL^>M}zF-7A(ozRL}M zOdwvcpZn>bC>~)9jw24=b&VrFV=W$~PA#N0Md|3;tbf93Z)1Fg(9btu2KWqj^Wz+- z@e5WKyRdG`^Tp!J>++a2D6cs0H4_UMD-uz45Z90Gdl-=RO&wng%e$n1Kp|9XaKGY2 zx=4pOKk060IO^T}(KUuHkn!QJ=jp#W1e*V*TtUD5=GoN>z5X4uO<$*a2Xlg`=bt8KSPy?*<2IU1%UWD+4FA$z^tn~RoOj)@`bIZDadI+Nj=zm} zuM=Bk9V{StWT(7^_Q|Om%SDfqx8>NEfXdsvzg{~oDy9@2bdDk?kBuJ&`W3P~YA+hl zE$J;dI;dcDC^uzKLow=3{GI077dO97LS*o7K2JD|t(0#@2A~%yf9yPG zT$L|$hs)3!nj2jjaTNTC6EgAJ$R2O^Iu?fZgXjOncVxQz4qTdF!)PoWXA4Y7{#Q!p zGd)=WNq?J}xKDI@X=!}F9VgnuoDxwn(S?0BZ}Y`&b*G6thZLx|rj8BY!;*AF-;if sXPS)HrV(EB)fmkLj}ef2xyVCQUGZtausZ?IM^SpWb4 literal 0 HcmV?d00001 diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index ae70262dc8..6673d95d77 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -42,7 +42,8 @@ "dist/credentials/HttpDigestAuth.credentials.js", "dist/credentials/HttpHeaderAuth.credentials.js", "dist/credentials/IntercomApi.credentials.js", - "dist/credentials/Imap.credentials.js", + "dist/credentials/Imap.credentials.js", + "dist/credentials/JiraApi.credentials.js", "dist/credentials/LinkFishApi.credentials.js", "dist/credentials/MailchimpApi.credentials.js", "dist/credentials/MailgunApi.credentials.js", @@ -100,7 +101,8 @@ "dist/nodes/HttpRequest.node.js", "dist/nodes/If.node.js", "dist/nodes/Interval.node.js", - "dist/nodes/Intercom/Intercom.node.js", + "dist/nodes/Intercom/Intercom.node.js", + "dist/nodes/Jira/Jira.node.js", "dist/nodes/LinkFish/LinkFish.node.js", "dist/nodes/Mailchimp/Mailchimp.node.js", "dist/nodes/Mailgun/Mailgun.node.js",