@ -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
|
||||
|
@ -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[]
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Variable } from '@typebot.io/schemas'
|
||||
import { Variable } from './types'
|
||||
|
||||
export const extractVariablesFromText =
|
||||
(variables: Variable[]) =>
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Variable } from '@typebot.io/schemas'
|
||||
import { Variable } from './types'
|
||||
|
||||
export const findUniqueVariableValue =
|
||||
(variables: Variable[]) =>
|
||||
|
@ -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(
|
||||
|
@ -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:*"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Variable } from '@typebot.io/schemas'
|
||||
import { Variable } from './types'
|
||||
|
||||
export const parseGuessedValueType = (
|
||||
value: Variable['value']
|
||||
|
@ -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[]) =>
|
||||
|
@ -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'
|
||||
|
@ -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]
|
||||
|
@ -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[]) =>
|
||||
|
13
packages/variables/types.ts
Normal file
13
packages/variables/types.ts
Normal 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
|
||||
}
|
@ -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
|
||||
),
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user