From 0ca9c076ca51d313392e45c3b013f2e83aaea843 Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 28 Sep 2024 11:56:55 +0100 Subject: [PATCH] feat(Iterable Node): Add support for EDC and USDC selection (#10908) --- .../credentials/IterableApi.credentials.ts | 40 ++++++++++++++++++- .../nodes/Iterable/GenericFunctions.ts | 11 ++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/packages/nodes-base/credentials/IterableApi.credentials.ts b/packages/nodes-base/credentials/IterableApi.credentials.ts index ba0e9a01042c3..0b19b8226e1e2 100644 --- a/packages/nodes-base/credentials/IterableApi.credentials.ts +++ b/packages/nodes-base/credentials/IterableApi.credentials.ts @@ -1,4 +1,9 @@ -import type { ICredentialType, INodeProperties } from 'n8n-workflow'; +import type { + IAuthenticateGeneric, + ICredentialTestRequest, + ICredentialType, + INodeProperties, +} from 'n8n-workflow'; export class IterableApi implements ICredentialType { name = 'iterableApi'; @@ -15,5 +20,38 @@ export class IterableApi implements ICredentialType { typeOptions: { password: true }, default: '', }, + { + displayName: 'Region', + name: 'region', + type: 'options', + options: [ + { + name: 'EDC', + value: 'https://api.eu.iterable.com', + }, + { + name: 'USDC', + value: 'https://api.iterable.com', + }, + ], + default: 'https://api.iterable.com', + }, ]; + + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + headers: { + Api_Key: '={{$credentials.apiKey}}', + }, + }, + }; + + test: ICredentialTestRequest = { + request: { + baseURL: '={{$credentials?.region}}', + url: '/api/webhooks', + method: 'GET', + }, + }; } diff --git a/packages/nodes-base/nodes/Iterable/GenericFunctions.ts b/packages/nodes-base/nodes/Iterable/GenericFunctions.ts index 7ecc3cae029fd..3253c046de8a8 100644 --- a/packages/nodes-base/nodes/Iterable/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Iterable/GenericFunctions.ts @@ -2,8 +2,8 @@ import type { IDataObject, IExecuteFunctions, IHttpRequestMethods, + IHttpRequestOptions, ILoadOptionsFunctions, - IRequestOptions, JsonObject, } from 'n8n-workflow'; import { NodeApiError } from 'n8n-workflow'; @@ -12,7 +12,6 @@ export async function iterableApiRequest( this: IExecuteFunctions | ILoadOptionsFunctions, method: IHttpRequestMethods, resource: string, - body: any = {}, qs: IDataObject = {}, uri?: string, @@ -20,15 +19,14 @@ export async function iterableApiRequest( ): Promise { const credentials = await this.getCredentials('iterableApi'); - const options: IRequestOptions = { + const options: IHttpRequestOptions = { headers: { 'Content-Type': 'application/json', - Api_Key: credentials.apiKey, }, method, body, qs, - uri: uri || `https://api.iterable.com/api${resource}`, + url: uri || `${credentials.region}/api${resource}`, json: true, }; try { @@ -38,8 +36,7 @@ export async function iterableApiRequest( if (Object.keys(body as IDataObject).length === 0) { delete options.body; } - //@ts-ignore - return await this.helpers.request.call(this, options); + return await this.helpers.httpRequestWithAuthentication.call(this, 'iterableApi', options); } catch (error) { throw new NodeApiError(this.getNode(), error as JsonObject); }