mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-31 16:57:08 +02:00
192 lines
4.4 KiB
TypeScript
192 lines
4.4 KiB
TypeScript
import {
|
|
OptionsRequestDto,
|
|
ResourceLocatorRequestDto,
|
|
ResourceMapperFieldsRequestDto,
|
|
ActionResultRequestDto,
|
|
} from '@n8n/api-types';
|
|
import { AuthenticatedRequest } from '@n8n/db';
|
|
import { Post, RestController, Body } from '@n8n/decorators';
|
|
import type { INodePropertyOptions, NodeParameterValueType } from 'n8n-workflow';
|
|
|
|
import { DynamicNodeParametersService } from '@/services/dynamic-node-parameters.service';
|
|
import { getBase } from '@/workflow-execute-additional-data';
|
|
|
|
@RestController('/dynamic-node-parameters')
|
|
export class DynamicNodeParametersController {
|
|
constructor(private readonly dynamicNodeParametersService: DynamicNodeParametersService) {}
|
|
|
|
@Post('/options')
|
|
async getOptions(
|
|
req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Body payload: OptionsRequestDto,
|
|
): Promise<INodePropertyOptions[]> {
|
|
await this.dynamicNodeParametersService.refineResourceIds(req.user, payload);
|
|
|
|
const {
|
|
credentials,
|
|
currentNodeParameters,
|
|
nodeTypeAndVersion,
|
|
path,
|
|
methodName,
|
|
loadOptions,
|
|
projectId,
|
|
} = payload;
|
|
|
|
const additionalData = await getBase({
|
|
userId: req.user.id,
|
|
projectId,
|
|
currentNodeParameters,
|
|
});
|
|
additionalData.dataTableProjectId = projectId;
|
|
|
|
if (methodName) {
|
|
return await this.dynamicNodeParametersService.getOptionsViaMethodName(
|
|
methodName,
|
|
path,
|
|
additionalData,
|
|
nodeTypeAndVersion,
|
|
currentNodeParameters,
|
|
credentials,
|
|
);
|
|
}
|
|
|
|
if (loadOptions) {
|
|
return await this.dynamicNodeParametersService.getOptionsViaLoadOptions(
|
|
loadOptions,
|
|
additionalData,
|
|
nodeTypeAndVersion,
|
|
currentNodeParameters,
|
|
credentials,
|
|
);
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
@Post('/resource-locator-results')
|
|
async getResourceLocatorResults(
|
|
req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Body payload: ResourceLocatorRequestDto,
|
|
) {
|
|
await this.dynamicNodeParametersService.refineResourceIds(req.user, payload);
|
|
|
|
const {
|
|
path,
|
|
methodName,
|
|
filter,
|
|
paginationToken,
|
|
credentials,
|
|
currentNodeParameters,
|
|
nodeTypeAndVersion,
|
|
projectId,
|
|
} = payload;
|
|
|
|
const additionalData = await getBase({
|
|
userId: req.user.id,
|
|
projectId,
|
|
currentNodeParameters,
|
|
});
|
|
additionalData.dataTableProjectId = projectId;
|
|
|
|
return await this.dynamicNodeParametersService.getResourceLocatorResults(
|
|
methodName,
|
|
path,
|
|
additionalData,
|
|
nodeTypeAndVersion,
|
|
currentNodeParameters,
|
|
credentials,
|
|
filter,
|
|
paginationToken,
|
|
);
|
|
}
|
|
|
|
@Post('/resource-mapper-fields')
|
|
async getResourceMappingFields(
|
|
req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Body payload: ResourceMapperFieldsRequestDto,
|
|
) {
|
|
await this.dynamicNodeParametersService.refineResourceIds(req.user, payload);
|
|
|
|
const { path, methodName, credentials, currentNodeParameters, nodeTypeAndVersion, projectId } =
|
|
payload;
|
|
|
|
const additionalData = await getBase({
|
|
userId: req.user.id,
|
|
projectId,
|
|
currentNodeParameters,
|
|
});
|
|
additionalData.dataTableProjectId = projectId;
|
|
|
|
return await this.dynamicNodeParametersService.getResourceMappingFields(
|
|
methodName,
|
|
path,
|
|
additionalData,
|
|
nodeTypeAndVersion,
|
|
currentNodeParameters,
|
|
credentials,
|
|
);
|
|
}
|
|
|
|
@Post('/local-resource-mapper-fields')
|
|
async getLocalResourceMappingFields(
|
|
req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Body payload: ResourceMapperFieldsRequestDto,
|
|
) {
|
|
await this.dynamicNodeParametersService.refineResourceIds(req.user, payload);
|
|
|
|
const { path, methodName, currentNodeParameters, nodeTypeAndVersion, projectId } = payload;
|
|
|
|
const additionalData = await getBase({
|
|
userId: req.user.id,
|
|
currentNodeParameters,
|
|
projectId,
|
|
});
|
|
|
|
return await this.dynamicNodeParametersService.getLocalResourceMappingFields(
|
|
methodName,
|
|
path,
|
|
additionalData,
|
|
nodeTypeAndVersion,
|
|
);
|
|
}
|
|
|
|
@Post('/action-result')
|
|
async getActionResult(
|
|
req: AuthenticatedRequest,
|
|
_res: Response,
|
|
@Body payload: ActionResultRequestDto,
|
|
): Promise<NodeParameterValueType> {
|
|
await this.dynamicNodeParametersService.refineResourceIds(req.user, payload);
|
|
|
|
const {
|
|
currentNodeParameters,
|
|
nodeTypeAndVersion,
|
|
path,
|
|
credentials,
|
|
handler,
|
|
payload: actionPayload,
|
|
projectId,
|
|
} = payload;
|
|
|
|
const additionalData = await getBase({
|
|
userId: req.user.id,
|
|
projectId,
|
|
currentNodeParameters,
|
|
});
|
|
|
|
return await this.dynamicNodeParametersService.getActionResult(
|
|
handler,
|
|
path,
|
|
additionalData,
|
|
nodeTypeAndVersion,
|
|
currentNodeParameters,
|
|
actionPayload,
|
|
credentials,
|
|
);
|
|
}
|
|
}
|