create.config.ts 7.39 KB
import { ProtocolEnum, ProtocolNameEnum, RequestMethodEnum } from '../../../enum/form';
import { useRuleChainI18n } from '../../../hook/useRuleChainI18n';
import { FormSchema } from '/@/components/Form';

export enum RestApiCallFieldsEnum {
  REST_ENDPOINT_URL_PATTERN = 'restEndpointUrlPattern',
  REQUEST_METHOD = 'requestMethod',
  USE_SIMPLE_CLIENT_HTTP_FACTORY = 'useSimpleClientHttpFactory',
  IGNORE_REQUEST_BODY = 'ignoreRequestBody',
  ENABLE_PROXY = 'enableProxy',
  USE_SYSTEM_PROXY_PROPERTIES = 'useSystemProxyProperties',
  PROXY_SCHEME = 'proxyScheme',
  PROXY_HOST = 'proxyHost',
  PROXY_PORT = 'proxyPort',
  PROXY_USER = 'proxyUser',
  PROXY_PASSWORD = 'proxyPassword',
  READ_TIMEOUT_MS = 'readTimeoutMs',
  MAX_PARALLEL_REQUESTS_COUNT = 'maxParallelRequestsCount',
  HEADERS = 'headers',
  USE_REDIS_QUEUE_FOR_MSG_PERSISTENCE = 'useRedisQueueForMsgPersistence',
  TRIM_QUEUE = 'trimQueue',
  MAX_QUEUE_SIZE = 'maxQueueSize',
  CREDENTIALS = 'credentials',

  TYPE = 'type',
  PASSWORD = 'password',
  CA_CERT = 'caCert',
  CA_CERT_FILE_NAME = 'caCertFileName',
  PRIVATE_KEY = 'privateKey',
  PRIVATE_KEY_FILE_NAME = 'privateKeyFileName',
  CERT = 'cert',
  CERT_FILE_NAME = 'certFileName',
  USERNAME = 'username',
}
const { tLabel, tPlaceholder } = useRuleChainI18n('external', 'restApiCall');

