mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 02:51:14 +00:00
refactor: Add IRequestOptions type to helpers.request for more type safety (no-changelog) (#8563)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -4,14 +4,14 @@ import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
IHttpRequestMethods,
|
||||
ILoadOptionsFunctions,
|
||||
IPollFunctions,
|
||||
IRequestOptions,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError } from 'n8n-workflow';
|
||||
|
||||
import type { OptionsWithUri } from 'request';
|
||||
|
||||
// Interfaces and Types -------------------------------------------------------------
|
||||
interface IHaloPSATokens {
|
||||
scope: string;
|
||||
@@ -35,7 +35,7 @@ export async function getAccessTokens(
|
||||
): Promise<IHaloPSATokens> {
|
||||
const credentials = await this.getCredentials('haloPSAApi');
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
const options: IRequestOptions = {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
@@ -60,7 +60,7 @@ export async function getAccessTokens(
|
||||
|
||||
export async function haloPSAApiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IPollFunctions,
|
||||
method: string,
|
||||
method: IHttpRequestMethods,
|
||||
resource: string,
|
||||
accessToken: string,
|
||||
body: IDataObject | IDataObject[] = {},
|
||||
@@ -70,7 +70,7 @@ export async function haloPSAApiRequest(
|
||||
const resourceApiUrl = (await this.getCredentials('haloPSAApi')).resourceApiUrl as string;
|
||||
|
||||
try {
|
||||
let options: OptionsWithUri = {
|
||||
let options: IRequestOptions = {
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
'User-Agent': 'https://n8n.io',
|
||||
@@ -96,7 +96,7 @@ export async function haloPSAApiRequest(
|
||||
return result;
|
||||
} catch (error) {
|
||||
const message = (error as JsonObject).message as string;
|
||||
if (method === 'DELETE' || method === 'GET' || (method === 'UPDATE' && message)) {
|
||||
if (method === 'DELETE' || method === 'GET' || (method === 'POST' && message)) {
|
||||
let newErrorMessage;
|
||||
if (message.includes('400')) {
|
||||
console.log(message);
|
||||
@@ -151,7 +151,7 @@ export async function haloPSAApiRequest(
|
||||
export async function haloPSAApiRequestAllItems(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions,
|
||||
propertyName: string,
|
||||
method: string,
|
||||
method: IHttpRequestMethods,
|
||||
endpoint: string,
|
||||
accessToken: string,
|
||||
body = {},
|
||||
@@ -224,7 +224,7 @@ export async function validateCredentials(
|
||||
): Promise<IHaloPSATokens> {
|
||||
const credentials = decryptedCredentials;
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
const options: IRequestOptions = {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user