All files / src/utils/parser/workflow workflowToState.ts

0% Statements 0/14
0% Branches 0/16
0% Functions 0/1
0% Lines 0/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61                                                                                                                         
import {
  defaultCode,
  exampleInput,
} from "../../../store/features/workflow/workflowSlice.ts";
import * as Extractors from "../../workflow/extractors/index.ts";
import * as Types from "../../workflow/types/index.ts";
import globalVariableToState from "./globalVariableToState.ts";
 
export const workflowToState = (workflow) => {
  const workflowActionType =
    workflow?.actions?.length > 0
      ? workflow.actions[0]?.type?.toLowerCase()
      : "";
  const workflowAction: Types.WorkflowActionContractType =
    workflow?.actions?.length > 0
      ? workflow.actions[0][workflowActionType]
      : {};
 
  const entryPointType =
    workflow?.entry_points?.length > 0
      ? workflow.entry_points[0]?.type?.toLowerCase()
      : "";
  const entryPoint: Types.WorkflowEntryPointContractType =
    workflow?.entry_points?.length > 0
      ? workflow.entry_points[0][entryPointType]
      : {};
 
  const scheduleType = workflow?.schedule?.type?.toLowerCase();
  const schedule: Types.ScheduleContractType = workflow?.schedule[scheduleType];
 
  const playbookId =
    workflow?.playbooks?.length > 0 ? workflow?.playbooks[0].id : null;
 
  const currentWorkflow = {
    name: workflow.name,
    type: workflow.type ?? "STANDARD",
    playbookId,
    notification: workflowActionType,
    workflowType: entryPointType,
    schedule: scheduleType,
    generateSummary: workflow?.configuration?.generate_summary,
    useTransformer:
      workflow?.configuration?.transformer_lambda_function?.definition !==
      undefined,
    evaluation_window_in_seconds:
      workflow?.configuration?.evaluation_window_in_seconds,
    transformerCode:
      workflow?.configuration?.transformer_lambda_function?.definition ??
      defaultCode,
    globalVariables: globalVariableToState(
      workflow?.configuration?.global_variable_set ?? {},
    ),
    exampleInput,
    ...Extractors.handleActionsExtractor(workflowActionType, workflowAction),
    ...Extractors.handleEntryPointsExtractor(entryPointType, entryPoint),
    ...Extractors.handleScheduleExtractor(scheduleType, schedule),
  };
 
  return currentWorkflow;
};