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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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