Refactor out extra credentials parameter

This commit is contained in:
Iván Ovejero 2021-05-07 10:02:53 +02:00
parent 878e2093db
commit a885518019
2 changed files with 4 additions and 25 deletions

View file

@ -59,22 +59,6 @@ export class ZohoOAuth2Api implements ICredentialType {
default: 'https://accounts.zoho.com/oauth/v2/token',
required: true,
},
{
displayName: 'Region',
name: 'region',
type: 'options' as NodePropertyTypes,
default: 'europe',
options: [
{
name: 'Europe',
value: 'europe',
},
{
name: 'United States',
value: 'unitedStates',
},
],
},
{
displayName: 'Scope',
name: 'scope',

View file

@ -6,7 +6,6 @@ import {
import {
IDataObject,
NodeApiError,
NodeOperationError,
} from 'n8n-workflow';
import {
@ -27,8 +26,7 @@ export async function zohoApiRequest(
) {
const operation = this.getNodeParameter('operation', 0) as string;
const { region } = this.getCredentials('zohoOAuth2Api') as { region: 'europe' | 'unitedStates' };
const tld = getTld(region);
const { oauthTokenData: { api_domain: apiDomain } } = this.getCredentials('zohoOAuth2Api') as { oauthTokenData: { api_domain: string} };
const options: OptionsWithUri = {
body: {
@ -38,7 +36,7 @@ export async function zohoApiRequest(
},
method,
qs,
uri: uri ?? `https://www.zohoapis.${tld}/crm/v2${endpoint}`,
uri: uri ?? `${apiDomain}/crm/v2${endpoint}`,
json: true,
};
@ -51,7 +49,7 @@ export async function zohoApiRequest(
}
try {
console.log(JSON.stringify(options.body.data, null, 2));
console.log(JSON.stringify(options, null, 2));
const responseData = await this.helpers.requestOAuth2.call(this, 'zohoOAuth2Api', options);
return operation === 'getAll' ? responseData : responseData.data;
} catch (error) {
@ -151,9 +149,6 @@ function hasAddressFields(locationField: unknown): locationField is LocationFiel
return locationField.hasOwnProperty('address_fields');
}
const getTld = (region: 'europe' | 'unitedStates') =>
({ europe: 'eu', unitedStates: 'com' }[region]);
// ----------------------------------------
// types
// ----------------------------------------