mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
refactor(core): Convert dynamic node-parameter routes to a decorated controller (no-changelog) (#7284)
1. Reduce a lot of code duplication 2. Move more endpoints out of `Server.ts` 3. Move all query-param parsing and validation into a middleware to make the route handlers simpler.
This commit is contained in:
committed by
GitHub
parent
05ed86c64b
commit
fc60e9a809
@@ -1355,17 +1355,6 @@ export interface ITabBarItem {
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export interface IResourceLocatorReqParams {
|
||||
nodeTypeAndVersion: INodeTypeNameVersion;
|
||||
path: string;
|
||||
methodName?: string;
|
||||
searchList?: ILoadOptions;
|
||||
currentNodeParameters: INodeParameters;
|
||||
credentials?: INodeCredentials;
|
||||
filter?: string;
|
||||
paginationToken?: unknown;
|
||||
}
|
||||
|
||||
export interface IResourceLocatorResultExpanded extends INodeListSearchItems {
|
||||
linkAlt?: string;
|
||||
}
|
||||
@@ -1473,13 +1462,30 @@ export type NodeAuthenticationOption = {
|
||||
displayOptions?: IDisplayOptions;
|
||||
};
|
||||
|
||||
export interface ResourceMapperReqParams {
|
||||
nodeTypeAndVersion: INodeTypeNameVersion;
|
||||
path: string;
|
||||
methodName?: string;
|
||||
currentNodeParameters: INodeParameters;
|
||||
credentials?: INodeCredentials;
|
||||
export declare namespace DynamicNodeParameters {
|
||||
interface BaseRequest {
|
||||
path: string;
|
||||
nodeTypeAndVersion: INodeTypeNameVersion;
|
||||
currentNodeParameters: INodeParameters;
|
||||
methodName?: string;
|
||||
credentials?: INodeCredentials;
|
||||
}
|
||||
|
||||
interface OptionsRequest extends BaseRequest {
|
||||
loadOptions?: ILoadOptions;
|
||||
}
|
||||
|
||||
interface ResourceLocatorResultsRequest extends BaseRequest {
|
||||
methodName: string;
|
||||
filter?: string;
|
||||
paginationToken?: string;
|
||||
}
|
||||
|
||||
interface ResourceMapperFieldsRequest extends BaseRequest {
|
||||
methodName: string;
|
||||
}
|
||||
}
|
||||
|
||||
export interface EnvironmentVariable {
|
||||
id: number;
|
||||
key: string;
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
import { makeRestApiRequest } from '@/utils/apiUtils';
|
||||
import type { DynamicNodeParameters, INodeTranslationHeaders, IRestApiContext } from '@/Interface';
|
||||
import type {
|
||||
INodeTranslationHeaders,
|
||||
IResourceLocatorReqParams,
|
||||
IRestApiContext,
|
||||
ResourceMapperReqParams,
|
||||
} from '@/Interface';
|
||||
import type {
|
||||
IDataObject,
|
||||
ILoadOptions,
|
||||
INodeCredentials,
|
||||
INodeListSearchResult,
|
||||
INodeParameters,
|
||||
INodePropertyOptions,
|
||||
INodeTypeDescription,
|
||||
INodeTypeNameVersion,
|
||||
@@ -38,38 +29,31 @@ export async function getNodesInformation(
|
||||
|
||||
export async function getNodeParameterOptions(
|
||||
context: IRestApiContext,
|
||||
sendData: {
|
||||
nodeTypeAndVersion: INodeTypeNameVersion;
|
||||
path: string;
|
||||
methodName?: string;
|
||||
loadOptions?: ILoadOptions;
|
||||
currentNodeParameters: INodeParameters;
|
||||
credentials?: INodeCredentials;
|
||||
},
|
||||
sendData: DynamicNodeParameters.OptionsRequest,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
return makeRestApiRequest(context, 'GET', '/node-parameter-options', sendData);
|
||||
return makeRestApiRequest(context, 'GET', '/dynamic-node-parameters/options', sendData);
|
||||
}
|
||||
|
||||
export async function getResourceLocatorResults(
|
||||
context: IRestApiContext,
|
||||
sendData: IResourceLocatorReqParams,
|
||||
sendData: DynamicNodeParameters.ResourceLocatorResultsRequest,
|
||||
): Promise<INodeListSearchResult> {
|
||||
return makeRestApiRequest(
|
||||
context,
|
||||
'GET',
|
||||
'/nodes-list-search',
|
||||
sendData as unknown as IDataObject,
|
||||
'/dynamic-node-parameters/resource-locator-results',
|
||||
sendData,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getResourceMapperFields(
|
||||
context: IRestApiContext,
|
||||
sendData: ResourceMapperReqParams,
|
||||
sendData: DynamicNodeParameters.ResourceMapperFieldsRequest,
|
||||
): Promise<ResourceMapperFields> {
|
||||
return makeRestApiRequest(
|
||||
context,
|
||||
'GET',
|
||||
'/get-mapping-fields',
|
||||
sendData as unknown as IDataObject,
|
||||
'/dynamic-node-parameters/resource-mapper-fields',
|
||||
sendData,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -166,7 +166,6 @@ import stringify from 'fast-json-stable-stringify';
|
||||
import type { EventBus } from 'n8n-design-system/utils';
|
||||
import { createEventBus } from 'n8n-design-system/utils';
|
||||
import type {
|
||||
ILoadOptions,
|
||||
INode,
|
||||
INodeCredentials,
|
||||
INodeListSearchItems,
|
||||
@@ -688,9 +687,6 @@ export default defineComponent({
|
||||
const loadOptionsMethod = this.getPropertyArgument(this.currentMode, 'searchListMethod') as
|
||||
| string
|
||||
| undefined;
|
||||
const searchList = this.getPropertyArgument(this.currentMode, 'searchList') as
|
||||
| ILoadOptions
|
||||
| undefined;
|
||||
|
||||
const requestParams: IResourceLocatorReqParams = {
|
||||
nodeTypeAndVersion: {
|
||||
@@ -699,7 +695,6 @@ export default defineComponent({
|
||||
},
|
||||
path: this.path,
|
||||
methodName: loadOptionsMethod,
|
||||
searchList,
|
||||
currentNodeParameters: resolvedNodeParameters,
|
||||
credentials: this.node.credentials,
|
||||
...(params.filter ? { filter: params.filter } : {}),
|
||||
|
||||
@@ -12,21 +12,14 @@ import {
|
||||
STORES,
|
||||
CREDENTIAL_ONLY_HTTP_NODE_VERSION,
|
||||
} from '@/constants';
|
||||
import type {
|
||||
INodeTypesState,
|
||||
IResourceLocatorReqParams,
|
||||
ResourceMapperReqParams,
|
||||
} from '@/Interface';
|
||||
import type { INodeTypesState, DynamicNodeParameters } from '@/Interface';
|
||||
import { addHeaders, addNodeTranslation } from '@/plugins/i18n';
|
||||
import { omit } from '@/utils';
|
||||
import type {
|
||||
ConnectionTypes,
|
||||
ILoadOptions,
|
||||
INode,
|
||||
INodeCredentials,
|
||||
INodeListSearchResult,
|
||||
INodeOutputConfiguration,
|
||||
INodeParameters,
|
||||
INodePropertyOptions,
|
||||
INodeTypeDescription,
|
||||
INodeTypeNameVersion,
|
||||
@@ -273,25 +266,20 @@ export const useNodeTypesStore = defineStore(STORES.NODE_TYPES, {
|
||||
addHeaders(headers, rootStore.defaultLocale);
|
||||
}
|
||||
},
|
||||
async getNodeParameterOptions(sendData: {
|
||||
nodeTypeAndVersion: INodeTypeNameVersion;
|
||||
path: string;
|
||||
methodName?: string;
|
||||
loadOptions?: ILoadOptions;
|
||||
currentNodeParameters: INodeParameters;
|
||||
credentials?: INodeCredentials;
|
||||
}): Promise<INodePropertyOptions[]> {
|
||||
async getNodeParameterOptions(
|
||||
sendData: DynamicNodeParameters.OptionsRequest,
|
||||
): Promise<INodePropertyOptions[]> {
|
||||
const rootStore = useRootStore();
|
||||
return getNodeParameterOptions(rootStore.getRestApiContext, sendData);
|
||||
},
|
||||
async getResourceLocatorResults(
|
||||
sendData: IResourceLocatorReqParams,
|
||||
sendData: DynamicNodeParameters.ResourceLocatorResultsRequest,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const rootStore = useRootStore();
|
||||
return getResourceLocatorResults(rootStore.getRestApiContext, sendData);
|
||||
},
|
||||
async getResourceMapperFields(
|
||||
sendData: ResourceMapperReqParams,
|
||||
sendData: DynamicNodeParameters.ResourceMapperFieldsRequest,
|
||||
): Promise<ResourceMapperFields | null> {
|
||||
const rootStore = useRootStore();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user