diff --git a/packages/embeds/js/package.json b/packages/embeds/js/package.json index 0020cad63..e382609d8 100644 --- a/packages/embeds/js/package.json +++ b/packages/embeds/js/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/js", - "version": "0.1.18", + "version": "0.1.19", "description": "Javascript library to display typebots on your website", "type": "module", "main": "dist/index.js", diff --git a/packages/embeds/js/src/features/blocks/logic/script/executeScript.ts b/packages/embeds/js/src/features/blocks/logic/script/executeScript.ts index 289b6d59a..ed6abd1be 100644 --- a/packages/embeds/js/src/features/blocks/logic/script/executeScript.ts +++ b/packages/embeds/js/src/features/blocks/logic/script/executeScript.ts @@ -4,11 +4,11 @@ import type { ScriptToExecute } from '@typebot.io/schemas' const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor export const executeScript = async ({ content, args }: ScriptToExecute) => { - const func = AsyncFunction( - ...args.map((arg) => arg.id), - parseContent(content) - ) try { + const func = AsyncFunction( + ...args.map((arg) => arg.id), + parseContent(content) + ) await func(...args.map((arg) => arg.value)) } catch (err) { console.error(err) diff --git a/packages/embeds/js/src/utils/guessApiHost.ts b/packages/embeds/js/src/utils/guessApiHost.ts index 304a641c9..493424395 100644 --- a/packages/embeds/js/src/utils/guessApiHost.ts +++ b/packages/embeds/js/src/utils/guessApiHost.ts @@ -1,8 +1,8 @@ -import { env } from '@typebot.io/env' +import { getRuntimeVariable } from '@typebot.io/env/getRuntimeVariable' const cloudViewerUrl = 'https://viewer.typebot.io' export const guessApiHost = () => - env.NEXT_PUBLIC_VIEWER_INTERNAL_URL ?? - env.NEXT_PUBLIC_VIEWER_URL[0] ?? + getRuntimeVariable('NEXT_PUBLIC_VIEWER_INTERNAL_URL') ?? + getRuntimeVariable('NEXT_PUBLIC_VIEWER_URL')?.split(',')[0] ?? cloudViewerUrl diff --git a/packages/embeds/nextjs/package.json b/packages/embeds/nextjs/package.json index f183efc1d..d8c28184e 100644 --- a/packages/embeds/nextjs/package.json +++ b/packages/embeds/nextjs/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/nextjs", - "version": "0.1.18", + "version": "0.1.19", "description": "Convenient library to display typebots on your Next.js website", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/embeds/react/package.json b/packages/embeds/react/package.json index 52520fa43..ba0081262 100644 --- a/packages/embeds/react/package.json +++ b/packages/embeds/react/package.json @@ -1,6 +1,6 @@ { "name": "@typebot.io/react", - "version": "0.1.18", + "version": "0.1.19", "description": "Convenient library to display typebots on your React app", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/env/env.ts b/packages/env/env.ts index db0b3aed1..4b3d356eb 100644 --- a/packages/env/env.ts +++ b/packages/env/env.ts @@ -1,14 +1,6 @@ import { createEnv } from '@t3-oss/env-nextjs' import { z } from 'zod' - -declare const window: { - __ENV: any -} - -const getRuntimeVariable = (key: string) => { - if (typeof window === 'undefined') return process.env[key] - return window.__ENV[key] -} +import { getRuntimeVariable } from './getRuntimeVariable' const boolean = z.enum(['true', 'false']).transform((value) => value === 'true') diff --git a/packages/env/getRuntimeVariable.ts b/packages/env/getRuntimeVariable.ts new file mode 100644 index 000000000..645215b85 --- /dev/null +++ b/packages/env/getRuntimeVariable.ts @@ -0,0 +1,10 @@ +declare const window: { + __ENV?: any +} + +const isBrowser = () => Boolean(typeof window !== 'undefined' && window.__ENV) + +export const getRuntimeVariable = (key: string) => { + if (isBrowser()) return window.__ENV[key] + return process.env[key] +}