export const formSchemas: FormSchema[] = [
  {
    field: RestApiCallFieldsEnum.REST_ENDPOINT_URL_PATTERN,
    label: tLabel(RestApiCallFieldsEnum.REST_ENDPOINT_URL_PATTERN),
    component: 'Input',
    required: true,
    helpMessage:
      'Hint: use ${metadataKey} for value from metadata, $[messageKey] for value from message body',
    componentProps: {
      placeholder: tPlaceholder(RestApiCallFieldsEnum.REST_ENDPOINT_URL_PATTERN),
    },
  },
  {
    field: RestApiCallFieldsEnum.REQUEST_METHOD,
    label: tLabel(RestApiCallFieldsEnum.REQUEST_METHOD),
    component: 'Select',
    required: true,
    componentProps: {
      options: Object.keys(RequestMethodEnum).map((value) => ({ label: value, value })),
      getPopupContainer: () => document.body,
      placeholder: tPlaceholder(RestApiCallFieldsEnum.REQUEST_METHOD, 'choose'),
    },
  },
  {
    field: RestApiCallFieldsEnum.ENABLE_PROXY,
    label: '',
    component: 'Checkbox',
    renderComponentContent: () => ({
      default: () => tLabel(RestApiCallFieldsEnum.ENABLE_PROXY),
    }),
  },
  {
    field: RestApiCallFieldsEnum.USE_SIMPLE_CLIENT_HTTP_FACTORY,
    label: '',
    component: 'Checkbox',
    show: ({ model }) => !model[RestApiCallFieldsEnum.ENABLE_PROXY],
    renderComponentContent: () => ({
      default: () => tLabel(RestApiCallFieldsEnum.USE_SIMPLE_CLIENT_HTTP_FACTORY),
    }),
  },
  {
    field: RestApiCallFieldsEnum.IGNORE_REQUEST_BODY,
    label: '',
    component: 'Checkbox',
    renderComponentContent: () => ({
      default: () => tLabel(RestApiCallFieldsEnum.IGNORE_REQUEST_BODY),
    }),
  },
  {
    field: RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES,
    label: '',
    component: 'Checkbox',
    show: ({ model }) => model[RestApiCallFieldsEnum.ENABLE_PROXY],
    renderComponentContent: () => ({
      default: () => tLabel(RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES),
    }),
  },
  {
    field: RestApiCallFieldsEnum.PROXY_SCHEME,
    label: tLabel(RestApiCallFieldsEnum.PROXY_SCHEME),
    component: 'Select',
    required: true,
    colProps: { span: 8 },
    componentProps: {
      options: Object.keys(ProtocolEnum).map((value) => ({
        label: ProtocolNameEnum[value],
        value,
      })),
      getPopupContainer: () => document.body,
      placeholder: tPlaceholder(RestApiCallFieldsEnum.PROXY_SCHEME, 'choose'),
    },
    ifShow: ({ model }) => {
      const ifShowField = model[RestApiCallFieldsEnum.ENABLE_PROXY];
      return ifShowField && !model[RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES];
    },
  },
  {
    field: RestApiCallFieldsEnum.PROXY_HOST,
    label: tLabel(RestApiCallFieldsEnum.PROXY_HOST),
    component: 'Input',
    required: true,
    colProps: { span: 8 },
    componentProps: {
      placeholder: tPlaceholder(RestApiCallFieldsEnum.PROXY_HOST),
    },
    ifShow: ({ model }) => {
      const ifShowField = model[RestApiCallFieldsEnum.ENABLE_PROXY];
      return ifShowField && !model[RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES];
    },
  },
  {
    field: RestApiCallFieldsEnum.PROXY_PORT,
    label: tLabel(RestApiCallFieldsEnum.PROXY_PORT),
    component: 'InputNumber',
    required: true,
    colProps: { span: 8 },
    componentProps: {
      placeholder: tPlaceholder(RestApiCallFieldsEnum.PROXY_HOST),
    },
    ifShow: ({ model }) => {
      const ifShowField = model[RestApiCallFieldsEnum.ENABLE_PROXY];
      return ifShowField && !model[RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES];
    },
  },
  {
    field: RestApiCallFieldsEnum.PROXY_USER,
    label: tLabel(RestApiCallFieldsEnum.PROXY_USER),
    component: 'Input',
    componentProps: {
      placeholder: tPlaceholder(RestApiCallFieldsEnum.PROXY_USER),
    },
    ifShow: ({ model }) => {
      const ifShowField = model[RestApiCallFieldsEnum.ENABLE_PROXY];
      return ifShowField && !model[RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES];
    },
  },
  {
    field: RestApiCallFieldsEnum.PROXY_PASSWORD,
    label: tLabel(RestApiCallFieldsEnum.PROXY_PASSWORD),
    component: 'Input',
    componentProps: {
      placeholder: tPlaceholder(RestApiCallFieldsEnum.PROXY_PASSWORD),
    },
    ifShow: ({ model }) => {
      const ifShowField = model[RestApiCallFieldsEnum.ENABLE_PROXY];
      return ifShowField && !model[RestApiCallFieldsEnum.USE_SYSTEM_PROXY_PROPERTIES];
    },
  },
  {
    field: RestApiCallFieldsEnum.READ_TIMEOUT_MS,
    label: tLabel(RestApiCallFieldsEnum.READ_TIMEOUT_MS),
    component: 'InputNumber',
    ifShow: ({ model }) => !model[RestApiCallFieldsEnum.USE_SIMPLE_CLIENT_HTTP_FACTORY],
    componentProps: {
      min: 0,
      placeholder: tPlaceholder(RestApiCallFieldsEnum.READ_TIMEOUT_MS),
    },
  },
  {
    field: RestApiCallFieldsEnum.MAX_PARALLEL_REQUESTS_COUNT,
    label: tLabel(RestApiCallFieldsEnum.MAX_PARALLEL_REQUESTS_COUNT),
    component: 'InputNumber',
    componentProps: {
      min: 0,
      placeholder: tPlaceholder(RestApiCallFieldsEnum.MAX_PARALLEL_REQUESTS_COUNT),
    },
  },
  {
    field: RestApiCallFieldsEnum.HEADERS,
    label: tLabel(RestApiCallFieldsEnum.HEADERS),
    component: 'Input',
    slot: RestApiCallFieldsEnum.HEADERS,
  },
  {
    field: RestApiCallFieldsEnum.USE_REDIS_QUEUE_FOR_MSG_PERSISTENCE,
    label: '',
    component: 'Checkbox',
    renderComponentContent: () => ({
      default: () => tLabel(RestApiCallFieldsEnum.USE_REDIS_QUEUE_FOR_MSG_PERSISTENCE),
    }),
  },
  {
    field: RestApiCallFieldsEnum.TRIM_QUEUE,
    label: '',
    component: 'Checkbox',
    ifShow: ({ model }) => model[RestApiCallFieldsEnum.USE_REDIS_QUEUE_FOR_MSG_PERSISTENCE],
    renderComponentContent: () => ({
      default: () => tLabel(RestApiCallFieldsEnum.TRIM_QUEUE),
    }),
  },
  {
    field: RestApiCallFieldsEnum.MAX_QUEUE_SIZE,
    label: tLabel(RestApiCallFieldsEnum.MAX_QUEUE_SIZE),
    component: 'InputNumber',
    ifShow: ({ model }) => model[RestApiCallFieldsEnum.USE_REDIS_QUEUE_FOR_MSG_PERSISTENCE],
    componentProps: {
      min: 0,
      placeholder: tPlaceholder(RestApiCallFieldsEnum.MAX_QUEUE_SIZE),
    },
  },
  {
    field: RestApiCallFieldsEnum.CREDENTIALS,
    label: tLabel(RestApiCallFieldsEnum.CREDENTIALS),
    component: 'Input',
    slot: RestApiCallFieldsEnum.CREDENTIALS,
  },
];