feat(editor): ✨ Code step
This commit is contained in:
@ -21,8 +21,6 @@ import { sendRequest } from 'utils'
|
||||
import { sendGaEvent } from '../../lib/gtag'
|
||||
import { parseVariables, parseVariablesInObject } from './variable'
|
||||
|
||||
const safeEval = eval
|
||||
|
||||
type IntegrationContext = {
|
||||
apiHost: string
|
||||
typebotId: string
|
||||
@ -222,7 +220,9 @@ const executeWebhook = async (
|
||||
})
|
||||
step.options.responseVariableMapping.forEach((varMapping) => {
|
||||
if (!varMapping?.bodyPath || !varMapping.variableId) return
|
||||
const value = safeEval(`(${JSON.stringify(data)}).${varMapping?.bodyPath}`)
|
||||
const value = Function(
|
||||
`return (${JSON.stringify(data)}).${varMapping?.bodyPath}`
|
||||
)()
|
||||
updateVariableValue(varMapping.variableId, value)
|
||||
})
|
||||
return step.outgoingEdgeId
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
SetVariableStep,
|
||||
RedirectStep,
|
||||
Comparison,
|
||||
CodeStep,
|
||||
} from 'models'
|
||||
import { isDefined, isNotDefined } from 'utils'
|
||||
import { sanitizeUrl } from './utils'
|
||||
@ -27,6 +28,8 @@ export const executeLogic = (
|
||||
return executeCondition(step, variables)
|
||||
case LogicStepType.REDIRECT:
|
||||
return executeRedirect(step, variables)
|
||||
case LogicStepType.CODE:
|
||||
return executeCode(step)
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,3 +100,9 @@ const executeRedirect = (
|
||||
)
|
||||
return step.outgoingEdgeId
|
||||
}
|
||||
|
||||
const executeCode = (step: CodeStep) => {
|
||||
if (!step.options.content) return
|
||||
Function(step.options.content)()
|
||||
return step.outgoingEdgeId
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
import { Variable } from 'models'
|
||||
import { isDefined, isNotDefined } from 'utils'
|
||||
|
||||
const safeEval = eval
|
||||
|
||||
export const stringContainsVariable = (str: string): boolean =>
|
||||
/\{\{(.*?)\}\}/g.test(str)
|
||||
|
||||
@ -22,7 +20,7 @@ export const parseVariables =
|
||||
|
||||
export const evaluateExpression = (str: string) => {
|
||||
try {
|
||||
const evaluatedResult = safeEval(str)
|
||||
const evaluatedResult = Function('return' + str)()
|
||||
return isNotDefined(evaluatedResult) ? '' : evaluatedResult.toString()
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
|
Reference in New Issue
Block a user