mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +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:
@@ -1,15 +1,15 @@
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
IHttpRequestMethods,
|
||||
INodeExecutionData,
|
||||
INodeType,
|
||||
INodeTypeDescription,
|
||||
IRequestOptions,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import type { OptionsWithUri } from 'request';
|
||||
|
||||
export class FacebookGraphApi implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
displayName: 'Facebook Graph API',
|
||||
@@ -308,7 +308,10 @@ export class FacebookGraphApi implements INodeType {
|
||||
const graphApiCredentials = await this.getCredentials('facebookGraphApi');
|
||||
|
||||
const hostUrl = this.getNodeParameter('hostUrl', itemIndex) as string;
|
||||
const httpRequestMethod = this.getNodeParameter('httpRequestMethod', itemIndex) as string;
|
||||
const httpRequestMethod = this.getNodeParameter(
|
||||
'httpRequestMethod',
|
||||
itemIndex,
|
||||
) as IHttpRequestMethods;
|
||||
let graphApiVersion = this.getNodeParameter('graphApiVersion', itemIndex) as string;
|
||||
const node = this.getNodeParameter('node', itemIndex) as string;
|
||||
const edge = this.getNodeParameter('edge', itemIndex) as string;
|
||||
@@ -323,7 +326,10 @@ export class FacebookGraphApi implements INodeType {
|
||||
uri = `${uri}/${edge}`;
|
||||
}
|
||||
|
||||
const requestOptions: OptionsWithUri = {
|
||||
const qs: IDataObject = {
|
||||
access_token: graphApiCredentials.accessToken,
|
||||
};
|
||||
const requestOptions: IRequestOptions = {
|
||||
headers: {
|
||||
accept: 'application/json,text/*;q=0.99',
|
||||
},
|
||||
@@ -331,9 +337,6 @@ export class FacebookGraphApi implements INodeType {
|
||||
uri,
|
||||
json: true,
|
||||
gzip: true,
|
||||
qs: {
|
||||
access_token: graphApiCredentials.accessToken,
|
||||
},
|
||||
rejectUnauthorized: !this.getNodeParameter('allowUnauthorizedCerts', itemIndex, false),
|
||||
};
|
||||
|
||||
@@ -343,7 +346,7 @@ export class FacebookGraphApi implements INodeType {
|
||||
const fields = options.fields as IDataObject;
|
||||
if (fields.field !== undefined) {
|
||||
const fieldsCsv = (fields.field as IDataObject[]).map((field) => field.name).join(',');
|
||||
requestOptions.qs.fields = fieldsCsv;
|
||||
qs.fields = fieldsCsv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,11 +356,13 @@ export class FacebookGraphApi implements INodeType {
|
||||
|
||||
if (queryParameters.parameter !== undefined) {
|
||||
for (const queryParameter of queryParameters.parameter as IDataObject[]) {
|
||||
requestOptions.qs[queryParameter.name as string] = queryParameter.value;
|
||||
qs[queryParameter.name as string] = queryParameter.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
requestOptions.qs = qs;
|
||||
|
||||
// Add the query parameters defined as a JSON object
|
||||
if (options.queryParametersJson) {
|
||||
let queryParametersJsonObj = {};
|
||||
@@ -366,7 +371,6 @@ export class FacebookGraphApi implements INodeType {
|
||||
} catch {
|
||||
/* Do nothing, at least for now */
|
||||
}
|
||||
const qs = requestOptions.qs;
|
||||
requestOptions.qs = {
|
||||
...qs,
|
||||
...queryParametersJsonObj,
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { OptionsWithUri } from 'request';
|
||||
|
||||
import type {
|
||||
IDataObject,
|
||||
IExecuteFunctions,
|
||||
IHookFunctions,
|
||||
IHttpRequestMethods,
|
||||
ILoadOptionsFunctions,
|
||||
IRequestOptions,
|
||||
IWebhookFunctions,
|
||||
JsonObject,
|
||||
} from 'n8n-workflow';
|
||||
@@ -14,7 +14,7 @@ import { capitalCase } from 'change-case';
|
||||
|
||||
export async function facebookApiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
||||
method: string,
|
||||
method: IHttpRequestMethods,
|
||||
resource: string,
|
||||
|
||||
body: any = {},
|
||||
@@ -32,7 +32,7 @@ export async function facebookApiRequest(
|
||||
|
||||
qs.access_token = credentials.accessToken;
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
const options: IRequestOptions = {
|
||||
headers: {
|
||||
accept: 'application/json,text/*;q=0.99',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user