n8n/packages/nodes-base/nodes/Raindrop/GenericFunctions.ts
Iván Ovejero b03e358a12
refactor: Integrate consistent-type-imports in nodes-base (no-changelog) (#5267)
* 👕 Enable `consistent-type-imports` for nodes-base

* 👕 Apply to nodes-base

*  Undo unrelated changes

* 🚚 Move to `.eslintrc.js` in nodes-base

*  Revert "Enable `consistent-type-imports` for nodes-base"

This reverts commit 529ad72b05.

* 👕 Fix severity
2023-01-27 12:22:44 +01:00

51 lines
1.1 KiB
TypeScript

import type { IExecuteFunctions, IHookFunctions } from 'n8n-core';
import type { IDataObject, ILoadOptionsFunctions } from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import type { OptionsWithUri } from 'request';
/**
* Make an authenticated API request to Raindrop.
*/
export async function raindropApiRequest(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
method: string,
endpoint: string,
qs: IDataObject,
body: IDataObject,
option: IDataObject = {},
) {
const options: OptionsWithUri = {
headers: {
'user-agent': 'n8n',
'Content-Type': 'application/json',
},
method,
uri: `https://api.raindrop.io/rest/v1${endpoint}`,
qs,
body,
json: true,
};
if (!Object.keys(body).length) {
delete options.body;
}
if (!Object.keys(qs).length) {
delete options.qs;
}
if (Object.keys(option).length !== 0) {
Object.assign(options, option);
}
try {
return await this.helpers.requestOAuth2.call(this, 'raindropOAuth2Api', options, {
includeCredentialsOnRefreshOnBody: true,
});
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}
}