index.ts 1.73 KB
import { TransformationCategoryComponentEnum } from '../../../enum/category';
import { useCreateNodeKey } from '../../../hook/useCreateNodeKey';
import type { NodeItemConfigType } from '../../../types/node';
import { RuleNodeTypeEnum } from '../../index.type';

const keys = useCreateNodeKey(TransformationCategoryComponentEnum.SCRIPT);

export interface ScriptDataType {
  someConfiguration?: Recordable;
}

export const ScriptConfig: NodeItemConfigType = {
  ...keys,
  clazz: 'org.thingsboard.rule.engine.transform.TbTransformMsgNode',
  categoryType: RuleNodeTypeEnum.TRANSFORMATION,
  name: 'script',
  configurationDescriptor: {
    nodeDefinition: {
      details:
        'JavaScript function receive 3 input parameters <br/> <code>metadata</code> - is a Message metadata.<br/><code>msg</code> - is a Message payload.<br/><code>msgType</code> - is a Message type.<br/>Should return the following structure:<br/><code>{ msg: <i style="color: #666;">new payload</i>,<br/>&nbsp&nbsp&nbspmetadata: <i style="color: #666;">new metadata</i>,<br/>&nbsp&nbsp&nbspmsgType: <i style="color: #666;">new msgType</i> }</code><br/>All fields in resulting object are optional and will be taken from original message if not specified.',
      description: 'Change Message payload, Metadata or Message type using JavaScript',
      inEnabled: true,
      outEnabled: true,
      relationTypes: ['Success', 'Failure'],
      customRelations: false,
      ruleChainNode: false,
      defaultConfiguration: {
        jsScript: 'return {msg: msg, metadata: metadata, msgType: msgType};',
      },
      uiResources: ['static/rulenode/rulenode-core-config.js'],
      configDirective: 'tbTransformationNodeScriptConfig',
      icon: '',
      iconUrl: '',
      docUrl: '',
    },
  },
};