2023-07-08 08:26:27 +08:00
import { ArrayItems } from '@formily/antd-v5' ;
2022-11-23 18:29:18 +08:00
2023-12-27 13:55:48 +08:00
import {
Instruction ,
WorkflowVariableInput ,
WorkflowVariableJSON ,
2024-01-02 21:35:09 +08:00
WorkflowVariableTextArea ,
2023-12-27 13:55:48 +08:00
defaultFieldNames ,
} from '@nocobase/plugin-workflow/client' ;
2023-12-07 21:46:58 +08:00
2023-01-15 12:56:04 +08:00
import { NAMESPACE } from '../locale' ;
2022-11-23 18:29:18 +08:00
2023-12-07 21:46:58 +08:00
export default class extends Instruction {
title = ` {{t("HTTP request", { ns: " ${ NAMESPACE } " })}} ` ;
type = 'request' ;
group = 'extended' ;
description = ` {{t("Send HTTP request to a URL. You can use the variables in the upstream nodes as request headers, parameters and request body.", { ns: " ${ NAMESPACE } " })}} ` ;
fieldset = {
2023-03-04 00:19:11 +08:00
method : {
2022-11-23 18:29:18 +08:00
type : 'string' ,
required : true ,
2023-01-15 12:56:04 +08:00
title : ` {{t("HTTP method", { ns: " ${ NAMESPACE } " })}} ` ,
2022-11-23 18:29:18 +08:00
'x-decorator' : 'FormItem' ,
2023-01-15 12:56:04 +08:00
'x-component' : 'Select' ,
2022-11-23 18:29:18 +08:00
'x-component-props' : {
2023-01-15 12:56:04 +08:00
showSearch : false ,
allowClear : false ,
2023-07-30 17:52:35 +08:00
className : 'auto-width' ,
2022-11-23 18:29:18 +08:00
} ,
2023-01-15 12:56:04 +08:00
enum : [
{ label : 'GET' , value : 'GET' } ,
{ label : 'POST' , value : 'POST' } ,
{ label : 'PUT' , value : 'PUT' } ,
{ label : 'PATCH' , value : 'PATCH' } ,
{ label : 'DELETE' , value : 'DELETE' } ,
] ,
2023-04-25 13:12:14 +08:00
default : 'POST' ,
2022-11-23 18:29:18 +08:00
} ,
2023-03-04 00:19:11 +08:00
url : {
2023-01-15 12:56:04 +08:00
type : 'string' ,
2022-11-23 18:29:18 +08:00
required : true ,
2023-01-15 12:56:04 +08:00
title : ` {{t("URL", { ns: " ${ NAMESPACE } " })}} ` ,
2022-11-23 18:29:18 +08:00
'x-decorator' : 'FormItem' ,
2023-04-25 13:12:14 +08:00
'x-decorator-props' : { } ,
2024-01-02 21:35:09 +08:00
'x-component' : 'WorkflowVariableTextArea' ,
2022-11-23 18:29:18 +08:00
'x-component-props' : {
2023-01-15 12:56:04 +08:00
placeholder : 'https://www.nocobase.com' ,
2022-11-23 18:29:18 +08:00
} ,
} ,
2023-03-04 00:19:11 +08:00
headers : {
2022-11-23 18:29:18 +08:00
type : 'array' ,
'x-component' : 'ArrayItems' ,
'x-decorator' : 'FormItem' ,
2023-01-15 12:56:04 +08:00
title : ` {{t("Headers", { ns: " ${ NAMESPACE } " })}} ` ,
description : ` {{t('"Content-Type" only support "application/json", and no need to specify', { ns: " ${ NAMESPACE } " })}} ` ,
2022-11-23 18:29:18 +08:00
items : {
type : 'object' ,
properties : {
space : {
type : 'void' ,
'x-component' : 'Space' ,
properties : {
name : {
type : 'string' ,
'x-decorator' : 'FormItem' ,
'x-component' : 'Input' ,
'x-component-props' : {
2023-01-15 12:56:04 +08:00
placeholder : ` {{t("Name")}} ` ,
2022-11-23 18:29:18 +08:00
} ,
} ,
value : {
type : 'string' ,
'x-decorator' : 'FormItem' ,
2023-11-03 20:08:11 +08:00
'x-component' : 'WorkflowVariableInput' ,
2023-02-20 11:52:06 +08:00
'x-component-props' : {
2023-04-23 16:51:56 +08:00
useTypedConstant : true ,
2023-04-25 13:12:14 +08:00
} ,
2022-11-23 18:29:18 +08:00
} ,
remove : {
type : 'void' ,
'x-decorator' : 'FormItem' ,
'x-component' : 'ArrayItems.Remove' ,
} ,
} ,
} ,
} ,
} ,
properties : {
add : {
type : 'void' ,
title : ` {{t("Add request header", { ns: " ${ NAMESPACE } " })}} ` ,
'x-component' : 'ArrayItems.Addition' ,
} ,
} ,
} ,
2023-03-04 00:19:11 +08:00
params : {
2023-01-15 12:56:04 +08:00
type : 'array' ,
'x-component' : 'ArrayItems' ,
2022-11-23 18:29:18 +08:00
'x-decorator' : 'FormItem' ,
2023-01-15 12:56:04 +08:00
title : ` {{t("Parameters", { ns: " ${ NAMESPACE } " })}} ` ,
items : {
type : 'object' ,
properties : {
space : {
type : 'void' ,
'x-component' : 'Space' ,
properties : {
name : {
type : 'string' ,
'x-decorator' : 'FormItem' ,
'x-component' : 'Input' ,
'x-component-props' : {
placeholder : ` {{t("Name")}} ` ,
} ,
} ,
value : {
type : 'string' ,
'x-decorator' : 'FormItem' ,
2023-11-03 20:08:11 +08:00
'x-component' : 'WorkflowVariableInput' ,
2023-02-20 11:52:06 +08:00
'x-component-props' : {
2023-04-23 16:51:56 +08:00
useTypedConstant : true ,
2023-04-25 13:12:14 +08:00
} ,
2023-01-15 12:56:04 +08:00
} ,
remove : {
type : 'void' ,
'x-decorator' : 'FormItem' ,
'x-component' : 'ArrayItems.Remove' ,
} ,
} ,
} ,
} ,
} ,
properties : {
add : {
type : 'void' ,
title : ` {{t("Add parameter", { ns: " ${ NAMESPACE } " })}} ` ,
'x-component' : 'ArrayItems.Addition' ,
} ,
2022-11-23 18:29:18 +08:00
} ,
} ,
2023-03-04 00:19:11 +08:00
data : {
2022-11-23 18:29:18 +08:00
type : 'string' ,
2023-01-15 12:56:04 +08:00
title : ` {{t("Body", { ns: " ${ NAMESPACE } " })}} ` ,
2022-11-23 18:29:18 +08:00
'x-decorator' : 'FormItem' ,
'x-decorator-props' : { } ,
2023-11-03 20:08:11 +08:00
'x-component' : 'WorkflowVariableJSON' ,
2022-11-23 18:29:18 +08:00
'x-component-props' : {
2023-07-05 22:01:41 +08:00
changeOnSelect : true ,
2022-11-23 18:29:18 +08:00
autoSize : {
2023-01-15 12:56:04 +08:00
minRows : 10 ,
2022-11-23 18:29:18 +08:00
} ,
placeholder : ` {{t("Input request data", { ns: " ${ NAMESPACE } " })}} ` ,
2023-01-15 12:56:04 +08:00
} ,
description : ` {{t("Only support standard JSON data", { ns: " ${ NAMESPACE } " })}} ` ,
} ,
2023-03-04 00:19:11 +08:00
timeout : {
2023-01-15 12:56:04 +08:00
type : 'number' ,
title : ` {{t("Timeout config", { ns: " ${ NAMESPACE } " })}} ` ,
'x-decorator' : 'FormItem' ,
'x-decorator-props' : { } ,
'x-component' : 'InputNumber' ,
'x-component-props' : {
addonAfter : ` {{t("ms", { ns: " ${ NAMESPACE } " })}} ` ,
min : 1 ,
step : 1000 ,
defaultValue : 5000 ,
2022-11-23 18:29:18 +08:00
} ,
} ,
2023-03-04 00:19:11 +08:00
ignoreFail : {
2022-11-23 18:29:18 +08:00
type : 'boolean' ,
2023-10-20 12:04:27 +08:00
title : ` {{t("Ignore failed request and continue workflow", { ns: " ${ NAMESPACE } " })}} ` ,
2022-11-23 18:29:18 +08:00
'x-decorator' : 'FormItem' ,
'x-component' : 'Checkbox' ,
2023-04-25 13:12:14 +08:00
} ,
2023-12-07 21:46:58 +08:00
} ;
components = {
2022-11-23 18:29:18 +08:00
ArrayItems ,
2023-11-03 20:08:11 +08:00
WorkflowVariableInput ,
2024-01-02 21:35:09 +08:00
WorkflowVariableTextArea ,
2023-11-09 20:40:27 +08:00
WorkflowVariableJSON ,
2023-12-07 21:46:58 +08:00
} ;
2023-11-03 20:08:11 +08:00
useVariables ( { key , title } , { types , fieldNames = defaultFieldNames } ) {
return {
[ fieldNames . value ] : key ,
[ fieldNames . label ] : title ,
} ;
2023-12-07 21:46:58 +08:00
}
}