2
0

🔥 Remove VIEWER_URL_INTERNAL variable

BREAKING CHANGE: NEXT_PUBLIC_VIEWER_INTERNAL does not exist anymore as typebot.io now directly points to the viewer project
This commit is contained in:
Baptiste Arnaud
2023-11-23 15:21:07 +01:00
parent 542e632472
commit 73d2e165bf
22 changed files with 51 additions and 48 deletions

View File

@@ -20,7 +20,6 @@ export const SupportBubble = (props: Omit<BubbleProps, 'typebot'>) => {
return ( return (
<Bubble <Bubble
apiHost="https://viewer.typebot.io"
typebot="typebot-support" typebot="typebot-support"
prefilledVariables={{ prefilledVariables={{
'User ID': user?.id, 'User ID': user?.id,

View File

@@ -1,6 +1,6 @@
import { Variable, WebhookResponse } from '@typebot.io/schemas' import { Variable, WebhookResponse } from '@typebot.io/schemas'
import { sendRequest } from '@typebot.io/lib' import { sendRequest } from '@typebot.io/lib'
import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' import { env } from '@typebot.io/env'
export const executeWebhook = ( export const executeWebhook = (
typebotId: string, typebotId: string,
@@ -8,7 +8,7 @@ export const executeWebhook = (
{ blockId }: { blockId: string } { blockId }: { blockId: string }
) => ) =>
sendRequest<WebhookResponse>({ sendRequest<WebhookResponse>({
url: `${getViewerUrl()}/api/typebots/${typebotId}/blocks/${blockId}/executeWebhook`, url: `${env.NEXT_PUBLIC_VIEWER_URL[0]}/api/typebots/${typebotId}/blocks/${blockId}/executeWebhook`,
method: 'POST', method: 'POST',
body: { body: {
variables, variables,

View File

@@ -18,8 +18,8 @@ import {
Text, Text,
Stack, Stack,
} from '@chakra-ui/react' } from '@chakra-ui/react'
import { getViewerUrl } from '@typebot.io/lib/getViewerUrl'
import { ModalProps } from '../EmbedButton' import { ModalProps } from '../EmbedButton'
import { env } from '@typebot.io/env'
export const FlutterFlowModal = ({ export const FlutterFlowModal = ({
isPublished, isPublished,
@@ -51,12 +51,12 @@ export const FlutterFlowModal = ({
<InputGroup size="sm"> <InputGroup size="sm">
<Input <Input
type={'text'} type={'text'}
defaultValue={`${getViewerUrl()}/${publicId}`} defaultValue={`${env.NEXT_PUBLIC_VIEWER_URL[0]}/${publicId}`}
/> />
<InputRightElement width="60px"> <InputRightElement width="60px">
<CopyButton <CopyButton
size="sm" size="sm"
textToCopy={`${getViewerUrl()}/${publicId}`} textToCopy={`${env.NEXT_PUBLIC_VIEWER_URL[0]}/${publicId}`}
/> />
</InputRightElement> </InputRightElement>
</InputGroup> </InputGroup>

View File

@@ -1,9 +1,9 @@
import { FlexProps } from '@chakra-ui/react' import { FlexProps } from '@chakra-ui/react'
import { useTypebot } from '@/features/editor/providers/TypebotProvider' import { useTypebot } from '@/features/editor/providers/TypebotProvider'
import { getViewerUrl } from '@typebot.io/lib/getViewerUrl'
import { CodeEditor } from '@/components/inputs/CodeEditor' import { CodeEditor } from '@/components/inputs/CodeEditor'
import prettier from 'prettier/standalone' import prettier from 'prettier/standalone'
import parserHtml from 'prettier/parser-html' import parserHtml from 'prettier/parser-html'
import { env } from '@typebot.io/env'
type Props = { type Props = {
widthLabel: string widthLabel: string
@@ -13,7 +13,7 @@ type Props = {
export const IframeSnippet = ({ widthLabel, heightLabel }: Props) => { export const IframeSnippet = ({ widthLabel, heightLabel }: Props) => {
const { typebot } = useTypebot() const { typebot } = useTypebot()
const src = `${getViewerUrl()}/${typebot?.publicId}` const src = `${env.NEXT_PUBLIC_VIEWER_URL[0]}/${typebot?.publicId}`
const code = prettier.format( const code = prettier.format(
`<iframe src="${src}" style="border: none; width=${widthLabel}; height=${heightLabel}"></iframe>`, `<iframe src="${src}" style="border: none; width=${widthLabel}; height=${heightLabel}"></iframe>`,
{ parser: 'html', plugins: [parserHtml] } { parser: 'html', plugins: [parserHtml] }

View File

@@ -18,8 +18,8 @@ import {
Text, Text,
Stack, Stack,
} from '@chakra-ui/react' } from '@chakra-ui/react'
import { getViewerUrl } from '@typebot.io/lib/getViewerUrl'
import { ModalProps } from '../EmbedButton' import { ModalProps } from '../EmbedButton'
import { env } from '@typebot.io/env'
export const NotionModal = ({ export const NotionModal = ({
isPublished, isPublished,
@@ -49,12 +49,12 @@ export const NotionModal = ({
<InputGroup size="sm"> <InputGroup size="sm">
<Input <Input
type={'text'} type={'text'}
defaultValue={`${getViewerUrl()}/${publicId}`} defaultValue={`${env.NEXT_PUBLIC_VIEWER_URL[0]}/${publicId}`}
/> />
<InputRightElement width="60px"> <InputRightElement width="60px">
<CopyButton <CopyButton
size="sm" size="sm"
textToCopy={`${getViewerUrl()}/${publicId}`} textToCopy={`${env.NEXT_PUBLIC_VIEWER_URL[0]}/${publicId}`}
/> />
</InputRightElement> </InputRightElement>
</InputGroup> </InputGroup>

View File

@@ -41,7 +41,6 @@ import {
} from '@chakra-ui/react' } from '@chakra-ui/react'
import { env } from '@typebot.io/env' import { env } from '@typebot.io/env'
import { isEmpty, isNotEmpty } from '@typebot.io/lib/utils' import { isEmpty, isNotEmpty } from '@typebot.io/lib/utils'
import { getViewerUrl } from '@typebot.io/lib/getViewerUrl'
import React, { useState } from 'react' import React, { useState } from 'react'
import { createId } from '@paralleldrive/cuid2' import { createId } from '@paralleldrive/cuid2'
@@ -449,9 +448,7 @@ const Webhook = ({
credentialsId: string credentialsId: string
}) => { }) => {
const { workspace } = useWorkspace() const { workspace } = useWorkspace()
const webhookUrl = `${ const webhookUrl = `${env.NEXT_PUBLIC_VIEWER_URL[0]}/api/v1/workspaces/${workspace?.id}/whatsapp/${credentialsId}/webhook`
env.NEXT_PUBLIC_VIEWER_INTERNAL_URL ?? getViewerUrl()
}/api/v1/workspaces/${workspace?.id}/whatsapp/${credentialsId}/webhook`
return ( return (
<Stack spacing={6}> <Stack spacing={6}>

View File

@@ -12,7 +12,7 @@ import {
import { useState } from 'react' import { useState } from 'react'
import { StandardSettings } from '../../../settings/StandardSettings' import { StandardSettings } from '../../../settings/StandardSettings'
import { isCloudProdInstance } from '@/helpers/isCloudProdInstance' import { isCloudProdInstance } from '@/helpers/isCloudProdInstance'
import { getViewerUrl } from '@typebot.io/lib/getViewerUrl' import { env } from '@typebot.io/env'
type Props = { type Props = {
publicId: string publicId: string
@@ -76,7 +76,7 @@ const parseWordpressShortcode = ({
publicId: string publicId: string
}) => { }) => {
return `[typebot typebot="${publicId}"${ return `[typebot typebot="${publicId}"${
isCloudProdInstance() ? '' : ` host="${getViewerUrl()}"` isCloudProdInstance() ? '' : ` host="${env.NEXT_PUBLIC_VIEWER_URL[0]}"`
}${width ? ` width="${width}"` : ''}${height ? ` height="${height}"` : ''}] }${width ? ` width="${width}"` : ''}${height ? ` height="${height}"` : ''}]
` `
} }

View File

@@ -2,10 +2,10 @@ import { BotProps } from '@typebot.io/nextjs'
import parserBabel from 'prettier/parser-babel' import parserBabel from 'prettier/parser-babel'
import prettier from 'prettier/standalone' import prettier from 'prettier/standalone'
import { isDefined } from '@typebot.io/lib' import { isDefined } from '@typebot.io/lib'
import { getViewerUrl } from '@typebot.io/lib/getViewerUrl'
import { Typebot } from '@typebot.io/schemas' import { Typebot } from '@typebot.io/schemas'
import { isCloudProdInstance } from '@/helpers/isCloudProdInstance' import { isCloudProdInstance } from '@/helpers/isCloudProdInstance'
import packageJson from '../../../../../../../../packages/embeds/js/package.json' import packageJson from '../../../../../../../../packages/embeds/js/package.json'
import { env } from '@typebot.io/env'
export const parseStringParam = ( export const parseStringParam = (
fieldName: string, fieldName: string,
@@ -59,7 +59,7 @@ 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 getViewerUrl() return env.NEXT_PUBLIC_VIEWER_URL[0]
} }
export const parseApiHostValue = ( export const parseApiHostValue = (

View File

@@ -1,11 +1,11 @@
import { Seo } from '@/components/Seo' import { Seo } from '@/components/Seo'
import { Flex } from '@chakra-ui/react' import { Flex } from '@chakra-ui/react'
import { Standard } from '@typebot.io/nextjs' import { Standard } from '@typebot.io/nextjs'
import { getViewerUrl } from '@typebot.io/lib/getViewerUrl'
import { SettingsSideMenu } from './SettingsSideMenu' import { SettingsSideMenu } from './SettingsSideMenu'
import { TypebotHeader } from '@/features/editor/components/TypebotHeader' import { TypebotHeader } from '@/features/editor/components/TypebotHeader'
import { useTypebot } from '@/features/editor/providers/TypebotProvider' import { useTypebot } from '@/features/editor/providers/TypebotProvider'
import { TypebotNotFoundPage } from '@/features/editor/components/TypebotNotFoundPage' import { TypebotNotFoundPage } from '@/features/editor/components/TypebotNotFoundPage'
import { env } from '@typebot.io/env'
export const SettingsPage = () => { export const SettingsPage = () => {
const { typebot, is404 } = useTypebot() const { typebot, is404 } = useTypebot()
@@ -18,7 +18,12 @@ export const SettingsPage = () => {
<Flex h="full" w="full"> <Flex h="full" w="full">
<SettingsSideMenu /> <SettingsSideMenu />
<Flex flex="1"> <Flex flex="1">
{typebot && <Standard apiHost={getViewerUrl()} typebot={typebot} />} {typebot && (
<Standard
apiHost={env.NEXT_PUBLIC_VIEWER_URL[0]}
typebot={typebot}
/>
)}
</Flex> </Flex>
</Flex> </Flex>
</Flex> </Flex>

View File

@@ -91,7 +91,6 @@ export const RealTimeResults = () => {
{typebot && ( {typebot && (
<Standard <Standard
typebot="airtable-real-time" typebot="airtable-real-time"
apiHost="https://typebot.io"
onAnswer={handleAnswer} onAnswer={handleAnswer}
style={{ style={{
borderRadius: '0.375rem', borderRadius: '0.375rem',

View File

@@ -1,5 +1,5 @@
import { env } from '@typebot.io/env'
import React from 'react' import React from 'react'
import { getViewerUrl } from '@typebot.io/lib/getViewerUrl'
export const ErrorPage = ({ error }: { error: Error }) => { export const ErrorPage = ({ error }: { error: Error }) => {
return ( return (
@@ -13,7 +13,7 @@ export const ErrorPage = ({ error }: { error: Error }) => {
padding: '0 1rem', padding: '0 1rem',
}} }}
> >
{!getViewerUrl() ? ( {!env.NEXT_PUBLIC_VIEWER_URL[0] ? (
<> <>
<h1 style={{ fontWeight: 'bold', fontSize: '30px' }}> <h1 style={{ fontWeight: 'bold', fontSize: '30px' }}>
NEXT_PUBLIC_VIEWER_URL is missing NEXT_PUBLIC_VIEWER_URL is missing

View File

@@ -3,9 +3,9 @@ import Head from 'next/head'
import Script from 'next/script' import Script from 'next/script'
import React from 'react' import React from 'react'
import { isNotEmpty } from '@typebot.io/lib' import { isNotEmpty } from '@typebot.io/lib'
import { getViewerUrl } from '@typebot.io/lib/getViewerUrl'
import { Settings } from '@typebot.io/schemas' import { Settings } from '@typebot.io/schemas'
import { defaultSettings } from '@typebot.io/schemas/features/typebot/settings/constants' import { defaultSettings } from '@typebot.io/schemas/features/typebot/settings/constants'
import { env } from '@typebot.io/env'
type SEOProps = { type SEOProps = {
url: string url: string
@@ -31,7 +31,10 @@ export const SEO = ({
<link <link
rel="icon" rel="icon"
type="image/png" type="image/png"
href={favIconUrl ?? defaultSettings.metadata.favIconUrl(getViewerUrl())} href={
favIconUrl ??
defaultSettings.metadata.favIconUrl(env.NEXT_PUBLIC_VIEWER_URL[0])
}
/> />
<meta name="title" content={title ?? typebotName} /> <meta name="title" content={title ?? typebotName} />
<meta <meta
@@ -56,7 +59,10 @@ export const SEO = ({
<meta <meta
property="og:image" property="og:image"
itemProp="image" itemProp="image"
content={imageUrl ?? defaultSettings.metadata.imageUrl(getViewerUrl())} content={
imageUrl ??
defaultSettings.metadata.imageUrl(env.NEXT_PUBLIC_VIEWER_URL[0])
}
/> />
<meta property="twitter:card" content="summary_large_image" /> <meta property="twitter:card" content="summary_large_image" />
@@ -71,7 +77,10 @@ export const SEO = ({
/> />
<meta <meta
property="twitter:image" property="twitter:image"
content={imageUrl ?? defaultSettings.metadata.imageUrl(getViewerUrl())} content={
imageUrl ??
defaultSettings.metadata.imageUrl(env.NEXT_PUBLIC_VIEWER_URL[0])
}
/> />
</Head> </Head>
{isNotEmpty(googleTagManagerId) && ( {isNotEmpty(googleTagManagerId) && (

View File

@@ -41,7 +41,8 @@
"tsup": "6.5.0", "tsup": "6.5.0",
"typebot-js": "workspace:*", "typebot-js": "workspace:*",
"typescript": "5.3.2", "typescript": "5.3.2",
"@typebot.io/lib": "workspace:*" "@typebot.io/lib": "workspace:*",
"@typebot.io/env": "workspace:*"
}, },
"peerDependencies": { "peerDependencies": {
"@typebot.io/prisma": "workspace:*", "@typebot.io/prisma": "workspace:*",

View File

@@ -1,4 +1,4 @@
import { CSSProperties, useMemo } from 'react' import { useMemo } from 'react'
import { TypebotProvider } from '../providers/TypebotProvider' import { TypebotProvider } from '../providers/TypebotProvider'
import styles from '../assets/style.css' import styles from '../assets/style.css'
import importantStyles from '../assets/importantStyles.css' import importantStyles from '../assets/importantStyles.css'
@@ -14,8 +14,8 @@ import {
import { Log } from '@typebot.io/prisma' import { Log } from '@typebot.io/prisma'
import { LiteBadge } from './LiteBadge' import { LiteBadge } from './LiteBadge'
import { isNotEmpty } from '@typebot.io/lib' import { isNotEmpty } from '@typebot.io/lib'
import { getViewerUrl } from '@typebot.io/lib/getViewerUrl'
import { BackgroundType } from '@typebot.io/schemas/features/typebot/theme/constants' import { BackgroundType } from '@typebot.io/schemas/features/typebot/theme/constants'
import { env } from '@typebot.io/env'
export type TypebotViewerProps = { export type TypebotViewerProps = {
typebot: Omit<PublicTypebot, 'updatedAt' | 'createdAt'> typebot: Omit<PublicTypebot, 'updatedAt' | 'createdAt'>
@@ -36,7 +36,7 @@ export type TypebotViewerProps = {
export const TypebotViewer = ({ export const TypebotViewer = ({
typebot, typebot,
apiHost = getViewerUrl(), apiHost = env.NEXT_PUBLIC_VIEWER_URL[0],
isPreview = false, isPreview = false,
isLoading = false, isLoading = false,
resultId, resultId,

View File

@@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/js", "name": "@typebot.io/js",
"version": "0.2.22", "version": "0.2.23",
"description": "Javascript library to display typebots on your website", "description": "Javascript library to display typebots on your website",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",

View File

@@ -1,8 +1,6 @@
import { getRuntimeVariable } from '@typebot.io/env/getRuntimeVariable' import { getRuntimeVariable } from '@typebot.io/env/getRuntimeVariable'
const cloudViewerUrl = 'https://viewer.typebot.io' const cloudViewerUrl = 'https://typebot.io'
export const guessApiHost = () => export const guessApiHost = () =>
getRuntimeVariable('NEXT_PUBLIC_VIEWER_INTERNAL_URL') ?? getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL')?.split(',')[0] ?? cloudViewerUrl
getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL')?.split(',')[0] ??
cloudViewerUrl

View File

@@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/nextjs", "name": "@typebot.io/nextjs",
"version": "0.2.22", "version": "0.2.23",
"description": "Convenient library to display typebots on your Next.js website", "description": "Convenient library to display typebots on your Next.js website",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/react", "name": "@typebot.io/react",
"version": "0.2.22", "version": "0.2.23",
"description": "Convenient library to display typebots on your React app", "description": "Convenient library to display typebots on your React app",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",

View File

@@ -94,7 +94,7 @@ class Typebot_Public
$lib_url = "https://cdn.jsdelivr.net/npm/@typebot.io/js@0.2.15/dist/web.js"; $lib_url = "https://cdn.jsdelivr.net/npm/@typebot.io/js@0.2.15/dist/web.js";
$width = '100%'; $width = '100%';
$height = '500px'; $height = '500px';
$api_host = 'https://viewer.typebot.io'; $api_host = 'https://typebot.io';
if (array_key_exists('width', $attributes)) { if (array_key_exists('width', $attributes)) {
$width = sanitize_text_field($attributes['width']); $width = sanitize_text_field($attributes['width']);
} }

4
packages/env/env.ts vendored
View File

@@ -33,16 +33,12 @@ const baseEnv = {
.string() .string()
.min(1) .min(1)
.transform((string) => string.split(',')), .transform((string) => string.split(',')),
NEXT_PUBLIC_VIEWER_INTERNAL_URL: z.string().url().optional(),
NEXT_PUBLIC_ONBOARDING_TYPEBOT_ID: z.string().min(1).optional(), NEXT_PUBLIC_ONBOARDING_TYPEBOT_ID: z.string().min(1).optional(),
NEXT_PUBLIC_BOT_FILE_UPLOAD_MAX_SIZE: z.coerce.number().optional(), NEXT_PUBLIC_BOT_FILE_UPLOAD_MAX_SIZE: z.coerce.number().optional(),
}, },
runtimeEnv: { runtimeEnv: {
NEXT_PUBLIC_E2E_TEST: getRuntimeVariable('NEXT_PUBLIC_E2E_TEST'), NEXT_PUBLIC_E2E_TEST: getRuntimeVariable('NEXT_PUBLIC_E2E_TEST'),
NEXT_PUBLIC_VIEWER_URL: getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL'), NEXT_PUBLIC_VIEWER_URL: getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL'),
NEXT_PUBLIC_VIEWER_INTERNAL_URL: getRuntimeVariable(
'NEXT_PUBLIC_VIEWER_INTERNAL_URL'
),
NEXT_PUBLIC_ONBOARDING_TYPEBOT_ID: getRuntimeVariable( NEXT_PUBLIC_ONBOARDING_TYPEBOT_ID: getRuntimeVariable(
'NEXT_PUBLIC_ONBOARDING_TYPEBOT_ID' 'NEXT_PUBLIC_ONBOARDING_TYPEBOT_ID'
), ),

View File

@@ -1,4 +0,0 @@
import { env } from '@typebot.io/env'
export const getViewerUrl = () =>
env.NEXT_PUBLIC_VIEWER_INTERNAL_URL ?? env.NEXT_PUBLIC_VIEWER_URL[0]

3
pnpm-lock.yaml generated
View File

@@ -758,6 +758,9 @@ importers:
specifier: 1.0.4 specifier: 1.0.4
version: 1.0.4 version: 1.0.4
devDependencies: devDependencies:
'@typebot.io/env':
specifier: workspace:*
version: link:../../env
'@typebot.io/lib': '@typebot.io/lib':
specifier: workspace:* specifier: workspace:*
version: link:../../lib version: link:../../lib