refactor(core): Remove linting exceptions in nodes-base (no-changelog) (#4944)

This commit is contained in:
Michael Kret
2023-01-13 19:11:56 +02:00
committed by GitHub
parent d7732ea150
commit 6608e69457
254 changed files with 2687 additions and 2675 deletions

View File

@@ -13,104 +13,6 @@ import moment from 'moment-timezone';
import jwt from 'jsonwebtoken';
export async function salesforceApiRequest(
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
method: string,
endpoint: string,
body: any = {},
qs: IDataObject = {},
uri?: string,
option: IDataObject = {},
): Promise<any> {
const authenticationMethod = this.getNodeParameter('authentication', 0, 'oAuth2') as string;
try {
if (authenticationMethod === 'jwt') {
// https://help.salesforce.com/articleView?id=remoteaccess_oauth_jwt_flow.htm&type=5
const credentialsType = 'salesforceJwtApi';
const credentials = await this.getCredentials(credentialsType);
const response = await getAccessToken.call(this, credentials);
const { instance_url, access_token } = response;
const options = getOptions.call(
this,
method,
uri || endpoint,
body,
qs,
instance_url as string,
);
Logger.debug(
`Authentication for "Salesforce" node is using "jwt". Invoking URI ${options.uri}`,
);
options.headers!.Authorization = `Bearer ${access_token}`;
Object.assign(options, option);
//@ts-ignore
return await this.helpers.request(options);
} else {
// https://help.salesforce.com/articleView?id=remoteaccess_oauth_web_server_flow.htm&type=5
const credentialsType = 'salesforceOAuth2Api';
const credentials = (await this.getCredentials(credentialsType)) as {
oauthTokenData: { instance_url: string };
};
const options = getOptions.call(
this,
method,
uri || endpoint,
body,
qs,
credentials.oauthTokenData.instance_url,
);
Logger.debug(
`Authentication for "Salesforce" node is using "OAuth2". Invoking URI ${options.uri}`,
);
Object.assign(options, option);
//@ts-ignore
return await this.helpers.requestOAuth2.call(this, credentialsType, options);
}
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}
}
export async function salesforceApiRequestAllItems(
this: IExecuteFunctions | ILoadOptionsFunctions,
propertyName: string,
method: string,
endpoint: string,
body: any = {},
query: IDataObject = {},
): Promise<any> {
const returnData: IDataObject[] = [];
let responseData;
let uri: string | undefined;
do {
responseData = await salesforceApiRequest.call(this, method, endpoint, body, query, uri);
uri = `${endpoint}/${responseData.nextRecordsUrl?.split('/')?.pop()}`;
returnData.push.apply(returnData, responseData[propertyName]);
} while (responseData.nextRecordsUrl !== undefined && responseData.nextRecordsUrl !== null);
return returnData;
}
/**
* Sorts the given options alphabetically
*
*/
export function sortOptions(options: INodePropertyOptions[]): void {
options.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
}
function getOptions(
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
method: string,
@@ -181,6 +83,114 @@ async function getAccessToken(
return this.helpers.request(options);
}
export async function salesforceApiRequest(
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
method: string,
endpoint: string,
body: any = {},
qs: IDataObject = {},
uri?: string,
option: IDataObject = {},
): Promise<any> {
const authenticationMethod = this.getNodeParameter('authentication', 0, 'oAuth2') as string;
try {
if (authenticationMethod === 'jwt') {
// https://help.salesforce.com/articleView?id=remoteaccess_oauth_jwt_flow.htm&type=5
const credentialsType = 'salesforceJwtApi';
const credentials = await this.getCredentials(credentialsType);
const response = await getAccessToken.call(this, credentials);
const { instance_url, access_token } = response;
const options = getOptions.call(
this,
method,
uri ?? endpoint,
body,
qs,
instance_url as string,
);
Logger.debug(
`Authentication for "Salesforce" node is using "jwt". Invoking URI ${options.uri}`,
);
options.headers!.Authorization = `Bearer ${access_token}`;
Object.assign(options, option);
//@ts-ignore
return await this.helpers.request(options);
} else {
// https://help.salesforce.com/articleView?id=remoteaccess_oauth_web_server_flow.htm&type=5
const credentialsType = 'salesforceOAuth2Api';
const credentials = (await this.getCredentials(credentialsType)) as {
oauthTokenData: { instance_url: string };
};
const options = getOptions.call(
this,
method,
uri ?? endpoint,
body,
qs,
credentials.oauthTokenData.instance_url,
);
Logger.debug(
`Authentication for "Salesforce" node is using "OAuth2". Invoking URI ${options.uri}`,
);
Object.assign(options, option);
//@ts-ignore
return await this.helpers.requestOAuth2.call(this, credentialsType, options);
}
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}
}
export async function salesforceApiRequestAllItems(
this: IExecuteFunctions | ILoadOptionsFunctions,
propertyName: string,
method: string,
endpoint: string,
body: any = {},
query: IDataObject = {},
): Promise<any> {
const returnData: IDataObject[] = [];
let responseData;
let uri: string | undefined;
do {
responseData = await salesforceApiRequest.call(this, method, endpoint, body, query, uri);
uri = `${endpoint}/${responseData.nextRecordsUrl?.split('/')?.pop()}`;
returnData.push.apply(returnData, responseData[propertyName]);
} while (responseData.nextRecordsUrl !== undefined && responseData.nextRecordsUrl !== null);
return returnData;
}
/**
* Sorts the given options alphabetically
*
*/
export function sortOptions(options: INodePropertyOptions[]): void {
options.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
}
export function getValue(value: any) {
if (moment(value).isValid()) {
return value;
} else if (typeof value === 'string') {
return `'${value}'`;
} else {
return value;
}
}
export function getConditions(options: IDataObject) {
const conditions = (options.conditionsUi as IDataObject)?.conditionValues as IDataObject[];
let data = undefined;
@@ -235,13 +245,3 @@ export function getQuery(options: IDataObject, sobject: string, returnAll: boole
return query;
}
export function getValue(value: any) {
if (moment(value).isValid()) {
return value;
} else if (typeof value === 'string') {
return `'${value}'`;
} else {
return value;
}
}

View File

@@ -303,7 +303,7 @@ export class Salesforce implements INodeType {
const userName = user.Name;
const userId = user.Id;
returnData.push({
name: userPrefix + userName,
name: userPrefix + (userName as string),
value: userId,
});
}
@@ -349,7 +349,7 @@ export class Salesforce implements INodeType {
const userName = user.Name;
const userId = user.Id;
returnData.push({
name: userPrefix + userName,
name: userPrefix + (userName as string),
value: userId,
});
}
@@ -1854,7 +1854,7 @@ export class Salesforce implements INodeType {
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
body.entity_content.PathOnClient = `${title}.${
additionalFields.fileExtension || binaryData.fileExtension
additionalFields.fileExtension ?? binaryData.fileExtension
}`;
data = {
entity_content: {