n8n/packages/nodes-base/nodes/Segment/GenericFunctions.ts
agobrech 67983e8f94
fix: Remove redundant await in node's api request functions without try/catch (#4639)
* 🐛 Remove useless await for actionNetwork

* 🔥 Remove useless await

* 🔥 Remove useless await keyword to other generic functions
2022-11-22 17:57:17 +01:00

41 lines
923 B
TypeScript

import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
IExecuteSingleFunctions,
IHookFunctions,
ILoadOptionsFunctions,
IWebhookFunctions,
} from 'n8n-core';
import { IDataObject } from 'n8n-workflow';
export async function segmentApiRequest(
this:
| IHookFunctions
| IExecuteFunctions
| IExecuteSingleFunctions
| ILoadOptionsFunctions
| IWebhookFunctions,
method: string,
resource: string,
body: any = {}, // tslint:disable-line:no-any
qs: IDataObject = {},
uri?: string,
_option: IDataObject = {},
// tslint:disable-next-line:no-any
): Promise<any> {
const options: OptionsWithUri = {
headers: {
'Content-Type': 'application/json',
},
method,
qs,
body,
uri: uri || `https://api.segment.io/v1${resource}`,
json: true,
};
if (!Object.keys(body).length) {
delete options.body;
}
return this.helpers.requestWithAuthentication.call(this, 'segmentApi', options);
}