@@ -29,7 +29,9 @@ const executeComparison =
|
||||
if (!comparison?.variableId) return false
|
||||
const inputValue = (
|
||||
variables.find((v) => v.id === comparison.variableId)?.value ?? ''
|
||||
).trim()
|
||||
)
|
||||
.toString()
|
||||
.trim()
|
||||
const value = parseVariables(variables)(comparison.value).trim()
|
||||
if (isNotDefined(value) || !comparison.comparisonOperator) return false
|
||||
return matchComparison(inputValue, comparison.comparisonOperator, value)
|
||||
|
||||
@@ -25,7 +25,10 @@ export const parseVariables =
|
||||
if (!variable) return ''
|
||||
if (options.fieldToParse === 'id') return variable.id
|
||||
const { value } = variable
|
||||
if (options.escapeForJson) return jsonParse(value)
|
||||
if (options.escapeForJson)
|
||||
return typeof value === 'string'
|
||||
? jsonParse(value)
|
||||
: jsonParse(JSON.stringify(value))
|
||||
const parsedValue = safeStringify(value)
|
||||
if (!parsedValue) return ''
|
||||
return parsedValue
|
||||
@@ -45,9 +48,10 @@ export const safeStringify = (val: unknown): string | null => {
|
||||
|
||||
export const parseCorrectValueType = (
|
||||
value: Variable['value']
|
||||
): string | boolean | number | null | undefined => {
|
||||
): string | string[] | boolean | number | null | undefined => {
|
||||
if (value === null) return null
|
||||
if (value === undefined) return undefined
|
||||
if (Array.isArray(value)) return value
|
||||
if (typeof value === 'number') return value
|
||||
if (value === 'true') return true
|
||||
if (value === 'false') return false
|
||||
|
||||
@@ -9,6 +9,7 @@ export const choiceInputOptionsSchema = optionBaseSchema.and(
|
||||
z.object({
|
||||
isMultipleChoice: z.boolean(),
|
||||
buttonLabel: z.string(),
|
||||
dynamicVariableId: z.string().optional(),
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
@@ -106,7 +106,12 @@ const scriptToExecuteSchema = z.object({
|
||||
args: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
value: z.string().or(z.number()).or(z.boolean()).nullish(),
|
||||
value: z
|
||||
.string()
|
||||
.or(z.number())
|
||||
.or(z.boolean())
|
||||
.or(z.array(z.string()))
|
||||
.nullish(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
@@ -3,7 +3,7 @@ import { z } from 'zod'
|
||||
export const variableSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
value: z.string().nullish(),
|
||||
value: z.string().or(z.array(z.string())).nullish(),
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -12,7 +12,7 @@ export const variableSchema = z.object({
|
||||
export const variableWithValueSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
value: z.string(),
|
||||
value: z.string().or(z.array(z.string())),
|
||||
})
|
||||
|
||||
/**
|
||||
|
||||
@@ -235,7 +235,7 @@ export const parseAnswers =
|
||||
if (isVariable) {
|
||||
const variable = answerOrVariable as VariableWithValue
|
||||
if (variable.value === null) return o
|
||||
return { ...o, [variable.name]: variable.value }
|
||||
return { ...o, [variable.name]: variable.value.toString() }
|
||||
}
|
||||
const answer = answerOrVariable as Answer
|
||||
const key = answer.variableId
|
||||
|
||||
Reference in New Issue
Block a user