2
0

fix(docker): 🐛 Runtime public environment

This commit is contained in:
Baptiste Arnaud
2022-06-21 10:36:41 +02:00
parent ea765640cf
commit e03fe9f7d9
54 changed files with 349 additions and 164 deletions

View File

@@ -20,6 +20,7 @@ import { isDefined, isNotDefined } from 'utils'
import { CustomDomainsDropdown } from './customDomain/CustomDomainsDropdown'
import { EditableUrl } from './EditableUrl'
import { integrationsList } from './integrations/EmbedButton'
import { env } from 'utils'
export const ShareContent = () => {
const { workspace } = useWorkspace()
@@ -58,9 +59,7 @@ export const ShareContent = () => {
</Heading>
{typebot && (
<EditableUrl
hostname={
process.env.NEXT_PUBLIC_VIEWER_URL ?? 'https://typebot.io'
}
hostname={env('VIEWER_URL') ?? 'https://typebot.io'}
pathname={publicId}
onPathnameChange={handlePublicIdChange}
/>

View File

@@ -5,7 +5,7 @@ import { BubbleParams } from 'typebot-js'
import { parseInitBubbleCode, typebotJsHtml } from '../params'
import { useTypebot } from 'contexts/TypebotContext'
import { CodeEditor } from 'components/shared/CodeEditor'
import { isEmpty } from 'utils'
import { env, isEmpty } from 'utils'
type ChatEmbedCodeProps = {
withStarterVariables?: boolean
@@ -21,9 +21,9 @@ export const ChatEmbedCode = ({
const snippet = prettier.format(
createSnippet({
url: `${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${typebot?.publicId}`,
button,
proactiveMessage,

View File

@@ -5,7 +5,7 @@ import { parseInitContainerCode, typebotJsHtml } from '../params'
import { IframeParams } from 'typebot-js'
import { useTypebot } from 'contexts/TypebotContext'
import { CodeEditor } from 'components/shared/CodeEditor'
import { isEmpty } from 'utils'
import { env, isEmpty } from 'utils'
type ContainerEmbedCodeProps = {
widthLabel: string
@@ -23,9 +23,9 @@ export const ContainerEmbedCode = ({
const snippet = prettier.format(
parseSnippet({
url: `${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${typebot?.publicId}`,
heightLabel,
widthLabel,

View File

@@ -1,7 +1,7 @@
import { FlexProps } from '@chakra-ui/react'
import { CodeEditor } from 'components/shared/CodeEditor'
import { useTypebot } from 'contexts/TypebotContext'
import { isEmpty } from 'utils'
import { env, isEmpty } from 'utils'
type Props = {
widthLabel: string
@@ -14,9 +14,9 @@ export const IframeEmbedCode = ({
}: Props & FlexProps) => {
const { typebot } = useTypebot()
const src = `${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${typebot?.publicId}`
const code = `<iframe src="${src}" width="${widthLabel}" height="${heightLabel}" />`

View File

@@ -4,7 +4,7 @@ import { useTypebot } from 'contexts/TypebotContext'
import parserHtml from 'prettier/parser-html'
import prettier from 'prettier/standalone'
import { PopupParams } from 'typebot-js'
import { isEmpty } from 'utils'
import { env, isEmpty } from 'utils'
import { parseInitPopupCode, typebotJsHtml } from '../params'
type PopupEmbedCodeProps = {
@@ -18,9 +18,9 @@ export const PopupEmbedCode = ({ delay }: PopupEmbedCodeProps & FlexProps) => {
const snippet = prettier.format(
createSnippet({
url: `${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${typebot?.publicId}`,
delay,
}),

View File

@@ -10,7 +10,7 @@ import parserBabel from 'prettier/parser-babel'
import prettier from 'prettier/standalone'
import { CodeEditor } from 'components/shared/CodeEditor'
import { useTypebot } from 'contexts/TypebotContext'
import { isEmpty } from 'utils'
import { env, isEmpty } from 'utils'
type StandardReactDivProps = { widthLabel: string; heightLabel: string }
export const StandardReactDiv = ({
@@ -21,9 +21,9 @@ export const StandardReactDiv = ({
const snippet = prettier.format(
parseContainerSnippet({
url: `${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${typebot?.publicId}`,
heightLabel,
widthLabel,
@@ -73,9 +73,9 @@ export const PopupReactCode = ({ delay }: PopupEmbedCodeProps & FlexProps) => {
const snippet = prettier.format(
parsePopupSnippet({
url: `${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${typebot?.publicId}`,
delay,
}),
@@ -124,9 +124,9 @@ export const ChatReactCode = ({
const snippet = prettier.format(
parseBubbleSnippet({
url: `${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${typebot?.publicId}`,
button,
proactiveMessage,

View File

@@ -18,7 +18,7 @@ import {
import { useToast } from 'components/shared/hooks/useToast'
import { useEffect, useRef, useState } from 'react'
import { createCustomDomain } from 'services/user'
import { isEmpty } from 'utils'
import { env, isEmpty } from 'utils'
const hostnameRegex =
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/
@@ -118,9 +118,9 @@ export const CustomDomainModal = ({
<Stack>
<Text fontWeight="bold">Value</Text>
<Text>
{isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL}
{isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')}
</Text>
</Stack>
</HStack>

View File

@@ -11,7 +11,7 @@ import { PopupEmbedSettings } from 'components/share/codeSnippets/Popup/EmbedSet
import { CodeEditor } from 'components/shared/CodeEditor'
import { useState } from 'react'
import { BubbleParams } from 'typebot-js'
import { isEmpty } from 'utils'
import { env, isEmpty } from 'utils'
import { ModalProps } from '../../EmbedButton'
type GtmInstructionsProps = {
@@ -41,9 +41,9 @@ const StandardInstructions = ({ publicId }: Pick<ModalProps, 'publicId'>) => {
const jsCode = parseInitContainerCode({
url: `${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${publicId}`,
})
const headCode = `${typebotJsHtml}

View File

@@ -16,7 +16,7 @@ import {
} from '@chakra-ui/react'
import { CopyButton } from 'components/shared/buttons/CopyButton'
import { PublishFirstInfo } from 'components/shared/Info'
import { isEmpty } from 'utils'
import { env, isEmpty } from 'utils'
import { ModalProps } from '../EmbedButton'
export const NotionModal = ({
@@ -46,17 +46,17 @@ export const NotionModal = ({
pr="4.5rem"
type={'text'}
defaultValue={`${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${publicId}`}
/>
<InputRightElement width="4.5rem">
<CopyButton
textToCopy={`${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${publicId}`}
/>
</InputRightElement>

View File

@@ -14,7 +14,7 @@ import { BubbleParams } from 'typebot-js'
import { ModalProps } from '../../EmbedButton'
import parserHtml from 'prettier/parser-html'
import prettier from 'prettier/standalone'
import { isEmpty } from 'utils'
import { env, isEmpty } from 'utils'
type ShopifyInstructionsProps = {
type: 'standard' | 'popup' | 'bubble'
@@ -46,9 +46,9 @@ const StandardInstructions = ({ publicId }: Pick<ModalProps, 'publicId'>) => {
const jsCode = parseInitContainerCode({
url: `${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${publicId}`,
})
const headCode = prettier.format(

View File

@@ -17,7 +17,7 @@ import {
import { ExternalLinkIcon } from 'assets/icons'
import { CopyButton } from 'components/shared/buttons/CopyButton'
import { PublishFirstInfo } from 'components/shared/Info'
import { isEmpty } from 'utils'
import { env, isEmpty } from 'utils'
import { ModalProps } from '../EmbedButton'
export const WordpressModal = ({
@@ -55,17 +55,17 @@ export const WordpressModal = ({
pr="4.5rem"
type={'text'}
defaultValue={`${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${publicId}`}
/>
<InputRightElement width="4.5rem">
<CopyButton
textToCopy={`${
isEmpty(process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL)
? process.env.NEXT_PUBLIC_VIEWER_URL
: process.env.NEXT_PUBLIC_VIEWER_INTERNAL_URL
isEmpty(env('VIEWER_INTERNAL_URL'))
? env('VIEWER_URL')
: env('VIEWER_INTERNAL_URL')
}/${publicId}`}
/>
</InputRightElement>

View File

@@ -9,7 +9,7 @@ import { useDebouncedCallback } from 'use-debounce'
import { linter } from '@codemirror/lint'
import { VariablesButton } from './buttons/VariablesButton'
import { Variable } from 'models'
import { isEmpty } from 'utils'
import { env } from 'utils'
const linterExtension = linter(jsonParseLinter())
@@ -43,7 +43,7 @@ export const CodeEditor = ({
setPlainTextValue(value)
onChange && onChange(value)
},
isEmpty(process.env.NEXT_PUBLIC_E2E_TEST) ? debounceTimeout : 0
env('E2E_TEST') === 'enabled' ? 0 : debounceTimeout
)
useEffect(

View File

@@ -12,6 +12,7 @@ import { SwitchWithLabel } from 'components/shared/SwitchWithLabel'
import { Input, Textarea } from 'components/shared/Textbox'
import { CredentialsType, SendEmailOptions } from 'models'
import React, { useState } from 'react'
import { env } from 'utils'
import { SmtpConfigModal } from './SmtpConfigModal'
type Props = {
@@ -96,9 +97,9 @@ export const SendEmailSettings = ({ options, onOptionsChange }: Props) => {
currentCredentialsId={options.credentialsId}
onCredentialsSelect={handleCredentialsSelect}
onCreateNewClick={onOpen}
defaultCredentialLabel={process.env.NEXT_PUBLIC_SMTP_FROM?.match(
/\<(.*)\>/
)?.pop()}
defaultCredentialLabel={env('SMTP_FROM')
?.match(/\<(.*)\>/)
?.pop()}
refreshDropdownKey={refreshCredentialsKey}
/>
</Stack>

View File

@@ -4,14 +4,13 @@ import { Grid, SearchContext } from '@giphy/react-components'
import { GiphyLogo } from 'assets/logos'
import React, { useContext, useState, useEffect } from 'react'
import { useDebounce } from 'use-debounce'
import { env } from 'utils'
type GiphySearchProps = {
onSubmit: (url: string) => void
}
const giphyFetch = new GiphyFetch(
process.env.NEXT_PUBLIC_GIPHY_API_KEY as string
)
const giphyFetch = new GiphyFetch(env('GIPHY_API_KEY') as string)
export const GiphySearch = ({ onSubmit }: GiphySearchProps) => {
const { fetchGifs, searchKey, setSearch } = useContext(SearchContext)

View File

@@ -16,12 +16,7 @@ import { useTypebot } from 'contexts/TypebotContext'
import { BaseEmoji, emojiIndex } from 'emoji-mart'
import { emojis } from './emojis'
import { Input } from '../Textbox/Input'
import { isEmpty } from 'utils'
import getConfig from 'next/config'
const {
publicRuntimeConfig: { NEXT_PUBLIC_GIPHY_API_KEY },
} = getConfig()
import { env, isEmpty } from 'utils'
type Props = {
url?: string
@@ -188,10 +183,10 @@ const EmojiContent = ({
}
const GiphyContent = ({ onNewUrl }: ContentProps) => {
if (isEmpty(NEXT_PUBLIC_GIPHY_API_KEY))
if (isEmpty(env('GIPHY_API_KEY')))
return <Text>NEXT_PUBLIC_GIPHY_API_KEY is missing in environment</Text>
return (
<SearchContextManager apiKey={NEXT_PUBLIC_GIPHY_API_KEY}>
<SearchContextManager apiKey={env('GIPHY_API_KEY') as string}>
<GiphySearch onSubmit={onNewUrl} />
</SearchContextManager>
)

View File

@@ -13,7 +13,7 @@ import {
import { Variable } from 'models'
import { useState, useRef, useEffect, ChangeEvent } from 'react'
import { useDebouncedCallback } from 'use-debounce'
import { isEmpty } from 'utils'
import { env } from 'utils'
import { VariablesButton } from './buttons/VariablesButton'
type Props = {
@@ -38,7 +38,7 @@ export const SearchableDropdown = ({
const debounced = useDebouncedCallback(
// eslint-disable-next-line @typescript-eslint/no-empty-function
onValueChange ? onValueChange : () => {},
isEmpty(process.env.NEXT_PUBLIC_E2E_TEST) ? debounceTimeout : 0
env('E2E_TEST') === 'enabled' ? 0 : debounceTimeout
)
const [filteredItems, setFilteredItems] = useState([
...items

View File

@@ -8,7 +8,7 @@ import {
} from '@chakra-ui/react'
import { useEffect, useState } from 'react'
import { useDebouncedCallback } from 'use-debounce'
import { isEmpty } from 'utils'
import { env } from 'utils'
export const SmartNumberInput = ({
value,
@@ -23,7 +23,7 @@ export const SmartNumberInput = ({
const [currentValue, setCurrentValue] = useState(value?.toString() ?? '')
const debounced = useDebouncedCallback(
onValueChange,
isEmpty(process.env.NEXT_PUBLIC_E2E_TEST) ? debounceTimeout : 0
env('E2E_TEST') === 'enabled' ? 0 : debounceTimeout
)
useEffect(

View File

@@ -7,7 +7,7 @@ import {
import { Variable } from 'models'
import React, { ChangeEvent, useEffect, useRef, useState } from 'react'
import { useDebouncedCallback } from 'use-debounce'
import { isEmpty } from 'utils'
import { env } from 'utils'
import { VariablesButton } from '../buttons/VariablesButton'
export type TextBoxProps = {
@@ -36,7 +36,7 @@ export const TextBox = ({
(value) => {
onChange(value)
},
isEmpty(process.env.NEXT_PUBLIC_E2E_TEST) ? debounceTimeout : 0
env('E2E_TEST') === 'enabled' ? 0 : debounceTimeout
)
useEffect(() => {

View File

@@ -17,7 +17,7 @@ import cuid from 'cuid'
import { Variable } from 'models'
import React, { useState, useRef, ChangeEvent, useEffect } from 'react'
import { useDebouncedCallback } from 'use-debounce'
import { byId, isEmpty, isNotDefined } from 'utils'
import { byId, env, isNotDefined } from 'utils'
type Props = {
initialVariableId?: string
@@ -47,7 +47,7 @@ export const VariableSearchInput = ({
const variable = variables.find((v) => v.name === value)
if (variable) onSelectVariable(variable)
},
isEmpty(process.env.NEXT_PUBLIC_E2E_TEST) ? debounceTimeout : 0
env('E2E_TEST') === 'enabled' ? 0 : debounceTimeout
)
const [filteredItems, setFilteredItems] = useState<Variable[]>(
variables ?? []

View File

@@ -1,8 +1,7 @@
import React, { useEffect, useState } from 'react'
import { Text, HStack } from '@chakra-ui/react'
import { SearchableDropdown } from '../../../shared/SearchableDropdown'
import { isEmpty } from 'utils'
import getConfig from 'next/config'
import { env, isEmpty } from 'utils'
type FontSelectorProps = {
activeFont?: string
@@ -21,12 +20,11 @@ export const FontSelector = ({
}, [])
const fetchPopularFonts = async () => {
const {
publicRuntimeConfig: { NEXT_PUBLIC_GOOGLE_API_KEY },
} = getConfig()
if (isEmpty(NEXT_PUBLIC_GOOGLE_API_KEY)) return []
if (isEmpty(env('GOOGLE_API_KEY'))) return []
const response = await fetch(
`https://www.googleapis.com/webfonts/v1/webfonts?key=${NEXT_PUBLIC_GOOGLE_API_KEY}&sort=popularity`
`https://www.googleapis.com/webfonts/v1/webfonts?key=${env(
'GOOGLE_API_KEY'
)}&sort=popularity`
)
return (await response.json()).items.map(
(item: { family: string }) => item.family