2
0

🩹 (share) Fix undefined apiHost under API instructions

This commit is contained in:
Baptiste Arnaud
2023-04-17 21:07:41 +02:00
parent 9345b33e74
commit 7c2ce2fc41
9 changed files with 24 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
import prettier from 'prettier/standalone' import prettier from 'prettier/standalone'
import parserHtml from 'prettier/parser-html' import parserHtml from 'prettier/parser-html'
import { import {
parseApiHost, parseApiHostValue,
parseInitBubbleCode, parseInitBubbleCode,
typebotImportCode, typebotImportCode,
} from '../../snippetParsers' } from '../../snippetParsers'
@@ -19,7 +19,7 @@ export const JavascriptBubbleSnippet = ({ theme, previewMessage }: Props) => {
${parseInitBubbleCode({ ${parseInitBubbleCode({
typebot: typebot?.publicId ?? '', typebot: typebot?.publicId ?? '',
apiHost: parseApiHost(typebot?.customDomain), apiHost: parseApiHostValue(typebot?.customDomain),
theme: { theme: {
...theme, ...theme,
chatWindow: { chatWindow: {

View File

@@ -2,7 +2,7 @@ import { useTypebot } from '@/features/editor/providers/TypebotProvider'
import parserHtml from 'prettier/parser-html' import parserHtml from 'prettier/parser-html'
import prettier from 'prettier/standalone' import prettier from 'prettier/standalone'
import { import {
parseApiHost, parseApiHostValue,
parseInitPopupCode, parseInitPopupCode,
typebotImportCode, typebotImportCode,
} from '../../snippetParsers' } from '../../snippetParsers'
@@ -16,7 +16,7 @@ export const JavascriptPopupSnippet = ({ autoShowDelay }: Props) => {
const snippet = prettier.format( const snippet = prettier.format(
createSnippet({ createSnippet({
typebot: typebot?.publicId ?? '', typebot: typebot?.publicId ?? '',
apiHost: parseApiHost(typebot?.customDomain), apiHost: parseApiHostValue(typebot?.customDomain),
autoShowDelay, autoShowDelay,
}), }),
{ {

View File

@@ -1,7 +1,7 @@
import parserHtml from 'prettier/parser-html' import parserHtml from 'prettier/parser-html'
import prettier from 'prettier/standalone' import prettier from 'prettier/standalone'
import { import {
parseApiHost, parseApiHostValue,
parseInitStandardCode, parseInitStandardCode,
typebotImportCode, typebotImportCode,
} from '../../snippetParsers' } from '../../snippetParsers'
@@ -40,7 +40,7 @@ export const parseStandardHeadCode = (
${parseInitStandardCode({ ${parseInitStandardCode({
typebot: publicId ?? '', typebot: publicId ?? '',
apiHost: parseApiHost(customDomain), apiHost: parseApiHostValue(customDomain),
})}</script>`, })}</script>`,
{ parser: 'html', plugins: [parserHtml] } { parser: 'html', plugins: [parserHtml] }
) )

View File

@@ -9,7 +9,7 @@ import {
parseInlineScript, parseInlineScript,
parseInitBubbleCode, parseInitBubbleCode,
typebotImportCode, typebotImportCode,
parseApiHost, parseApiHostValue,
} from '../../../snippetParsers' } from '../../../snippetParsers'
export const parseDefaultBubbleTheme = (typebot?: Typebot) => ({ export const parseDefaultBubbleTheme = (typebot?: Typebot) => ({
@@ -36,7 +36,7 @@ export const ScriptBubbleInstructions = () => {
${parseInitBubbleCode({ ${parseInitBubbleCode({
typebot: typebot?.publicId ?? '', typebot: typebot?.publicId ?? '',
apiHost: parseApiHost(typebot?.customDomain), apiHost: parseApiHostValue(typebot?.customDomain),
theme, theme,
previewMessage, previewMessage,
})}` })}`

View File

@@ -5,7 +5,7 @@ import { useState } from 'react'
import { PopupSettings } from '../../../settings/PopupSettings' import { PopupSettings } from '../../../settings/PopupSettings'
import { parseInitPopupCode } from '../../../snippetParsers' import { parseInitPopupCode } from '../../../snippetParsers'
import { import {
parseApiHost, parseApiHostValue,
parseInlineScript, parseInlineScript,
typebotImportCode, typebotImportCode,
} from '../../../snippetParsers/shared' } from '../../../snippetParsers/shared'
@@ -19,7 +19,7 @@ export const ScriptPopupInstructions = () => {
${parseInitPopupCode({ ${parseInitPopupCode({
typebot: typebot?.publicId ?? '', typebot: typebot?.publicId ?? '',
apiHost: parseApiHost(typebot?.customDomain), apiHost: parseApiHostValue(typebot?.customDomain),
autoShowDelay: inputValue, autoShowDelay: inputValue,
})}` })}`
) )

View File

@@ -6,7 +6,7 @@ import { StandardSettings } from '../../../settings/StandardSettings'
import { parseInitStandardCode } from '../../../snippetParsers/standard' import { parseInitStandardCode } from '../../../snippetParsers/standard'
import { parseStandardElementCode } from '../../Javascript/JavascriptStandardSnippet' import { parseStandardElementCode } from '../../Javascript/JavascriptStandardSnippet'
import { import {
parseApiHost, parseApiHostValue,
parseInlineScript, parseInlineScript,
typebotImportCode, typebotImportCode,
} from '../../../snippetParsers/shared' } from '../../../snippetParsers/shared'
@@ -30,7 +30,7 @@ export const ScriptStandardInstructions = () => {
${parseInitStandardCode({ ${parseInitStandardCode({
typebot: typebot?.publicId ?? '', typebot: typebot?.publicId ?? '',
apiHost: parseApiHost(typebot?.customDomain), apiHost: parseApiHostValue(typebot?.customDomain),
})}`) })}`)
return ( return (

View File

@@ -12,7 +12,7 @@ import {
import { BubbleProps } from '@typebot.io/js' import { BubbleProps } from '@typebot.io/js'
import { useState } from 'react' import { useState } from 'react'
import { BubbleSettings } from '../../../settings/BubbleSettings/BubbleSettings' import { BubbleSettings } from '../../../settings/BubbleSettings/BubbleSettings'
import { parseApiHost, parseInitBubbleCode } from '../../../snippetParsers' import { parseApiHostValue, parseInitBubbleCode } from '../../../snippetParsers'
import { parseDefaultBubbleTheme } from '../../Javascript/instructions/JavascriptBubbleInstructions' import { parseDefaultBubbleTheme } from '../../Javascript/instructions/JavascriptBubbleInstructions'
type Props = { type Props = {
@@ -29,7 +29,7 @@ export const WordpressBubbleInstructions = ({ publicId }: Props) => {
const initCode = parseInitBubbleCode({ const initCode = parseInitBubbleCode({
typebot: publicId, typebot: publicId,
apiHost: parseApiHost(typebot?.customDomain), apiHost: parseApiHostValue(typebot?.customDomain),
theme: { theme: {
...theme, ...theme,
chatWindow: { chatWindow: {

View File

@@ -11,7 +11,7 @@ import {
import { useState } from 'react' import { useState } from 'react'
import { PopupSettings } from '../../../settings/PopupSettings' import { PopupSettings } from '../../../settings/PopupSettings'
import { parseInitPopupCode } from '../../../snippetParsers/popup' import { parseInitPopupCode } from '../../../snippetParsers/popup'
import { parseApiHost } from '../../../snippetParsers' import { parseApiHostValue } from '../../../snippetParsers'
type Props = { type Props = {
publicId: string publicId: string
@@ -25,7 +25,7 @@ export const WordpressPopupInstructions = ({
const initCode = parseInitPopupCode({ const initCode = parseInitPopupCode({
typebot: publicId, typebot: publicId,
apiHost: parseApiHost(customDomain), apiHost: parseApiHostValue(customDomain),
autoShowDelay, autoShowDelay,
}) })

View File

@@ -51,7 +51,12 @@ export const parseApiHost = (
customDomain: Typebot['customDomain'] | undefined customDomain: Typebot['customDomain'] | undefined
) => { ) => {
if (customDomain) return new URL(`https://${customDomain}`).origin if (customDomain) return new URL(`https://${customDomain}`).origin
return isCloudProdInstance return env('VIEWER_INTERNAL_URL') ?? getViewerUrl()
? undefined }
: env('VIEWER_INTERNAL_URL') ?? getViewerUrl()
export const parseApiHostValue = (
customDomain: Typebot['customDomain'] | undefined
) => {
if (isCloudProdInstance) return
return parseApiHost(customDomain)
} }