701 workflow improve webhook triggers (#11455)
as title Nota bene: I did not filter execution by http method. A POST webhook trigger can be triggered by a GET request for more flexibility. Tell me if you think it is a mistake https://github.com/user-attachments/assets/1833cbea-51a8-4772-bcd8-088d6a087e79
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
import { getWebhookTriggerDefaultSettings } from '@/workflow/workflow-trigger/utils/getWebhookTriggerDefaultSettings';
|
||||
|
||||
describe('getWebhookTriggerDefaultSettings', () => {
|
||||
it('returns correct settings for GET http method', () => {
|
||||
const result = getWebhookTriggerDefaultSettings('GET');
|
||||
expect(result).toEqual({
|
||||
authentication: null,
|
||||
httpMethod: 'GET',
|
||||
outputSchema: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('returns correct settings for POST http method', () => {
|
||||
const result = getWebhookTriggerDefaultSettings('POST');
|
||||
expect(result).toEqual({
|
||||
authentication: null,
|
||||
httpMethod: 'POST',
|
||||
expectedBody: {
|
||||
message: 'Workflow was started',
|
||||
},
|
||||
outputSchema: {
|
||||
message: {
|
||||
icon: 'IconVariable',
|
||||
isLeaf: true,
|
||||
label: 'message',
|
||||
type: 'string',
|
||||
value: 'Workflow was started',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('throws an error for an invalid http method', () => {
|
||||
// @ts-expect-error Testing invalid input
|
||||
expect(() => getWebhookTriggerDefaultSettings('INVALID')).toThrowError(
|
||||
'Invalid webhook http method',
|
||||
);
|
||||
});
|
||||
});
|
||||
+2
@@ -64,6 +64,8 @@ export const getTriggerDefaultDefinition = ({
|
||||
name: defaultLabel,
|
||||
settings: {
|
||||
outputSchema: {},
|
||||
httpMethod: 'GET',
|
||||
authentication: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
import { WorkflowWebhookTrigger } from '@/workflow/types/Workflow';
|
||||
import { assertUnreachable } from '@/workflow/utils/assertUnreachable';
|
||||
import { WebhookHttpMethods } from '@/workflow/workflow-trigger/constants/WebhookTriggerHttpMethodOptions';
|
||||
|
||||
export const getWebhookTriggerDefaultSettings = (
|
||||
webhookHttpMethods: WebhookHttpMethods,
|
||||
): WorkflowWebhookTrigger['settings'] => {
|
||||
switch (webhookHttpMethods) {
|
||||
case 'GET':
|
||||
return {
|
||||
outputSchema: {},
|
||||
httpMethod: webhookHttpMethods,
|
||||
authentication: null,
|
||||
};
|
||||
case 'POST':
|
||||
return {
|
||||
outputSchema: {
|
||||
message: {
|
||||
icon: 'IconVariable',
|
||||
type: 'string',
|
||||
label: 'message',
|
||||
value: 'Workflow was started',
|
||||
isLeaf: true,
|
||||
},
|
||||
},
|
||||
httpMethod: webhookHttpMethods,
|
||||
expectedBody: {
|
||||
message: 'Workflow was started',
|
||||
},
|
||||
authentication: null,
|
||||
};
|
||||
}
|
||||
return assertUnreachable(webhookHttpMethods, 'Invalid webhook http method');
|
||||
};
|
||||
Reference in New Issue
Block a user