-
Notifications
You must be signed in to change notification settings - Fork 38.4k
fix(core): Fix 431 for large dynamic node parameters #9384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ivov
merged 7 commits into
master
from
pay-997-bug-restnode-parameter-options-sends-all-node-options-in-uri
May 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e5d5a74
fix(core): Fix 431 for large dynamic node parameters
ivov 0127322
Merge branch 'master' into pay-997-bug-restnode-parameter-options-sen…
ivov 3174770
Tests
ivov e6d3049
No need to check for `methodName` in `/options`
ivov 4236530
Merge master
ivov 2e65fab
Fix e2e
ivov 5e2e01a
Standardize (except spy)
ivov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,29 @@ | ||
import type { RequestHandler } from 'express'; | ||
import { NextFunction, Response } from 'express'; | ||
import type { | ||
INodeListSearchResult, | ||
INodePropertyOptions, | ||
ResourceMapperFields, | ||
} from 'n8n-workflow'; | ||
import type { INodePropertyOptions } from 'n8n-workflow'; | ||
import { jsonParse } from 'n8n-workflow'; | ||
|
||
import { Get, Middleware, RestController } from '@/decorators'; | ||
import { Post, RestController } from '@/decorators'; | ||
import { getBase } from '@/WorkflowExecuteAdditionalData'; | ||
import { DynamicNodeParametersService } from '@/services/dynamicNodeParameters.service'; | ||
import { DynamicNodeParametersRequest } from '@/requests'; | ||
import { BadRequestError } from '@/errors/response-errors/bad-request.error'; | ||
|
||
const assertMethodName: RequestHandler = (req, res, next) => { | ||
const { methodName } = req.query as DynamicNodeParametersRequest.BaseRequest['query']; | ||
if (!methodName) { | ||
throw new BadRequestError('Parameter methodName is required.'); | ||
} | ||
next(); | ||
}; | ||
|
||
@RestController('/dynamic-node-parameters') | ||
export class DynamicNodeParametersController { | ||
constructor(private readonly service: DynamicNodeParametersService) {} | ||
|
||
@Middleware() | ||
parseQueryParams(req: DynamicNodeParametersRequest.BaseRequest, _: Response, next: NextFunction) { | ||
const { credentials, currentNodeParameters, nodeTypeAndVersion } = req.query; | ||
if (!nodeTypeAndVersion) { | ||
throw new BadRequestError('Parameter nodeTypeAndVersion is required.'); | ||
} | ||
if (!currentNodeParameters) { | ||
throw new BadRequestError('Parameter currentNodeParameters is required.'); | ||
} | ||
|
||
req.params = { | ||
nodeTypeAndVersion: jsonParse(nodeTypeAndVersion), | ||
currentNodeParameters: jsonParse(currentNodeParameters), | ||
credentials: credentials ? jsonParse(credentials) : undefined, | ||
}; | ||
@Post('/options') | ||
async getOptions(req: DynamicNodeParametersRequest.Options): Promise<INodePropertyOptions[]> { | ||
const { | ||
credentials, | ||
currentNodeParameters, | ||
nodeTypeAndVersion, | ||
path, | ||
methodName, | ||
loadOptions, | ||
} = req.body; | ||
|
||
next(); | ||
} | ||
if (!methodName) throw new BadRequestError('Missing `methodName` in request body'); | ||
|
||
/** Returns parameter values which normally get loaded from an external API or get generated dynamically */ | ||
@Get('/options') | ||
async getOptions(req: DynamicNodeParametersRequest.Options): Promise<INodePropertyOptions[]> { | ||
const { path, methodName, loadOptions } = req.query; | ||
const { credentials, currentNodeParameters, nodeTypeAndVersion } = req.params; | ||
const additionalData = await getBase(req.user.id, currentNodeParameters); | ||
|
||
if (methodName) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this check still needed now that we are also checking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, please see e6d3049 |
||
|
@@ -75,13 +50,22 @@ export class DynamicNodeParametersController { | |
return []; | ||
} | ||
|
||
@Get('/resource-locator-results', { middlewares: [assertMethodName] }) | ||
async getResourceLocatorResults( | ||
req: DynamicNodeParametersRequest.ResourceLocatorResults, | ||
): Promise<INodeListSearchResult | undefined> { | ||
const { path, methodName, filter, paginationToken } = req.query; | ||
const { credentials, currentNodeParameters, nodeTypeAndVersion } = req.params; | ||
@Post('/resource-locator-results') | ||
async getResourceLocatorResults(req: DynamicNodeParametersRequest.ResourceLocatorResults) { | ||
const { | ||
path, | ||
methodName, | ||
filter, | ||
paginationToken, | ||
credentials, | ||
currentNodeParameters, | ||
nodeTypeAndVersion, | ||
} = req.body; | ||
|
||
if (!methodName) throw new BadRequestError('Missing `methodName` in request body'); | ||
|
||
const additionalData = await getBase(req.user.id, currentNodeParameters); | ||
|
||
return await this.service.getResourceLocatorResults( | ||
methodName, | ||
path, | ||
|
@@ -94,13 +78,14 @@ export class DynamicNodeParametersController { | |
); | ||
} | ||
|
||
@Get('/resource-mapper-fields', { middlewares: [assertMethodName] }) | ||
async getResourceMappingFields( | ||
req: DynamicNodeParametersRequest.ResourceMapperFields, | ||
): Promise<ResourceMapperFields | undefined> { | ||
const { path, methodName } = req.query; | ||
const { credentials, currentNodeParameters, nodeTypeAndVersion } = req.params; | ||
@Post('/resource-mapper-fields') | ||
async getResourceMappingFields(req: DynamicNodeParametersRequest.ResourceMapperFields) { | ||
const { path, methodName, credentials, currentNodeParameters, nodeTypeAndVersion } = req.body; | ||
|
||
if (!methodName) throw new BadRequestError('Missing `methodName` in request body'); | ||
|
||
const additionalData = await getBase(req.user.id, currentNodeParameters); | ||
|
||
return await this.service.getResourceMappingFields( | ||
methodName, | ||
path, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we consider converting
DynamicNodeParametersRequest.Options
(and other request types in this controller) to a validatable class, to ensure that properties likenodeTypeAndVersion
andcurrentNodeParameters
are actually sent and valid?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love this - Val is planning to address this more generally: https://n8nio.slack.com/archives/C069HS026UF/p1715177726506449?thread_ts=1715164850.683949&cid=C069HS026UF