feat(n8n Form Trigger Node): Improvements (#7571)

Github issue / Community forum post (link here to close automatically):

---------

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
Michael Kret
2023-12-13 17:00:51 +02:00
committed by GitHub
parent 26f0d57f5f
commit 953a58f18b
37 changed files with 1163 additions and 496 deletions

View File

@@ -1674,6 +1674,8 @@ export interface IWebhookDescription {
responseMode?: WebhookResponseMode | string;
responseData?: WebhookResponseData | string;
restartWebhook?: boolean;
isForm?: boolean;
hasLifecycleMethods?: boolean; // set automatically by generate-ui-types
ndvHideUrl?: boolean; // If true the webhook will not be displayed in the editor
ndvHideMethod?: boolean; // If true the method will not be displayed in the editor
}
@@ -1920,6 +1922,7 @@ export interface IWorkflowExecuteAdditionalData {
instanceBaseUrl: string;
setExecutionStatus?: (status: ExecutionStatus) => void;
sendDataToUI?: (type: string, data: IDataObject | IDataObject[]) => void;
formWaitingBaseUrl: string;
webhookBaseUrl: string;
webhookWaitingBaseUrl: string;
webhookTestBaseUrl: string;
@@ -2209,7 +2212,8 @@ export type FieldType =
| 'time'
| 'array'
| 'object'
| 'options';
| 'options'
| 'url';
export type ValidationResult = {
valid: boolean;
@@ -2305,6 +2309,9 @@ export interface IPublicApiSettings {
export type ExpressionEvaluatorType = 'tmpl' | 'tournament';
export interface IN8nUISettings {
endpointForm: string;
endpointFormTest: string;
endpointFormWaiting: string;
endpointWebhook: string;
endpointWebhookTest: string;
saveDataErrorExecution: WorkflowSettings.SaveDataExecution;

View File

@@ -122,6 +122,19 @@ export const tryToParseObject = (value: unknown): object => {
}
};
export const tryToParseUrl = (value: unknown): string => {
if (typeof value === 'string' && !value.includes('://')) {
value = `http://${value}`;
}
const urlPattern = /^(https?|ftp|file):\/\/\S+|www\.\S+/;
if (!urlPattern.test(String(value))) {
throw new ApplicationError(`The value "${String(value)}" is not a valid url.`, {
extra: { value },
});
}
return String(value);
};
type ValidateFieldTypeOptions = Partial<{
valueOptions: INodePropertyOptions[];
strict: boolean;
@@ -225,6 +238,13 @@ export const validateFieldType = (
}
return { valid: true, newValue: value };
}
case 'url': {
try {
return { valid: true, newValue: tryToParseUrl(value) };
} catch (e) {
return { valid: false, errorMessage: defaultErrorMessage };
}
}
default: {
return { valid: true, newValue: value };
}