2
0

♻️ Include forged blocks schema in typebot schema

Closes #1364
This commit is contained in:
Baptiste Arnaud
2024-03-18 16:09:19 +01:00
parent 26a9282c20
commit ed5096e2b6
93 changed files with 8599 additions and 4965 deletions

View File

@ -1,10 +1,10 @@
import { Variable } from '@typebot.io/schemas'
import {
defaultParseVariablesOptions,
parseVariables,
ParseVariablesOptions,
} from './parseVariables'
import { parseGuessedTypeFromString } from './parseGuessedTypeFromString'
import { Variable } from './types'
type DeepParseOptions = {
guessCorrectTypes?: boolean

View File

@ -1,10 +1,11 @@
import { Variable } from '@typebot.io/schemas'
import { parseVariables } from './parseVariables'
import { extractVariablesFromText } from './extractVariablesFromText'
import { parseGuessedValueType } from './parseGuessedValueType'
import { isDefined } from '@typebot.io/lib'
import { defaultTimeout } from '@typebot.io/schemas/features/blocks/integrations/webhook/constants'
import { safeStringify } from '@typebot.io/lib/safeStringify'
import { Variable } from './types'
const defaultTimeout = 10
type Props = {
variables: Variable[]

View File

@ -1,4 +1,4 @@
import { Variable } from '@typebot.io/schemas'
import { Variable } from './types'
export const extractVariablesFromText =
(variables: Variable[]) =>

View File

@ -1,4 +1,4 @@
import { Variable } from '@typebot.io/schemas'
import { Variable } from './types'
export const findUniqueVariableValue =
(variables: Variable[]) =>

View File

@ -1,8 +1,8 @@
import { Result, Variable } from '@typebot.io/schemas'
import { Variable } from './types'
export const injectVariablesFromExistingResult = (
variables: Variable[],
resultVariables: Result['variables']
resultVariables: any[]
): Variable[] =>
variables.map((variable) => {
const resultVariable = resultVariables.find(

View File

@ -4,7 +4,6 @@
"license": "AGPL-3.0-or-later",
"private": true,
"dependencies": {
"@typebot.io/lib": "workspace:*",
"@typebot.io/schemas": "workspace:*"
"@typebot.io/lib": "workspace:*"
}
}

View File

@ -1,4 +1,4 @@
import { Variable } from '@typebot.io/schemas'
import { Variable } from './types'
export const parseGuessedValueType = (
value: Variable['value']

View File

@ -1,6 +1,6 @@
import { Variable } from '@typebot.io/schemas'
import { parseGuessedValueType } from './parseGuessedValueType'
import { parseVariables } from './parseVariables'
import { Variable } from './types'
export const parseVariableNumber =
(variables: Variable[]) =>

View File

@ -1,7 +1,7 @@
import { safeStringify } from '@typebot.io/lib/safeStringify'
import { isDefined, isNotDefined } from '@typebot.io/lib/utils'
import { Variable, VariableWithValue } from '@typebot.io/schemas'
import { parseGuessedValueType } from './parseGuessedValueType'
import { Variable, VariableWithValue } from './types'
export type ParseVariablesOptions = {
fieldToParse?: 'value' | 'id'

View File

@ -1,9 +1,9 @@
import { safeStringify } from '@typebot.io/lib/safeStringify'
import { StartChatInput, Variable } from '@typebot.io/schemas'
import { Variable } from './types'
export const prefillVariables = (
variables: Variable[],
prefilledVariables: NonNullable<StartChatInput['prefilledVariables']>
prefilledVariables: Record<string, any>
): Variable[] =>
variables.map((variable) => {
const prefilledVariable = prefilledVariables[variable.name]

View File

@ -1,5 +1,5 @@
import { isNotDefined } from '@typebot.io/lib/utils'
import { Variable, VariableWithValue } from '@typebot.io/schemas'
import { Variable, VariableWithValue } from './types'
export const transformVariablesToList =
(variables: Variable[]) =>

View File

@ -0,0 +1,13 @@
export type Variable = {
id: string
name: string
value?: string | (string | null)[] | null | undefined
}
export type VariableWithValue = Pick<Variable, 'id' | 'name'> & {
value: string | (string | null)[]
}
export type VariableWithUnknowValue = Pick<Variable, 'id' | 'name'> & {
value?: unknown
}

View File

@ -1,26 +1,22 @@
import { safeStringify } from '@typebot.io/lib/safeStringify'
import {
SessionState,
VariableWithUnknowValue,
Variable,
} from '@typebot.io/schemas'
import { Variable, VariableWithUnknowValue } from './types'
export const updateVariablesInSession =
(state: SessionState) =>
(newVariables: VariableWithUnknowValue[]): SessionState => ({
(state: any) => (newVariables: VariableWithUnknowValue[]) => ({
...state,
typebotsQueue: state.typebotsQueue.map((typebotInQueue, index) =>
index === 0
? {
...typebotInQueue,
typebot: {
...typebotInQueue.typebot,
variables: updateTypebotVariables(typebotInQueue.typebot)(
newVariables
),
},
}
: typebotInQueue
typebotsQueue: state.typebotsQueue.map(
(typebotInQueue: { typebot: { variables: Variable[] } }, index: number) =>
index === 0
? {
...typebotInQueue,
typebot: {
...typebotInQueue.typebot,
variables: updateTypebotVariables(typebotInQueue.typebot)(
newVariables
),
},
}
: typebotInQueue
),
})