Best Practices for Validating Workflow Nodes in Node-based Automation Systems

in blurt •  10 months ago 

Introduction:

Node-based automation systems provide a powerful way to design and manage complex workflows. However, ensuring the integrity of these workflows is crucial for their successful execution. In this blog post, we'll explore best practices for validating different types of nodes within a node-based automation system, using JavaScript as an example language.


src

  • Delay Node Validation:
export function validateDelayNode({ node }) {
  if (!node?.delay_data) {
    return true;
  }

  const { delay_type, date, days, releaseWindow, trigger_by } = node.delay_data;

  if (
    delay_type === "nurturing" &&
    (!("interval_value" in node.delay_data) ||
      !("trigger_by" in node.delay_data))
  ) {
    return true;
  } else if (
    delay_type === "recurring" &&
    (!date?.start_date ||
      !(days?.length > 0) ||
      !releaseWindow?.start_time ||
      !trigger_by)
  ) {
    return true;
  }
}


src

  • Communication Node Validation:
export function validateCommunicationNode({ node }) {
  const { communication_data } = node;

  if (
    !communication_data ||
    !communication_data.communication_type ||
    !communication_data.template_id
  ) {
    return true;
  }
}
  • Tag Node Validation:
export function validateTagNode({ node }) {
  if (!node?.tag_data) {
    return true;
  }
}
  • Exit Node Validation:
export function validateExitNode({ node }) {
  const { exit_condition_data } = node;

  if (!exit_condition_data || !exit_condition_data.length) {
    return true;
  }

  for (const exitCondition of exit_condition_data) {
    if (
      !exitCondition?.filterOptions.every(
        (opt) => opt?.fieldName && opt?.operator
      )
    ) {
      return true;
    }
  }
}
  • If-Else Node Validation:
export function validateIfElseNode({ node }) {
  const { if_else_data } = node;

  if (!if_else_data || !if_else_data.length) {
    return true;
  }

  for (let i = 0; i < node.length; i++) {
    const currentObject = node[i];

    if (!currentObject.next_action) {
      return true;
    }

    if (
      i < node.length &&
      (!currentObject.filterOptions ||
        !currentObject.filterOptions.every(
          (option) => option.fieldName && option.operator
        ))
    ) {
      return true;
    }
  }
}
  • Lead Stage Node Validation:
export function validateLeadStageNode({ node }) {
  const { lead_stage_data } = node;

  if (!lead_stage_data || !lead_stage_data.lead_stage) {
    return true;
  }
}
  • Allocation Node Validation:
export function validateAllocationNode({ node }) {
  const { allocation_counsellor_data } = node;

  if (!allocation_counsellor_data || !allocation_counsellor_data.length) {
    return true;
  }
}
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE BLURT!