mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor: Format nodes-base package (A-F) (#3800)
* 🔨 prettier formated nodes - A * 🔨 prettier formated nodes - B * ⚡ prettier formated nodes - C * ⚡ prettier formated nodes - D * ⚡ prettier formated nodes - E-F * 🎨 Adjust nodes-base formatting command (#3805) * Format additional files in nodes A-F (#3811) * ⚡ fixes * 🎨 Add Mindee to ignored dirs Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
@@ -5,15 +5,9 @@ import {
|
||||
IWebhookFunctions,
|
||||
} from 'n8n-core';
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
INodePropertyOptions,
|
||||
NodeApiError,
|
||||
} from 'n8n-workflow';
|
||||
import { IDataObject, INodePropertyOptions, NodeApiError } from 'n8n-workflow';
|
||||
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
export interface IFormstackFieldDefinitionType {
|
||||
id: string;
|
||||
@@ -58,7 +52,14 @@ export enum FormstackFieldFormat {
|
||||
* @param {object} body
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, endpoint: string, body: IDataObject = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
export async function apiRequest(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
body: IDataObject = {},
|
||||
query: IDataObject = {},
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0);
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
@@ -76,7 +77,7 @@ export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoa
|
||||
|
||||
try {
|
||||
if (authenticationMethod === 'accessToken') {
|
||||
const credentials = await this.getCredentials('formstackApi') as IDataObject;
|
||||
const credentials = (await this.getCredentials('formstackApi')) as IDataObject;
|
||||
|
||||
options.headers!['Authorization'] = `Bearer ${credentials.accessToken}`;
|
||||
return await this.helpers.request!(options);
|
||||
@@ -88,7 +89,6 @@ export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoa
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make an API request to paginated Formstack endpoint
|
||||
* and return all results
|
||||
@@ -101,8 +101,15 @@ export async function apiRequest(this: IHookFunctions | IExecuteFunctions | ILoa
|
||||
* @param {IDataObject} [query]
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
export async function apiRequestAllItems(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, endpoint: string, body: IDataObject, dataKey: string, query?: IDataObject): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
export async function apiRequestAllItems(
|
||||
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
|
||||
method: string,
|
||||
endpoint: string,
|
||||
body: IDataObject,
|
||||
dataKey: string,
|
||||
query?: IDataObject,
|
||||
// tslint:disable-next-line:no-any
|
||||
): Promise<any> {
|
||||
if (query === undefined) {
|
||||
query = {};
|
||||
}
|
||||
@@ -129,7 +136,6 @@ export async function apiRequestAllItems(this: IHookFunctions | IExecuteFunction
|
||||
return returnData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all the available forms
|
||||
*
|
||||
@@ -139,7 +145,9 @@ export async function apiRequestAllItems(this: IHookFunctions | IExecuteFunction
|
||||
*/
|
||||
export async function getForms(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const endpoint = 'form.json';
|
||||
const responseData = await apiRequestAllItems.call(this, 'GET', endpoint, {}, 'forms', { folders: false });
|
||||
const responseData = await apiRequestAllItems.call(this, 'GET', endpoint, {}, 'forms', {
|
||||
folders: false,
|
||||
});
|
||||
|
||||
if (responseData.items === undefined) {
|
||||
throw new Error('No data got returned');
|
||||
@@ -154,7 +162,6 @@ export async function getForms(this: ILoadOptionsFunctions): Promise<INodeProper
|
||||
return returnData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all the fields of a form
|
||||
*
|
||||
@@ -163,7 +170,10 @@ export async function getForms(this: ILoadOptionsFunctions): Promise<INodeProper
|
||||
* @param {string} formID
|
||||
* @returns {Promise<IFormstackFieldDefinitionType[]>}
|
||||
*/
|
||||
export async function getFields(this: IWebhookFunctions, formID: string): Promise<Record<string, IFormstackFieldDefinitionType>> {
|
||||
export async function getFields(
|
||||
this: IWebhookFunctions,
|
||||
formID: string,
|
||||
): Promise<Record<string, IFormstackFieldDefinitionType>> {
|
||||
const endpoint = `form/${formID}.json`;
|
||||
const responseData = await apiRequestAllItems.call(this, 'GET', endpoint, {}, 'fields');
|
||||
|
||||
@@ -174,14 +184,13 @@ export async function getFields(this: IWebhookFunctions, formID: string): Promis
|
||||
const fields = responseData.items as IFormstackFieldDefinitionType[];
|
||||
const fieldMap: Record<string, IFormstackFieldDefinitionType> = {};
|
||||
|
||||
fields.forEach(field => {
|
||||
fields.forEach((field) => {
|
||||
fieldMap[field.id] = field;
|
||||
});
|
||||
|
||||
return fieldMap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns all the fields of a form
|
||||
*
|
||||
@@ -190,7 +199,10 @@ export async function getFields(this: IWebhookFunctions, formID: string): Promis
|
||||
* @param {string} uniqueId
|
||||
* @returns {Promise<IFormstackFieldDefinitionType[]>}
|
||||
*/
|
||||
export async function getSubmission(this: ILoadOptionsFunctions | IWebhookFunctions, uniqueId: string): Promise<IFormstackSubmissionFieldContainer[]> {
|
||||
export async function getSubmission(
|
||||
this: ILoadOptionsFunctions | IWebhookFunctions,
|
||||
uniqueId: string,
|
||||
): Promise<IFormstackSubmissionFieldContainer[]> {
|
||||
const endpoint = `submission/${uniqueId}.json`;
|
||||
const responseData = await apiRequestAllItems.call(this, 'GET', endpoint, {}, 'data');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user