2
0

Customizable allowed origins

This commit is contained in:
Baptiste Arnaud
2024-01-17 09:04:07 +01:00
parent b2f8cd44b8
commit 8771def9a1
12 changed files with 151 additions and 5 deletions

View File

@ -131,6 +131,10 @@ export const startSession = async ({
dynamicTheme: parseDynamicThemeInState(typebot.theme),
isStreamEnabled: startParams.isStreamEnabled,
typingEmulation: typebot.settings.typingEmulation,
allowedOrigins:
startParams.type === 'preview'
? undefined
: typebot.settings.security?.allowedOrigins,
...initialSessionState,
}

View File

@ -88,6 +88,7 @@ const sessionStateSchemaV3 = sessionStateSchemaV2
.extend({
version: z.literal('3'),
currentBlockId: z.string().optional(),
allowedOrigins: z.array(z.string()).optional(),
})
export type SessionState = z.infer<typeof sessionStateSchemaV3>

View File

@ -42,6 +42,11 @@ export const settingsSchema = z
isEnabled: z.boolean().optional(),
})
.optional(),
security: z
.object({
allowedOrigins: z.array(z.string()).optional(),
})
.optional(),
})
.openapi({
title: 'Settings',

View File

@ -20,9 +20,11 @@ export const deepParseVariables =
},
parseVariablesOptions: ParseVariablesOptions = defaultParseVariablesOptions
) =>
<T extends Record<string, unknown>>(object: T): T =>
Object.keys(object).reduce<T>((newObj, key) => {
const currentValue = object[key]
<T>(object: T): T => {
if (!object) return object as T
if (typeof object !== 'object') return object as T
return Object.keys(object).reduce<T>((newObj, key) => {
const currentValue = (object as Record<string, unknown>)[key]
if (typeof currentValue === 'string') {
const parsedVariable = parseVariables(
@ -63,3 +65,4 @@ export const deepParseVariables =
return { ...newObj, [key]: currentValue }
}, {} as T)
}